Skip to content

Instantly share code, notes, and snippets.

@StuartGordonReid
Created June 15, 2015 14:23
Show Gist options
  • Save StuartGordonReid/961cd2b227d023aa51af to your computer and use it in GitHub Desktop.
Save StuartGordonReid/961cd2b227d023aa51af to your computer and use it in GitHub Desktop.
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 - https://gist.github.com/StuartGordonReid/f01f479c783dd40cc21e
"""
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