Login  Register

Re: Question about EuropeanOption with Quantlib

Posted by Luigi Ballabio on Jan 19, 2006; 8:00am
URL: http://quantlib.414.s1.nabble.com/Question-about-EuropeanOption-with-Quantlib-tp4376p4377.html

On 1/18/06, gilles herzog <[hidden email]> wrote:
> I begin with quantlib and I try to understant EuropeanOption.cpp ( example
> in quantlib default's directory )
> I have several questions.
>
> What is the operator () ??

The part of the code you quoted is a leftover---it is no longer used
in the example. However, adding an operator() to a class makes it
possible to use instances in the same way as functions. Namely, if Foo
is a class with an operator() and f is a Foo instance, it is possible
to write f(x). This calls Foo::operator() passing x as the argument.

> What is the interest of the class PlainVanillaPayoff ? You can't compute a
> payoff without knowing the value of the asset because it is Max(St-K,0) for
> the call .

Right. The payoff as you wrote it is a function of two variables,
namely, S and K.
A PlainVanillaPayoff instance is a curried version of the above, i.e.,
the strike is fixed (it is passed to the constructor) and the created
object can be used as a function of the asset value only. Hmm, I'm not
being very clear. Here's an example:

// you fix a given K when you create the payoff object...
PlainVanillaPayoff p(Option::Call, K);
// ...and now it can give you the payoff for any value of the asset, as in:
double p1 = p(S1);
double p2 = p(S2);
// where S1 and S2 are different values of the asset at maturity.

Note that in the above, I've been able to write p(S). This is because
I gave the payoff class an operator().

Later,
    Luigi