我正在模拟一维对称随机游走过程:
我想模拟1000个不同的
哪个函数可以让我用随机游走时间序列
y[t] = y[t-1] + epsilon[t]
在时间段t
中,白噪声用epsilon[t] ~ N(0,1)
表示。在这个过程中没有漂移。
此外,RW是对称的,因为Pr(y[i] = +1) = Pr(y[i] = -1) = 0.5
。
这是我的R代码:
set.seed(1)
t=1000
epsilon=sample(c(-1,1), t, replace = 1)
y<-c()
y[1]<-0
for (i in 2:t) {
y[i]<-y[i-1]+epsilon[i]
}
par(mfrow=c(1,2))
plot(1:t, y, type="l", main="Random walk")
outcomes <- sapply(1:1000, function(i) cumsum(y[i]))
hist(outcomes)
我想模拟1000个不同的
y[i,t]
系列 (i=1,…,1000; t=1,…,1000
)。 (之后,我将检查在t=3
、t=5
和t=10
时回到原点 (y[1]=0
) 的概率。)哪个函数可以让我用随机游走时间序列
y[t]
进行这种重复?