Login  Register

Question on registerWith for evaluationDates

Posted by Tawanda Gwena on Apr 09, 2010; 7:55pm
URL: http://quantlib.414.s1.nabble.com/Question-on-registerWith-for-evaluationDates-tp6582.html

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