Frash
Frash

Reputation: 728

Time to maturity (TTM) shifted for day conversion using RQuantlib in R

I'm using RQuantlib package in R to calculate the implied volatility. As a input to the function EuropeanOptionImpliedVolatility I use TTM days divided by 365. But if I use the output implied volatility to calculate the option price back using hand crafted Black Scholes function, I end with a different values.

I found the cause to be in the europeanOptionImpliedVolatilityEngine, which converts the input fractional year by using the conversion

int(maturity*360 + 0.5);

Source: RQuantlib github

So this ends up shifting the TTM values passed on to the C code function with difference of 1 day in some cases, about 70% of the data got date shifted in my case.

x=OptGreeks$TTM/365
y=floor(x*360+0.5)
z=OptGreeks$TTM - y
table(z)

Output

z
   0    1 
2636 4910 

Any idea why this is being done and any measure the get the correct days (TTM) passed instead of this anomaly? Hope someone listens.

Upvotes: 1

Views: 274

Answers (1)

Luigi Ballabio
Luigi Ballabio

Reputation: 4343

The function should probably be extended so that one can choose a day-count convention, and that's the way to go if you're familiar with C++ and can patch and recompile RQuantLib.

In the meantime, I'm afraid that the way to work around the problem is for you to use days/360, too. This means you'll also have to adjust your input rates and the output volatility; the relations you want to satisfy are r360 t360 = r365 t365 (from which you'll get the r360 to pass as input, given your r365) and sigma2360 t360 = sigma2365 t365 (from which you'll get sigma365 given the returned sigma360).

Upvotes: 1

Related Questions