所以我正在使用RQuantLib的AmericanOption功能。如果输入是单个数字,它可以正常工作,例如:
AmericanOption(type = 'call', underlying = 73.59, strike = 74, dividendYield
= 0, riskFreeRate = 0.006, maturity = 0.25, volatility= 0.2, timeSteps =
150, gridPoints = 149, engine="CrankNicolson")
但是,由于我的时间序列数据包含相同选项的日常数据,例如:
Time underlying strike ...
10-01 73 74
10-02 74 74
10-03 75 74
...
显然,我想将定价函数应用于每个数据点,并将结果输出为包含每天结果的新数据框。
由于我已经将基础价格和执行价格作为数据列表,我所做的是为股息创建0的序列("股息"),无风险的顺序为0.006(" riskfree&# 34;),衰变成熟度为:
end <- 21/252
interval <- 1/252
opmaturity <- seq(0.25, end, by=-interval)
(从3个月到成熟到1个月到期)
所以我当然不能做到以下几点:
AmericanOption(type = 'call', underlying = RR$Stock, strike =
RR$Strike.Price, dividendYield = dividend, riskFreeRate = riskfree, maturity
= ematurity, volatility= vol, timeSteps = 150, gridPoints = 149,
engine="CrankNicolson")
因为函数需要单值输入。
那么,我该如何正确地告诉函数输入时间序列数据?
由于
答案 0 :(得分:0)
使用mapply
功能就足够了
mapply(AmericanOption, type = 'call', underlying = RR$Stock, strike =
RR$Strike.Price, dividendYield = dividend, riskFreeRate = riskfree, maturity
= ematurity, volatility= vol, timeSteps = 150, gridPoints = 149,
engine="CrankNicolson")