尝试使用R包fOptions计算一组选项的理论价格:
set.seed(1)
library(fOptions)
#Defining sample data frame
Type <- c("Call", "Call", "Call", "Call", "Call")
Stock.Price <- runif(5, max=50, min=10)
Strike <- runif(5, max=50, min=10)
Time <- runif(5, max=2, min=0.1)
Interest <- runif(5, max=1, min=0)
Volatility <- runif(5, max=1, min=0)
df <- data.frame(Type, Stock.Price,Strike,Time,Interest,Volatility)
View(df)
attach(df)
> df
Type Stock.Price Strike Time Interest Volatility
1 Call 29.74165 14.31775 1.5875722 0.4772301 0.43809711
2 Call 17.44870 38.94844 1.1507690 0.7323137 0.24479728
3 Call 43.09493 26.45098 1.1064672 0.6927316 0.07067905
4 Call 36.73867 42.83785 1.5997768 0.4776196 0.09946616
5 Call 41.76959 35.88241 0.1443293 0.8612095 0.31627171
#Pricing via Black-Scholes is simple
bs.val <- GBSOption("c", Stock.Price,Strike,Time,Interest,Interest,Volatility)
bs.prices <- bs.val@price
> bs.prices
[1] 23.037969 2.147545 30.804657 16.786512 10.097270
#Pricing via CRR gives an error
crr.val <- CRRBinomialTreeOption("ca",Stock.Price,Strike,Time,Interest,Interest,Volatility,30)
crr.prices <- crr.val@price
> crr.prices
[1] 6265524
此外,调用crr.val时会出现以下错误:
Warning messages:
1: In u^(0:n) :
longer object length is not a multiple of shorter object length
2: In S * u^(0:n) :
longer object length is not a multiple of shorter object length
3: In d^(n:0) :
longer object length is not a multiple of shorter object length
4: In S * u^(0:n) * d^(n:0) - X :
longer object length is not a multiple of shorter object length
我希望得到一个价格矢量,就像bs.prices一样。