模拟时间倒数 [0,100] 中的布朗运动,并通过模拟 n = 1000 个点来绘制路径。我生成以下代码:
n <- 1000
t <- 100
bm <- c(0, cumsum(rnorm(n,0,sqrt(t/n))))
steps <- seq(0,t,length=n+1)
plot(steps,bm,type="l")
Run Code Online (Sandbox Code Playgroud)
如何模拟标准布朗运动的 50 个样本路径并以不同的颜色显示每个路径,就像一堆轨迹一样?
我认为它会是这样的replicate(50,bm),但是当我这样做时,xy.coords 中出现错误。感谢您的帮助!
在 [0,1] 上模拟布朗桥,并通过模拟 n = 1000 个点来绘制路径。我生成以下代码
n <- 1000
t <- seq(0,1,length=n)
No.Ex<-10
bm <- c(0,cumsum(rnorm(n-1,0,1)))/sqrt(n)
B = replicate(No.Ex,{
bb <- bm - t*bm[n]
})
matplot(B, type = "l", col = cols, lty = 1)
Run Code Online (Sandbox Code Playgroud)
生成几何布朗运动样本路径的代码
simGBM<- function(P0, mu, sigma, T, nSteps, nRepl){
dt<- T/nSteps
muT<- (mu-sigma^2/2)*dt
sigmaT<- sqrt(dt)*sigma
pathMatrix<- matrix(nrow …Run Code Online (Sandbox Code Playgroud)