import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as smWe shall next study Gaussian process regression. The most canonical example of a Gaussian process is the Brownian Motion. Here is how it can be simulated.
Brownian Motion¶
is Brownian motion. The following algorithm simulates Brownian Motion on for some fixed (e.g., ).
M = 65 # time horizon
N = 5000 # number of grid points
dt = M / N # step size
t = np.linspace(0, M, N+1)
# generate increments
increments = np.sqrt(dt) * np.random.randn(N)
# Brownian path
B = np.zeros(N+1)
B[1:] = np.cumsum(increments)
plt.figure(figsize=(10, 5))
plt.plot(t, B)
plt.xlabel("t")
plt.ylabel("B(t)")
plt.title("Brownian Motion on [0,M]")
plt.show()

In the plot above, successive values are joined by straight lines. We can also plot by assuming that the value is constant in between successive values. This is done below.
plt.figure(figsize=(10, 5))
plt.step(t, B, where="post")
plt.show()
When is large, we cannot spot any differences between the above two plots (the differences are much more apparent when is small).