File:Ornstein-Uhlenbeck-trace.svg

Summary

Description
English: A sampled traces of an Ornstein-Uhlenbeck process with θ=1 and σ=1.
Date
Source Own work
Author Geek3
SVG development
InfoField
Source code
InfoField

Matplotlib source code

The plot was generated with Matplotlib
#! /usr/bin/env python3
# -*- coding:utf8 -*-

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
import numpy as np
from math import *

plt.rcParams['font.sans-serif'] = 'DejaVu Sans'
np.random.seed(42)

mu = 0. # long-term mean
tau = 1. # relaxation time scale
theta = 1. / tau # mean reversion rate
sigma = 1. # diffusion
D = sigma**2 / 2 # diffusion constant
sigmaX = sigma / sqrt(2 * theta) # standard deviation of X
t = np.linspace(0, 30, 5001)

dt = t[1:] - t[:-1]
randnorm = np.random.normal(0, 1, len(t))
X = np.empty_like(t)
X[0] = mu + sigmaX * randnorm[0]

for i in range(1, len(t)):
    X[i] = X[i-1] + (mu - X[i-1]) * dt[i-1] * theta + sigma * sqrt(dt[i-1]) * randnorm[i]

fig = plt.figure(figsize=(520 / 90.0, 340 / 90.0), dpi=72)
plt.plot(t, X)
plt.grid(True)
plt.gca().yaxis.set_major_locator(MultipleLocator(1))
plt.xlim(t[0], t[-1])
plt.ylim(-2.1, 2.1)
plt.xlabel(r't / $\theta^{-1}$')
plt.ylabel('X')
plt.tight_layout()
plt.savefig('Ornstein-Uhlenbeck-trace.svg')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Ornstein-Uhlenbeck-trace.svgCategory:Self-published work
Category:Ornstein-Uhlenbeck process
Category:CC-BY-SA-4.0 Category:Ornstein-Uhlenbeck process Category:Self-published work Category:Valid SVG created with Matplotlib code