Login  Register

Re: Managed Wrapper

Posted by John Maiden on Apr 04, 2011; 12:49am
URL: http://quantlib.414.s1.nabble.com/Managed-Wrapper-tp8470p8475.html

To add more color, I'm testing a simple option pricer, using the EquityOption
example. I've done some more testing. I can get an American option to build and
link, but I can't get a European option to link. See code below. If I uncomment
the European section then I can't get the code to link.

void priceOptionEuro(
        Date valueDate,
        Date settlementDate,
        Date maturity,
        Real underlying,
        Real strike,
        Rate riskFreeRate,
        Spread dividendYield,
        Volatility volatility,
        double &NPV)
{
        // Hard-coded values for now
        Calendar calendar = TARGET();
        DayCounter dayCounter = Actual365Fixed();
        Option::Type type(Option::Call);

        // Exercise type

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

    // bootstrap the yield/dividend/vol curves
        // Flat yield structure
    Handle<YieldTermStructure> flatTermStructure(
        boost::shared_ptr<YieldTermStructure>(
            new FlatForward(settlementDate, riskFreeRate, dayCounter)));

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

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

    boost::shared_ptr<StrikedTypePayoff> payoff(
                                    new PlainVanillaPayoff(type, strike));
       
        Size timeSteps = 801;

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

        // European code that gives linking problem
        /*boost::shared_ptr<Exercise> europeanExercise(
                            new EuropeanExercise(maturity));

        VanillaOption europeanOption(payoff, europeanExercise);
   
    europeanOption.setPricingEngine(boost::shared_ptr<PricingEngine>(
                new FDEuropeanEngine<CrankNicolson>(bsmProcess, timeSteps,
timeSteps-1)));
                               
        NPV = europeanOption.NPV();*/

        // American code that builds and links
        boost::shared_ptr<Exercise> americanExercise(
                                    new AmericanExercise(settlementDate, maturity));

        VanillaOption americanOption(payoff, americanExercise);

        americanOption.setPricingEngine(boost::shared_ptr<PricingEngine>(
            new FDAmericanEngine<CrankNicolson>(bsmProcess, timeSteps,
timeSteps-1)));
       
        NPV = americanOption.NPV();
}


------------------------------------------------------------------------------
Create and publish websites with WebMatrix
Use the most popular FREE web apps or write code yourself;
WebMatrix provides all the features you need to develop and
publish your website. http://p.sf.net/sfu/ms-webmatrix-sf
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users