我用两种方法模拟标准布朗运动,但是不知道做的对不对,因为两种方法作图 结果不一样
##第一种方法:
##n=1000
S1000=c();
n=1000;
seq_t=sort(runif(n));
for (i in 1:n)
{ t=runif(1);
nt=round(n*t);
e=rnorm(nt);
S1000[nt]=sum(e)/sqrt(n);
}
##第二种方法
##n=1000
n=1000;
Brown1000=c();
t=sort(runif(n));
Brown1000[1]=0;
Brown1000[2]=Brown1000[1]+rnorm(1)*sqrt(t[1]);
for (i in 2:n)
{ w=Brown1000+rnorm(1)*sqrt(t[i+1]-t);
Brown1000=c(Brown1000,w);
}
#Brownian motion
T = 1 # end of interval[0,T]
N = 300
x=0 #initial value of the process at time t0.
t0=0 #initial time
dt <- (T-t0)/N
t <- seq(t0,T, length=N+1) # set up scale
X <- ts(cumsum(c(x,rnorm(N)*sqrt(dt))),start=t0, deltat=dt)
ts.plot(X)
进一步了解,请参考
package "sde"
Simulation and Inference for Stochastic Differential Equations