Re: Vega and Rho calculation for European and American Options using Finite Difference Method

Posted by Luigi Ballabio on
URL: http://quantlib.414.s1.nabble.com/Vega-and-Rho-calculation-for-European-and-American-Options-using-Finite-Difference-Method-tp7925p7928.html

On Sat, 2010-01-16 at 12:39 -0800, ravi agrawal wrote:
> I am trying to calculate greeks from the FD framework. Presently I
> moved to using wrapper for vega and rho. Also I notice that Theta is
> being calculated in FD framework by using black scholes equation using
> the values of FD delta and gamma. I wanted to calculate it by grid
> method but am searching for grid and value  2-d array where I could
> get call option value which has expiry some grid times less that the
> present option. Could anyone tell me where I can find this value 2 d
> grid and price 2d grid?

You can look, e.g., at <ql/pricingengines/vanilla/fdeuropeanengine.hpp>,
around line 75.  There's a call to model.rollback(...), that evolves the
prices to t=0 (their values after the call are in the prices_ array.)
After extracting the value at center and the greeks, you can add another
call to model.rollback(...) taking the prices some time before 0.  After
that call, you can extract the value at center again and use it to
calculate theta.  The same can be done in the FD engines for american
and bermudan options.

As for the rho/vega issue:

> On Fri, Jan 15, 2010 at 5:14 AM, Andrew Kolesnikov <[hidden email]>
> wrote:
>        
>        
>         Hi, Ravi
>         As u can see QL architecture doesnt allow u to calculate
>         vega/rho by perturbation within corresponding method of
>         OneAssetOption class, cause itsn't possible to create a clone
>         object with shift vol/rate parameter.

That's because you can't shift it in a general way. At the instrument
level, you don't know if you're using a Black-Scholes model, a Heston
model, or something else entirely.

>         My suggestion is to develop your own Instrument class which
>         also inherenced from LazyObject class and additionally have
>         shiftedNPV(variable, value) function with NPV calculation of
>         shifted clone object.

If you go for shifting and recalculating, you can do it right now using
quotes.  You can do something like the following:

// put the values in quotes:

shared_ptr<SimpleQuote> riskFreeRate(new SimpleQuote(0.02));
shared_ptr<SimpleQuote> volatility(new SimpleQuote(0.15));
// ... other required parameters ...

// create flat curves with the above values:

Handle<YieldTermStructure> r(
    shared_ptr<YieldTermStructure>(
        new FlatForward(today,
                        Handle<Quote>(riskFreeRate),
                        Actual365())));

Handle<BlackVolTermStructure> sigma(
    shared_ptr<BlackVolTermStructure>(
        new BlackConstantVol(today,
                             NullCalendar(),
                             Handle<Quote>(volatility),
                             Actual365()));
                                                 
// ...and the others.

// create the process:

shared_ptr<BlackScholesMertonProcess> process(
    new BlackScholesMertonProcess(s0, q, r, sigma));

// instantiate the option and set it an engine using the process

VanillaOption option(...);
option.setPricingEngine(
    boost::shared_ptr<PricingEngine>(
        new FDEuropeanEngine<CrankNicolson>(process,
                                            timeSteps,gridSteps)));

// now you're set.

// first you get the unperturbed price:

Real P = option.NPV();

// then by shifting the quotes you can get any perturbed value:

Rate r0 = riskFreeRate->value();
Spread dr = 0.0001;
riskFreeRate->setValue(r0 + dr);

// the quote change is propagated automatically,
// and this now gives you the value for the new rate:

Real P1 = option.NPV();

// same downwards:

riskFreeRate->setValue(r0 - dr);
Real P2 = option.NPV();

// put them together for the rho:

Real rho = (P1-P2)/(2*dr);

// and don't forget to restore the original rate.

riskFreeRate->setValue(r0);

// do the same for the volatility quote, and you get the vega.

Hope this helps,
        Luigi



--

For every problem there is one solution which is simple, neat, and
wrong.
-- H. L. Mencken



------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
QuantLib-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-users