Created
June 15, 2015 14:23
-
-
Save StuartGordonReid/961cd2b227d023aa51af to your computer and use it in GitHub Desktop.
Ornstein Uhlenbeck Stochastic Process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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