Skip to content

Instantly share code, notes, and snippets.

@addiversitas
Last active October 18, 2020 13:52
Show Gist options
  • Save addiversitas/6610ad0dc2bd1ee7f561caab032d6f31 to your computer and use it in GitHub Desktop.
Save addiversitas/6610ad0dc2bd1ee7f561caab032d6f31 to your computer and use it in GitHub Desktop.
iv calculation for APPL calls and puts including dividend yield
divYield <- getQuote(symbol, what = yahooQF("Dividend Yield"))$`Dividend Yield`
if(is.na(divYield)){divYield <- 0}
#calculating IV
calls$iv <- apply(calls, 1, getIV, S = lastPrice, r = 0.0011, q = divYield, type = "call")
puts$iv <- apply(puts, 1, getIV, S = lastPrice, r = 0.0011, q = divYield, type = "put")
#create grids
library(reshape2)
ivGridCalls <- acast(calls, ttm ~ moneyness, value.var = "iv")
ivGridPuts <- acast(puts, ttm ~ moneyness, value.var = "iv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment