设${ B(t) }$是布朗运动,${ X(t) }$是漂移$X(t) =B(T)+ t$和$\tau(x) := \inf{t >0:X(T)= x}$的布朗运动。
使用以下方法通过模拟找到$\mathbb{E}\τ(1)$:
足够细网格的
到目前为止我对此的看法。
#Set b_0 = 0 and b_1 = rnorm(1)
b_t <- c()
b_t[1] <- 0
b_t[2] <- rnorm(1)
x=1
#Find the first passage time so when does X(t) hit 1 for the first time
while(b_t[x]<1){
b_t[x+2] <- rnorm(n = 1, mean = (b_t[x+1]- b_t[x] )/2, sd = x/2)
x <- x+1
}
我相信我的代码无法正确地生成二元分段。有人能帮忙吗?
发布于 2020-08-01 05:00:51
这是我想出来的。不过,以前还没有做过这个特别的模拟,所以可能会有错误--小心:
# Total time to run simulation
TT <- 100
# Drift term
mu <- 0.01
# Variance term
sigma <- 2
# Time step
delta_t <- 0.05
# Level to be crossed
x <- 30
# Time vector
T <- seq(0, TT, delta_t)
# Unit normals
Z <- rnorm(length(T), 0, 1)
# Brownian motion variates
X <- cumsum(sigma* sqrt(T)*Z + mu*T)
# Plot and print results
plot(T, X, type="l", main="Brownian Motion")
if(x > 0 && max(X) > x) {
tau <- T[min(which(X > x))]
cat("Time at which BM crossed ", x, ": ", tau, sep="")
} else if(x <= 0 && min(X) < x) {
tau <- T[min(which(X < x))]
cat("Time at which BM crossed ", x, ": ", tau, sep="")
} else {
cat("BM didn't cross ", x, sep="")
}
https://stackoverflow.com/questions/63207825
复制