Basics

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Basics

animesh
I am trying to create an instance of fd class using this call
FiniteDifferenceModel<CrankNicolson<TridiagonalOperator> >


Obviously this is not possible since the constructor is (const
operator_type& L, const bc_set& bcs, const std::vector<Time>&
stoppingTimes = std::vector<Time>())

What I understand is stoppingTimes is an array for maturities. In case
of plain vanilla or simple up out call it might be single maturity say 1
year. So that information can be easily sent through. The other two
fields operator_type and bc_set are wierdos. Tough to get at first
glance :).

Since the documentation is obsolete I tried opening up lots of header
files and lots of cpp files to wrap around the code in my head. (Frankly
speaking I come from C Linux Kernel Coding world so C++ is a mess to
me!). Anyway if someone has followed my problem till this point do read on!

Again operator_type and bc_set are members of Evolver class which can be
something like CrankNicolson. So I rushed to it's header file
cranknicolson.hpp to get some clues. But still I can't figure out what's
operator_type or bc_set. My best guess was TridiagonalOperator class,
but still that didn't work.

Since most of the FD engines given in the sample examples are of useless
from trading perspective I was creating more practicle ones which can be
used more from static hedging perspective. So it would be really helpful
if someone can help me understand at least how to initialize the generic
FiniteDifferenceModel class.

I guess I should send this to dev's list, but well will wait...if I
don't get the reply I will forward coz i guess questions are not that
simple ;)

Thanks for reading,

Animesh Saxena

(Associate)

Exotic Derivatives
NOMURA


------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Basics

animesh
Night hours seemed to make the code work!
Figured out this much

Option::Type type = Option::Call;
    double underlying = 100.0, strike = 95.0;
    Time residualTime = 1.0;
    Rate dividendYield = 0.00, riskFreeRate = 0.05;
    double volatility = 0.10;
   
    unsigned int timeSteps = 365;
    unsigned int gridPoints = 400;
    Array grid(gridPoints), prices(gridPoints);
    double x0 = log(underlying);
    double Delta = 4.0*volatility*pow(residualTime,0.5);
    double xMin = x0 - Delta, xMax = x0 + Delta;
    double h = (xMax-xMin)/(gridPoints-1);
    for (unsigned int i=0; i<gridPoints; i++) {
        grid[i] = xMin + i*h;
        prices[i] = exp(grid[i]);
        std::cout<<prices[i]<<"\t";
    }
   
    Array exercisingValue(gridPoints);
    for (unsigned int i=0; i<gridPoints; i++)
        exercisingValue[i] = ((prices[i]-strike)>0? prices[i]-strike:0.0);
   
    double nu = riskFreeRate - dividendYield - volatility*volatility/2.0;
    TridiagonalOperator L = BlackScholesOperator(volatility, nu,
riskFreeRate, gridPoints, h);
   
    std::vector<boost::shared_ptr<BoundaryCondition<TridiagonalOperator>
 > > BCs_(2);
   
    BCs_[0] = boost::shared_ptr<BoundaryCondition<TridiagonalOperator> >
(new NeumannBC(1,NeumannBC::Lower));
   
    BCs_[1] = boost::shared_ptr<BoundaryCondition<TridiagonalOperator> >
(new NeumannBC(400,NeumannBC::Upper));
   
    stoppingTimes[0] = 1;
    FiniteDifferenceModel<CrankNicolson<TridiagonalOperator> >
model(L,BCs_,stoppingTimes);  
    Array f = exercisingValue;
    model.rollback(f, residualTime, 0.0, timeSteps);
    int ik;
    ik = 201;
    std::cout<<"\n";
    std::cout<<"Strikes:"<<exp(grid[ik])<<"\t"<<f[ik]<<"\n";

Above code compiles but still I don't have idea how to correctly specify
Boundary conditions, coz I am not sure what this is doing....

    BCs_[0] = boost::shared_ptr<BoundaryCondition<TridiagonalOperator> >
(new NeumannBC(1,NeumannBC::Lower));

Can anyone explain just this one line of code? I am guessing it's
conditions for vanilla like Max(S(T) - Strike,0), so similarly I can
have more exotic payoff's but I
need to understand the intricacies of this class to fully understand
it's function. Can anyone help me??

Also can't make sense of output! If any other mistakes in above code do
lemme know....

Thanks Again...

Animesh Saxena

(Associate)

Exotic Derivatives
NOMURA


animesh saxena wrote:

> I am trying to create an instance of fd class using this call
> FiniteDifferenceModel<CrankNicolson<TridiagonalOperator> >
>
>
> Obviously this is not possible since the constructor is (const
> operator_type& L, const bc_set& bcs, const std::vector<Time>&
> stoppingTimes = std::vector<Time>())
>
> What I understand is stoppingTimes is an array for maturities. In case
> of plain vanilla or simple up out call it might be single maturity say
> 1 year. So that information can be easily sent through. The other two
> fields operator_type and bc_set are wierdos. Tough to get at first
> glance :).
>
> Since the documentation is obsolete I tried opening up lots of header
> files and lots of cpp files to wrap around the code in my head.
> (Frankly speaking I come from C Linux Kernel Coding world so C++ is a
> mess to me!). Anyway if someone has followed my problem till this
> point do read on!
>
> Again operator_type and bc_set are members of Evolver class which can
> be something like CrankNicolson. So I rushed to it's header file
> cranknicolson.hpp to get some clues. But still I can't figure out
> what's operator_type or bc_set. My best guess was TridiagonalOperator
> class, but still that didn't work.
>
> Since most of the FD engines given in the sample examples are of
> useless from trading perspective I was creating more practicle ones
> which can be used more from static hedging perspective. So it would be
> really helpful if someone can help me understand at least how to
> initialize the generic FiniteDifferenceModel class.
>
> I guess I should send this to dev's list, but well will wait...if I
> don't get the reply I will forward coz i guess questions are not that
> simple ;)
>
> Thanks for reading,
>
> Animesh Saxena
>
> (Associate)
>
> Exotic Derivatives
> NOMURA
>
>

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users