Question on registerWith for evaluationDates

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

Question on registerWith for evaluationDates

Tawanda Gwena
Dear  all,

I have the simple problem of trying to change the evaluation date for a basic option. For some reason I cannot seem to set the observer to work properly. I want to work out the price of an option on 15 May 2009 and 10 May 2010. The option expires on 17 May 2010.

If I set the evaluation date to after expiry I (rightly) get the value of the option to be 0. 

Here is some code which I have. How can I fix/understand this?


#include <ql/quantlib.hpp>
#include <iostream>


using namespace QuantLib;

int main(int, char* []) 
{
    std::cout << std::endl;


    // set up dates
    Calendar calendar = TARGET();
    Date todaysDate(15, May, 2009);
    Settings::instance().evaluationDate() = todaysDate;
    Date settlementDate(17, May, 2009);
    Date maturity(17, May, 2010);
    DayCounter dayCounter = Actual365Fixed();

    

    // option parameters
    Option::Type type(Option::Call);
    Real underlying = 40;
    Real strike = 40;
    Spread dividendYield = 0.00;
    Rate riskFreeRate = 0.06;
    Volatility volatility = 0.1;

    

    //basic option
    boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(type, strike));
    boost::shared_ptr<Exercise> europeanExercise(new EuropeanExercise(maturity));
    VanillaOption europeanOption(payoff, europeanExercise);

    //Handle setups
    Handle<Quote> underlyingH(boost::shared_ptr<Quote>(new SimpleQuote(underlying)));

    

    Handle<YieldTermStructure> flatTermStructure(
                                boost::shared_ptr<YieldTermStructure>(
                                             new FlatForward(settlementDate,
                                                             riskFreeRate,   
                                                             dayCounter)));


    Handle<YieldTermStructure> flatDividendTS(
                                boost::shared_ptr<YieldTermStructure>(
                                            new FlatForward(settlementDate,
                                                            dividendYield,
                                                            dayCounter)));


    Handle<BlackVolTermStructure> flatVolTS(
                                boost::shared_ptr<BlackVolTermStructure>(
                                            new BlackConstantVol(settlementDate, 
                                                                 calendar, 
                                                                 volatility,
                                                                 dayCounter)));



    boost::shared_ptr<BlackScholesMertonProcess> bsmProcess(
                                new BlackScholesMertonProcess(underlyingH, 
                                                              flatDividendTS,
                                                              flatTermStructure, 
                                                              flatVolTS));

    boost::shared_ptr<PricingEngine> analyticEngine(new AnalyticEuropeanEngine(bsmProcess));

    

    europeanOption.setPricingEngine(analyticEngine);

    europeanOption.registerWith(Settings::instance().evaluationDate());

    std::cout<<"European Option value on 15, May 2009: "  << europeanOption.NPV()<<std::endl;

    Settings::instance().evaluationDate() = Date(10, May, 2010);
    
    std::cout<<"European Option value on 10 May 2010: "  << europeanOption.NPV()<<std::endl;

    


    return 0;
}


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Question on registerWith for evaluationDates

Luigi Ballabio

On Apr 9, 2010, at 9:55 PM, Tawanda Gwena wrote:

> I have the simple problem of trying to change the evaluation date  
> for a basic option. For some reason I cannot seem to set the  
> observer to work properly. I want to work out the price of an option  
> on 15 May 2009 and 10 May 2010. The option expires on 17 May 2010.
>
> If I set the evaluation date to after expiry I (rightly) get the  
> value of the option to be 0.
>
> Here is some code which I have. How can I fix/understand this?
>
>     Handle<YieldTermStructure> flatTermStructure(
>                                 boost::shared_ptr<YieldTermStructure>(
>                                              new  
> FlatForward(settlementDate,
>                                                              
> riskFreeRate,
>                                                              
> dayCounter)));

If you use the FlatForward constructor that takes a reference date,  
the curve will keep calculating discounts from that date, no matter  
where you move the evaluation date.  Use the constructor taking a  
number of settlement days instead, and the reference date will move  
with the evaluation date.

Luigi


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users
Reply | Threaded
Open this post in threaded view
|

Re: Question on registerWith for evaluationDates

Tawanda Gwena
Thanks!

I can now have a good weekend.


On Apr 9, 2010, at 4:07 PM, Luigi Ballabio wrote:

>
> On Apr 9, 2010, at 9:55 PM, Tawanda Gwena wrote:
>
>> I have the simple problem of trying to change the evaluation date  
>> for a basic option. For some reason I cannot seem to set the  
>> observer to work properly. I want to work out the price of an  
>> option on 15 May 2009 and 10 May 2010. The option expires on 17 May  
>> 2010.
>>
>> If I set the evaluation date to after expiry I (rightly) get the  
>> value of the option to be 0.
>>
>> Here is some code which I have. How can I fix/understand this?
>>
>>    Handle<YieldTermStructure> flatTermStructure(
>>                                boost::shared_ptr<YieldTermStructure>(
>>                                             new  
>> FlatForward(settlementDate,
>>                                                              
>> riskFreeRate,
>>                                                              
>> dayCounter)));
>
> If you use the FlatForward constructor that takes a reference date,  
> the curve will keep calculating discounts from that date, no matter  
> where you move the evaluation date.  Use the constructor taking a  
> number of settlement days instead, and the reference date will move  
> with the evaluation date.
>
> Luigi
>


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users