Here is my code for downloading spot prices and calculating realized volatilities for a bunch of indices.
library(quantmod)
library(PerformanceAnalytics)
library(RQuantLib)
tickers.index = c("^RUT","^STOXX50E","^HSI")
myEnv <- new.env()
getSymbols(tickers.index, src='yahoo', from = "2004-03-26", to = "2012-10-10", env = myEnv, adjust=TRUE)
index <- do.call(merge, c(eapply(myEnv, Ad), all=TRUE))
index <-na.locf(index)
#Calculate daily returns for all indices and convert to arithmetic returns
index.ret <- exp(CalculateReturns(index,method="compound")) - 1
index.ret[1,] <- 0
#Calculate realized vol for all the indices
index.realized <- xts(apply(index.ret,2,runSD,n=20), index(index.ret))*sqrt(252)
index.realized[1:19,] <- 1
What I would like to do now is to calculate a series of Put prices with the function EuropeanOption for every index, every day with the following parameters:
- Underlying Price - Today's close from the index XTS
- Strike Price - Yesterday's close from the index XTS
- Implied Vol - Yesterday's realized vol from the index.realized XTS
- All other parameters will just be constants
I have tried to implement this with various attempts using apply and etc but couldn't get it to work. I don't have to use the RQuantLib - if other functions to calculate the price of an European option can make this easier, I am fine with it. Would greatly appreciate any help.
Thank you.