[R-SIG-Finance] RQuantLib: AmericanOptionImpliedVolatility bug

Charles Duranceau cduranceau at nial.ky
Fri May 26 17:46:13 CEST 2017


I found a problem with the function "AmericanOptionImpliedVolatility" in RQantLib which return an error for a specific set of conditions (but cannot identifies exactly what are these).
I present a case related to a short term, very deep in-the-money put with negative interest rate that generate error message. I present a reproducible example below.
I found the related function "AmericanOption" with default produce similar error when use in a routine to back-out the implied volatility.
However, I found good result (no error)  when using the engine="CrankNicolson" :  a naïve routine for backing-out the implied vol with this function return a volatility.
There's a work around but think this information may add more stability to RQL.

Best Regards

RQuantLib Version 4.2

R version 3.3.2 (64bits)


price = 14.5
strike = 65
Spot= 50.5
Rate = -0.00361
DividendYield = 0
Volatility = 0.296
YearToMaturity = 3/365

# error when Implied Vol
AmericanOptionImpliedVolatility("put", price,Spot, strike, DividendYield, Rate,YearToMaturity, Volatility)

Error in americanOptionImpliedVolatilityEngine(type, value, underlying,  :

../../../QuantLib-1.6.2/ql/math/solver1d.hpp:202: In function `QuantLib::Real QuantLib::Solver1D<Impl>::solve(const F&, QuantLib::Real, QuantLib::Real, QuantLib::Real, QuantLib::Real) const [with F = QuantLib::{anonymous}::PriceError; Impl = QuantLib::Brent; QuantLib::Real = double]':
root not bracketed: f[1e-007,4] -> [1.955446e-003,3.006858e+000]

#also generate error
AmericanOption("put", Spot, strike, DividendYield, Rate,YearToMaturity, Volatility)

# works well
AmericanOption("put", Spot, strike, DividendYield, Rate,YearToMaturity, Volatility,timeSteps=150, gridPoints=149, engine="CrankNicolson")
# backing out the implied vol naively works
fImpliedVol(Volatility,price,"put", Spot, strike, DividendYield, Rate,YearToMaturity)

fImpliedVol<-function(iniVol,Premium,Callput, Spot, Strike, DivYield, Rate,YrtoMat){
  ftm<-function(ImpVol,Premium,Callput, Spot, Strike, DivYield, Rate,YrtoMat, iVol)
    ov<-AmericanOption(type=Callput, underlying=Spot, strike=Strike,dividendYield=DivYield, riskFreeRate=Rate, maturity=YrtoMat,volatility=ImpVol,
                       timeSteps=150, gridPoints=149, engine= "CrankNicolson")
  imp<-optimize(f=ftm,c(lower = 0, upper = 1.5), tol = 1e-4,Premium,Callput,Spot, Strike, DivYield, Rate,YrtoMat)

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] RQuantLib_0.4.3 dplyr_0.5.0

loaded via a namespace (and not attached):
[1] zoo_1.8-0        magrittr_1.5     R6_2.1.2         assertthat_0.2.0 DBI_0.6-1        tools_3.3.2      tibble_1.0       Rcpp_0.12.10
 [9] grid_3.3.2       lattice_0.20-34


	[[alternative HTML version deleted]]

More information about the R-SIG-Finance mailing list