[英]How to estimate Parameters of Black-schole or GBM in R
How can I estimate the Drift and Volatility of GBM or BROWNIAN MOTION PROCESS in R code ?. 如何在R代码中估算GBM或布朗运动过程的漂移和波动? there are some code in python But there in not anything in R python中有一些代码,但是R中没有任何内容
With the Sim.DiffProc
package, an example: 使用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
finally I found my answer : 终于我找到了答案:
# calculating log returns
returns <- diff(log(price))
# calculate mu (drift)
mu = mean(returns)
# calculate sigma
sigma = sd(returns)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.