1

I am trying to draw a Implied Graph For BAC company. I did the codes to draw implied volatility vs Strike Prices (below). The plot code below will draw the graph for Implied Volatility vs Strike prices on just ONE date (Mar.27.2020)

May I know how do I edit my codes to draw a 3D graph which draws the Implied Volatility VS Strike Prices and Time To maturity please?

install.packages("quantmod")
install.packages("jsonlite")
install.packages("lubridate")
install.packages("fOptions")
library(quantmod)
library(jsonlite)
library(lubridate)
library(fOptions)

# Getting option chain data of Bank of America (all expiries)
CHAIN <- getOptionChain("BAC", NULL)
# Setting maturity of options as T (in years)
maturity <- as.Date(names(CHAIN), format="%b.%d.%Y")
today <- as.Date(Sys.Date(), format="%Y-%m-%d")
T <- as.numeric((maturity - today)/365)
# Interest Rate = 2%pa
r = 0.02;ImpVol<-1:1
# Getting latest price of Bank of America shares
getSymbols("BAC",from=today,to=today,src="yahoo")
S=as.numeric(Ad(`BAC`))
# Plot implied volatility over strike price given market prices of options (blue line)
for (i in 1:length(CHAIN$Mar.27.2020$calls$Strike)){ImpVol[i]<- GBSVolatility(CHAIN$Mar.27.2020$calls$Last[i], "c", S, CHAIN$Mar.27.2020$calls$Strike[i], T[1], r, 0)}

  #GBSVolatility(CHAIN$Mar.27.2020$calls$Last[i], "c", S, CHAIN$Mar.27.2020$calls$Strike[i],0.00274, r, 0)}
length(CHAIN$Mar.27.2020$calls$Strike)
length(ImpVol)
plot(CHAIN$Mar.27.2020$calls$Strike[!is.na(ImpVol)], ImpVol[!is.na(ImpVol)], xlab = "Strike price", ylab = "Implied volatility", lwd =3, type = "l", col
     = "blue")
zx8754
  • 52,746
  • 12
  • 114
  • 209

0 Answers0