Skip to content

Instantly share code, notes, and snippets.

Created June 15, 2015 14:23
  • Star 4 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ornstein Uhlenbeck Stochastic Process
import math
import numpy
import random
import decimal
import scipy.linalg
import numpy.random as nrand
import matplotlib.pyplot as plt
Note that this Gist uses the Model Parameters class found here -
def ornstein_uhlenbeck_levels(param):
This method returns the rate levels of a mean-reverting ornstein uhlenbeck process.
:param param: the model parameters object
:return: the interest rate levels for the Ornstein Uhlenbeck process
ou_levels = [param.all_r0]
brownian_motion_returns = brownian_motion_log_returns(param)
for i in range(1, param.all_time):
drift = param.ou_a * (param.ou_mu - ou_levels[i-1]) * param.all_delta
randomness = brownian_motion_returns[i - 1]
ou_levels.append(ou_levels[i - 1] + drift + randomness)
return ou_levels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment