Skip to content

Instantly share code, notes, and snippets.

@StuartGordonReid
Created June 15, 2015 14:17
Show Gist options
  • Save StuartGordonReid/c3eb91be480802631af0 to your computer and use it in GitHub Desktop.
Save StuartGordonReid/c3eb91be480802631af0 to your computer and use it in GitHub Desktop.
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 brownian_motion_log_returns(param):
"""
This method returns a Wiener process. The Wiener process is also called Brownian motion. For more information
about the Wiener process check out the Wikipedia page: http://en.wikipedia.org/wiki/Wiener_process
:param param: the model parameters object
:return: brownian motion log returns
"""
sqrt_delta_sigma = math.sqrt(param.all_delta) * param.all_sigma
return nrand.normal(loc=0, scale=sqrt_delta_sigma, size=param.all_time)
def brownian_motion_levels(param):
"""
Returns a price sequence whose returns evolve according to a brownian motion
:param param: model parameters object
:return: returns a price sequence which follows a brownian motion
"""
return convert_to_prices(param, brownian_motion_log_returns(param))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment