如何估计R中的Black-Schole或GBM参数

时间:2019-03-29 21:14:30

标签: r

如何估算R代码中GBM或布朗运动过程的漂移和波动? python中有一些代码,但是R中没有任何内容

2 个答案:

答案 0 :(得分:1)

使用Sim.DiffProc包,例如:

library(Sim.DiffProc)

# simulate a trajectory of a GBM
# (theta: drift factor, sigma: volatility)
set.seed(666)
traj <- GBM(N=10000, t0=0, T=1, x0=1, theta=4, sigma=2)

# fit the parameters
fx <- expression( theta[1]*x ) ## drift coefficient of model (theta1 = theta)
gx <- expression( theta[2]*x ) ## diffusion coefficient of model (theta2 = sigma)
fit <- fitsde(data = traj, drift = fx, diffusion = gx, 
              start = list(theta1=3, theta2=3), 
              lower = c(0, 0), control = list(maxit=1000))
coef(fit) ## estimates
#   theta1   theta2 
# 7.042467 2.000404 
confint(fit) ## confidence intervals
#           2.5 %    97.5 %
# theta1 3.121749 10.963185
# theta2 1.972680  2.028127

答案 1 :(得分:0)

最后我找到了答案:

# calculating log returns
returns <- diff(log(price))
# calculate mu (drift)
mu = mean(returns)
# calculate sigma
sigma = sd(returns)