# Quantlib: AmericanOption implied volatility / root not bracketed

When I apply the americanoptionimpliedvolatility function in the following format:

  impliedvol_test_v1$IV <- NA impliedvol_test_v1$risk free rate <- as.numeric(impliedvol_test_v1$risk free rate) for(iRow in seq(1,nrow(impliedvol_test_v1),1)){ typeTMP <- impliedvol_test_v1$type[iRow]
valueTMP <- impliedvol_test_v1$value[iRow] strikeTMP <- impliedvol_test_v1$strike[iRow]
underlyingTMP <- impliedvol_test_v1$underlying[iRow] dividendyieldTMP <- impliedvol_test_v1$Dividend yield[iRow]
riskfreerateTMP <- impliedvol_test_v1$risk free rate[iRow] maturityTMP <- impliedvol_test_v1$maturity[iRow]
volatilityTMP <- impliedvol_test_v1$volatility[iRow] impliedvol_test_v1$IV[iRow] <- AmericanOptionImpliedVolatility(typeTMP,
valueTMP,strikeTMP, underlyingTMP, dividendyieldTMP, riskfreerateTMP,
maturityTMP, volatilityTMP)

}


I receive the following error: Error in americanOptionImpliedVolatilityEngine(type, value, underlying, :

../../../QuantLib-1.6.2/ql/math/solver1d.hpp:202: In function QuantLib::Real QuantLib::Solver1D::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] -> [2.230734e+000,2.306800e+001]

Which is weird since I receive IV values when I plug them in manually.

The dataset looks like:

When I plug in the values manually, I receive values for each row.

• There is a specific quantlib forum where I think it would be better to ask this question? – Yian Pap Dec 8 '17 at 11:17

Could you show the exact call that you use when you "plug them in manually"?

Anyway, can you override the bracketing interval in RQuantLib with a tighter range, say 1% to 100%?

library("NMOF")
vanillaOptionImpliedVol("american", price = 3.7,
S = 37.39, X = 35,
tau = .1698, q = 0.0654, r = 0.17,
uniroot.control = list(interval = c(0.01, 1)))
## [1] 0.3172167

vanillaOptionAmerican(S = 37.39, X = 35,
tau = .1698, q = 0.0654, r = 0.17,
v = .3173^2)\$value
## [1] 3.700333
`
• For example, I recieve values only for the first two rows using my entries as above. For the subsequent row, I used again the same americanptionimpliedvolatility function and it gave me a value for the IV. What seems to be wrong here ? &how do I adjust for it? – Benjamin E. Pfeiffer Dec 8 '17 at 14:44
• Which rows work and which don't? – Enrico Schumann Dec 8 '17 at 15:11
• Check the order of arguments in your function call: it should be underlying, then strike. It seems you have them the other way around. (Naming arguments is a good idea.) – Enrico Schumann Dec 8 '17 at 15:13
• you're right! thanks, however, it generates values only up to a certain row and then returns the same values in the subsequent rows until the end. – Benjamin E. Pfeiffer Dec 8 '17 at 15:27
• asked differently: apparently, the code stops working as soon as the values do not lead to any IV. Is there a way to add code to let the function start at the next row which contains valid values? – Benjamin E. Pfeiffer Dec 8 '17 at 15:31