arrays - How do I create a vector of objects in R? -


this question has answer here:

i need calculate de implied volatility financial options using quantlib package r. i'm having trouble using iterations function "europeanoptionimpliedvolatility" because output object (called impliedvolatility).

largo = nrow(call26) #number of rows in 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 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 need implied volatilities... wich if calculate single financial option can acces with

valor$impliedvol 

what can do? thanks!

there's error in loop, instead of:

for(i in largo){ 

it's :

for(i in 1:largo){ 

because of error, implied volatility of last element (index 195) computed (as can see in output structure have posted, first 194 list slots null , last has value).

once have fixed typo, access value do:

impl_vol[[i]]$impliedvol 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -