从多变量XTS的波动率和现货价格计算期权价格

时间:2022-08-26 12:37:52

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:

我现在要做的是使用以下参数每天为每个索引计算一系列PutO价格功能:

  • Underlying Price - Today's close from the index XTS
  • 标的价格 - 今天接近XTS指数
  • Strike Price - Yesterday's close from the index XTS
  • 罢工价格 - 昨日收盘指数XTS
  • Implied Vol - Yesterday's realized vol from the index.realized XTS
  • Implied Vol - 昨天从索引中实现了卷。实现了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.

我试图通过使用apply等进行各种尝试来实现它,但无法使其工作。我没有必要使用RQuantLib - 如果其他功能来计算欧洲选项的价格可以使这更容易,我很好。非常感谢任何帮助。

Thank you.

谢谢。

1 个解决方案

#1


1  

OK I got it working

好的我搞定了

puts.unwind <- mapply(EuropeanOption,"put",index,na.locf(lag(index,1),fromLast=TRUE),0,0,29/365‌​,index.realized) 
puts.unwind <- xts(matrix(as.numeric(puts.unwind[1,]),nrow(index),ncol(index)),index(index)) 

First line calculates the puts and the second line extracts only the prices and reformats into an XTS.

第一行计算掉货币,第二行只提取价格并重新格式化为XTS。

#1


1  

OK I got it working

好的我搞定了

puts.unwind <- mapply(EuropeanOption,"put",index,na.locf(lag(index,1),fromLast=TRUE),0,0,29/365‌​,index.realized) 
puts.unwind <- xts(matrix(as.numeric(puts.unwind[1,]),nrow(index),ncol(index)),index(index)) 

First line calculates the puts and the second line extracts only the prices and reformats into an XTS.

第一行计算掉货币,第二行只提取价格并重新格式化为XTS。