I am trying to solve exercise 3.9.10 on p. 66 of Ubbo F. Wiersema's "Brownian Motion Calculus" (John Wiley & Sons, 2008), which asks to simulate the stochastic integral $$ \int_0^1 B(t)\ dB(t) $$ by initially using a partition of $[0, 1]$ into $n = 2^8$ sub-intervals and running $1000$ simulations of the discrete stochastic integral $$ I^{(n)} = \sum_{i = 0}^{n - 1} B(t_i)\left(B(t_{i + 1}) - B(t_i)\right) $$ for this $n$, then repeating this procedure by repeatedly doubling $n$ to $2^{11}$. The exercise asks to compare the results against the mean and variance of the closed form of the integral, namely $$ \int_0^1 B(t)\ dB(t) = \frac{1}{2} B(1)^2 - \frac{1}{2} $$ which are $0$ and $\frac{1}{2}$, respectively (since $B(1)$ is a standard normal random variable).
I have written a simulation in R, as shown below. However, the variances resulting from this simulation are
> v_sim
8 9 10 11
0.4771895 0.4304475 0.5260542 0.4664552
which don't appear to converge to the anticipated value $0.5$. The same phenomenon is observed when changing the seed to $2$ and $3$ as well as when the number of sub-intervals is increased to $2^{12}$ to $2^{15}$. What am I doing wrong?
NSIMS <- 1000L # number of simulations of the integral for every "level"
LEVELS <- 8L:11L # level n corresponds to 2^n sample points between 0 and 1
SEED <- 1
set.seed(SEED)
sims <- data.frame(simid = 1L:NSIMS) # sims contains one colum per every level.
# The column simid is a dummy column
# intended to avoid an error message
# when columns are added to sims
# on the fly inside the following loop.
# This column is deleted after the loop
# ends.
for (n in LEVELS)
{
nticks <- 2^n # nticks is the number of sample points between 0 and 1
delta <- 1/nticks
ticks <- seq(from = 0, to = 1, by = delta)
std <- sqrt(delta)
sim <- vector(mode = "numeric", length = NSIMS)
for (j in 1L:NSIMS)
{
b <- cumsum(c(0, rnorm(nticks, sd = std))) # b is a simulated
# Brownian motion path
# sampled at the tick
# marks.
integral <- 0
for (i in 1L:(length(b) - 1L))
{
integral <- integral + b[i]*(b[i + 1] - b[i])
}
sim[j] <- integral
}
sims[, as.character(n)] <- sim
}
sims$simid <- NULL
m_sim <- sapply(sims, mean)
v_sim <- sapply(sims, var)
cumsum
in place of thei
loop. Matrix/apply could also be preferred here to data frame/sapply, etc. This is a very good exercise. Hints: state clearly what you expect to find and why, find the joint distribution of the $n$ summed variables say $X_i$. $\endgroup$