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:

enter image description here

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

Thanks for your help! Ben

  • $\begingroup$ There is a specific quantlib forum where I think it would be better to ask this question? $\endgroup$ – 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%?

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
  • $\begingroup$ 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? $\endgroup$ – Benjamin E. Pfeiffer Dec 8 '17 at 14:44
  • $\begingroup$ Which rows work and which don't? $\endgroup$ – Enrico Schumann Dec 8 '17 at 15:11
  • $\begingroup$ 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.) $\endgroup$ – Enrico Schumann Dec 8 '17 at 15:13
  • $\begingroup$ 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. $\endgroup$ – Benjamin E. Pfeiffer Dec 8 '17 at 15:27
  • $\begingroup$ 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? $\endgroup$ – Benjamin E. Pfeiffer Dec 8 '17 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.