finmath / finmath-lib

Mathematical Finance Library: Algorithms and methodologies related to mathematical finance.
Apache License 2.0
488 stars 168 forks source link

question on SABRVolatilityCube #75

Closed summepau closed 4 years ago

summepau commented 4 years ago

Hi,

I am looking – as a relative beginner to Java – at your finmath package, specifically to build a SABR swaption grid.

I am confused by your conventions though.

In the code to getValue in SABRVolatilityCube.java you have

if(termination<maturity) {
   throw new IllegalArgumentException("Termination has to be larger (or equal) maturity. Was termination="+termination+", maturity="+maturity);
}

Therefore termination must be an absolute number, not relative to maturity.

But all the code does next is call the data tables:

final double underlying = underlyingTable.getValue(maturity, termination);
final double sabrRho = rhoTable.getValue(maturity, termination);
final double baseVol = baseVolTable.getValue(maturity, termination);
final double sabrVolvol = volvolTable.getValue(maturity, termination);

and DataTableLinear is defined with termination being relative to maturity:

* @param maturities The maturities of the points as offset with respect to the reference date.
* @param terminations The terminations of the points as offset with respect to the maturity date.

So for example a 5y-2y swaption cannot be accessed. Have I missed something?

Regards

Paul

AlgoAmigo commented 4 years ago

Hi Paul,

note that the function getValue is overloaded. Calling this function with arguments of the type double does not yield the same result as calling it with arguments of type int.

The part of DataTableLinear which you are refering to, is the documentation of the function which expects arguments of type int. However, SABRVolatilityCube calls the double implementation. The documentation of this overloaded function is:

* @param maturity Maturity in double as year fraction with respect to reference date.
* @param termination Termination in double as year fraction with respect to reference date.

This means the termination in this case is treated as an absolute number.

Kind Regards, Jan

summepau commented 4 years ago

Understood, thanks!