我正在研究我的建模技巧,并且正在 Black Scholes 尝试一下。这个想法是使用当前期权价格 (x) 来估计波动率 (b)。
当我运行 nlsLM 时,我收到此错误:
Error in assign(i, data[[i]], envir = env) :
attempt to use zero-length variable name
我看不出错误在哪里,我已经从公式中删除了所有变量,并用它们在这个特定情况下的数值替换了它们。x 和 b 保留为变量。我在没有 d1 和 d2 的情况下运行了这个,换句话说,将每个长公式放在各自的 pnorm() 中,但也没有运气。
x 是执行价格,y 是截至 2014 年 12 月 12 日的 12/20/14 到期的 GOOG 看涨期权的价格。
这是重现错误的代码。
df <- structure(list(x = c(505, 510, 512.5, 515, 517.5, 520, 522.5,
525, 527.5, 530, 532.5), y = c(17.7, 12.5, 12, 9.2, 7.82, 6.3,
5.1, 4.1, 3.21, 2.45, 1.9)), .Names = c("x", "y"),
row.names = c(NA, -11L), class = "data.frame")
f <- function(x, b){
d1 = (1/(b*sqrt(0.021918)))*(log(518.66/x) + (0.0025+b^2/2) * 0.021918)
d2 = (1/(b*sqrt(0.021918)))*(log(518.66/x) - (0.0025+b^2/2) * 0.021918)
return (pnorm(d1)*518.66 - pnorm(d2)*x*exp(-0.0025*0.021918))
}
library(minpack.lm)
test <- nlsLM(y~f(x, b), data=df, start=list((b=0.50)))
谢谢你。