Simulation of Brownian motion#

# Author: Steven Golovkine <steven_golovkine@icloud.com>
# License: MIT

# Load packages
import numpy as np

from FDApy.simulation import Brownian
from FDApy.visualization import plot

The package provides a class to simulate different types of Brownian motion using the following classe: Brownian. The type of Brownian motion can be standard, geometric or fractional.

# Set general parameters
rng = 42
n_obs = 10
argvals = np.arange(0, 1.01, 0.01)

# Set Brownian parameters
init_point = 1.0
mu = 1.0
sigma = 0.5
hurst = 0.8

Standard Brownian motion#

A standard Brownian motion is a stochastic process define as \(\{X_t\}_{t \geq 0}\). The process has the following properties:

  • \(\{X_t\}_{t \geq 0}\) is a Gaussian process.

  • For \(s, t \geq 0\), \(\mathbb{E}(X_t) = 0\) and \(\mathbb{E}(X_sX_t) = \min(s, t)\).

  • The function \(t \rightarrow X_t\) is continuous with probablity \(1\).

To simulate a standard Brownian motion, you can use the following code:

br = Brownian(name="standard", random_state=rng)
br.new(n_obs=n_obs, argvals=argvals, init_point=init_point)

_ = plot(br.data)
plot brownian

Geometric Brownian motion#

A geometric Brownian motion is a stochastic process \(\{X_t\}_{t \geq 0}\) in which the logarithm of the randomly varying quantity is a Brownian motion with drift.

The process \(\{X_t\}_{t \geq 0}\) satisfies the following stochastic differential equation:

\[dX_t = \mu X_t dt + \sigma X_t dW_t\]

where \(\{W_t\}_{t \geq 0}\) is a Brownian motion, \(\mu\) is the percentage drift and \(\sigma\) is the percentage volatility.

To simulate a geometric Brownian motion, you can use the following code:

br = Brownian(name="geometric", random_state=rng)
br.new(n_obs=n_obs, argvals=argvals, init_point=init_point, mu=mu, sigma=sigma)

_ = plot(br.data)
plot brownian

Fractional Brownian motion#

A fractional Brownian motion is a stochastic process \(\{X_t\}_{t \geq 0}\) that generalize Brownian motion. Let \(H \in (0, 1)\) be the Hurst parameter. The process has the following properties:

  • \(\{X_t\}_{t \geq 0}\) is a Gaussian process.

  • For \(s, t \geq 0\), \(\mathbb{E}(X_t) = 0\) and \(\mathbb{E}(X_sX_t) = \frac{1}{2}\left(|s|^{2H} + |t|^{2H} - |s - t|^{2H}\right)\).

  • The function \(t \rightarrow X_t\) is continuous with probablity \(1\).

The value of \(H\) defines the process. If \(H = 1/2\), \(\{X_t\} _{t \geq 0}\) is a Brownian motion. If \(H > 1/2\), the increments of \(\{X_t\}_{t \geq 0}\) are positively correlated. If \(H < 1/2\), the increments of \(\{X_t\}_{t \geq 0}\) are negatively correlated.

To simulate a fractional Brownian motion, you can use the following code:

br = Brownian(name="fractional", random_state=rng)
br.new(n_obs=n_obs, argvals=argvals, hurst=hurst)

_ = plot(br.data)
plot brownian

Total running time of the script: (0 minutes 0.279 seconds)

Gallery generated by Sphinx-Gallery