I need to calculate de Implied Volatility for Financial Options using the QuantLib package for R. I'm having trouble using iterations for the function "EuropeanOptionImpliedVolatility" because its output is a Object (called ImpliedVolatility).
largo = nrow(call26) #number of rows in my data set
impl_vol= vector("list",largo)
for(i in largo){
impl_vol[[i]] = EuropeanOptionImpliedVolatility(type="call", value=valor_opcion[i],
underlying=st[i], strike=strike[i], dividendYield=dividendo[i],
riskFreeRate=rf[i], maturity=maturity[i], volatility=0.4)
}
The result of this is:
list(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, structure(list(impliedVol = 0.173643438965225,
parameters = structure(list(type = "call", value = 52.95,
underlying = 1497.66, strike = 1680, dividendYield = 0.01,
riskFreeRate = 0.04, maturity = 0.983561644, volatility = 0.4), .Names = c("type",
"value", "underlying", "strike", "dividendYield", "riskFreeRate",
"maturity", "volatility"))), .Names = c("impliedVol",
"parameters"), class = c("EuropeanOptionImpliedVolatility",
"ImpliedVolatility")))
And I need the implied volatilities... wich if I calculate for a single Financial Option i can acces to it with
valor$impliedVol
What can i do? Thanks!