I am also interested in simple codes for QuantLib (I have just a smattering of C++ and option pricing).
If I understand correctly, the C++ code in the email prices plain vanilla European call options.
It uses the standard Black and Scholes theory for a dividend-paying stock.
No stochastic volatility, flat term structure and so on.
).
I am not totally sure whether the dividends in the example are paid continuosly or not, but if I set the yield to zero, then I am in the case of a non-dividend paying stock.
But the output of the code in the email (I simply reset the value of the yield and print out the relevant quantities) is a bit puzzling to me:
whereas the other library provides a small value (about 0.08) but definitely non-zero.
Furthermore, in the case of stock which pays dividends continuously, again I get a non-zero price using the mentioned library.
> Gilles,
>
> In case it helps, here is the EuropeanOption.cpp example stripped to
> its most basics:
>
> #include <ql/quantlib.hpp>
> #include <iostream>
> using namespace QuantLib;
>
> int main()
> {
> Option::Type type(Option::Call);
> Real underlying = 7.00, strike = 8.00;
> Spread dividendYield = 0.05;
> Rate riskFreeRate = 0.05;
> Volatility volatility = 0.10;
> Date todaysDate(15, May, 1998);
> Date settlementDate(17, May, 1998), exerciseDate(17, May, 1999);
> Settings::instance().evaluationDate() = todaysDate;
> DayCounter dayCounter = Actual365Fixed();
> Time maturity = dayCounter.yearFraction(settlementDate,exerciseDate);
>
> boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exerciseDate));
> 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, volatility, dayCounter)));
>
> boost::shared_ptr<StrikedTypePayoff> payoff(
> new PlainVanillaPayoff(type, strike));
>
> boost::shared_ptr<BlackScholesProcess> stochasticProcess(
> new BlackScholesProcess(underlyingH, flatDividendTS,
> flatTermStructure, flatVolTS));
>
> EuropeanOption option(stochasticProcess, payoff, exercise);
>
> option.setPricingEngine(boost::shared_ptr<PricingEngine>(
> new AnalyticEuropeanEngine()));
>
> std::cout << "Black-Scholes value: " << option.NPV() << std::endl;
>
> return 0;
> }
>
>
> > Thank you very much
> >
> > NB: in EuropeanOption, what means
> > return std::exp(-r_*maturity_)
> > *PlainVanillaPayoff(type_, strike_)(s0_*std::exp(x))
> > *std::exp(-(x - nuT)*(x -nuT)/(2*sigma_*sigma_*maturity_))
> > /std::sqrt(2.0*M_PI*sigma_*sigma_*maturity_);
> > in the operator().
> > Why a PI ? why multiply the payoff with a exp ?
>
>
>
>
>
> _______________________________________________
> Quantlib-users mailing list
>
[hidden email]
>
https://lists.sourceforge.net/lists/listinfo/quantlib-users