Posted by
Robert Kubrick on
URL: http://quantlib.414.s1.nabble.com/Caching-the-pricing-engine-tp6574p6577.html
I'm doing exactly what you suggested for price, volatility and yield
but I get the wrong npv and greeks values.
Calc::Calc(double riskFreeRate, boost::gregorian::date settlement):
_riskFreeRate(riskFreeRate),
_settlement(Day(settlement.day()), Month(settlement.month().as_enum
()), Year(settlement.year())),
_dayCounter(Actual365Fixed()),
_calendar(TARGET()),
_underlyingQuote(new SimpleQuote(1)),
_volQuote(new SimpleQuote(1)),
_yieldQuote(new SimpleQuote(1))
{
date today = day_clock::local_day();
Settings::instance().evaluationDate() = Date(Day(today.day()),
Month(today.month().as_enum()), Year(today.year()));
Date exerciseDate(Day(30), Month(12), Year(2020));
_pExercise = shared_ptr<Exercise>(new EuropeanExercise
(exerciseDate));
_pPayoff = shared_ptr<StrikedTypePayoff>(new PlainVanillaPayoff
(Option::Call, 1));
_pFlatVolTS = shared_ptr<BlackVolTermStructure>(new
BlackConstantVol(_settlement,
_calendar,
Handle<Quote>(_volQuote),
_dayCounter));
_pFlatTermStruct = shared_ptr<YieldTermStructure>(new FlatForward
(_settlement,
_riskFreeRate,
_dayCounter));
_pFlatDividendTermStruct = shared_ptr<YieldTermStructure>(new
FlatForward(_settlement,
Handle<Quote>(_yieldQuote),
_dayCounter));
_pProcess = shared_ptr<BlackScholesMertonProcess>(new
BlackScholesMertonProcess(Handle<Quote>(_underlyingQuote),
Handle<YieldTermStructure>(_pFlatDividendTermStruct),
Handle<YieldTermStructure>(_pFlatTermStruct),
Handle<BlackVolTermStructure>(_pFlatVolTS)));
_pPE = shared_ptr<PricingEngine>(new AnalyticEuropeanEngine
(_pProcess));
_pOption = new EuropeanOption(_pPayoff, _pExercise);
_pOption->setPricingEngine(_pPE);
}
void Calc::run(Side side, double price, int strike, double yield,
const date& exercise, double vol)
{
_underlyingQuote->setValue(price);
_volQuote->setValue(vol);
_yieldQuote->setValue(yield);
QuantLib::Option::arguments args;
args.payoff = shared_ptr<StrikedTypePayoff>(new PlainVanillaPayoff
(side == CALL ? Option::Call : Option::Put, strike));
args.exercise = shared_ptr<Exercise>(new EuropeanExercise(Date(Day
(exercise.day()), Month(exercise.month().as_enum()), Year
(exercise.year()))));
_pOption->setupArguments(&args);
cout << "NPV: " << _pOption->NPV() << endl;
cout << "Delta: " << _pOption->delta() << endl;
cout << "Gamma: " << _pOption->gamma() << endl;
/*
_npv = _pOption->NPV();
_delta = _pOption->delta();
_gamma = _pOption->gamma();
_vega = _pOption->vega();
_theta = _pOption->theta();
_rho = _pOption->rho();
*/
}
On Sep 15, 2008, at 3:57 AM, Luigi Ballabio wrote:
> On Sun, 2008-09-14 at 19:16 -0400, Robert Kubrick wrote:
>> Is there a way to dynamically change the engine process parameters,
>> volatility and yield in particular?
>
> Yes---when you write:
>
>
>>> Handle<BlackVolTermStructure> flatVolTS
>>> (shared_ptr<BlackVolTermStructure>(new BlackConstantVol(_settlement,
>>>
>>> _calendar,
>>>
>>> vol,
>>>
>>> _dayCounter)));
>>>
>
> Do instead:
>
> shared_ptr<SimpleQuote> volQuote(new SimpleQuote(0.20));
>
> Handle<BlackVolTermStructure>
> flatVolTS(shared_ptr<BlackVolTermStructure>(
> new BlackConstantVol(_settlement,
> _calendar,
> Handle<Quote>(volQuote),
> _dayCounter)));
>
> after you've built your options, you can execute:
>
> volQuote->setValue(0.25);
>
> and all the options will see the new volatility (i.e., they'll
> return a
> different value when you call NPV() etc.)
>
> Luigi
>
>
>
> --
>
> Better to remain silent and be thought a fool than to speak out and
> remove all doubt.
> -- Abraham Lincoln
>
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users