Skip to content

Instantly share code, notes, and snippets.

View StuartGordonReid's full-sized avatar

Stuart Gordon Reid StuartGordonReid

View GitHub Profile
@StuartGordonReid
StuartGordonReid / DrawdownAdjustedReturns.py
Created June 12, 2015 13:58
Risk adjusted returns based on Drawdown risk
"""
Note that this Gist uses functions made available in another Gist -
https://gist.github.com/StuartGordonReid/67a1ec4fbc8a84c0e856
"""
def calmar_ratio(er, returns, rf):
return (er - rf) / max_dd(returns)
@StuartGordonReid
StuartGordonReid / ModelParameters.py
Created June 15, 2015 14:13
Model Parameters Class
class ModelParameters:
"""
Encapsulates model parameters
"""
def __init__(self,
all_s0, all_time, all_delta, all_sigma, gbm_mu,
jumps_lamda=0.0, jumps_sigma=0.0, jumps_mu=0.0,
cir_a=0.0, cir_mu=0.0, all_r0=0.0, cir_rho=0.0,
ou_a=0.0, ou_mu=0.0,
def convert_to_returns(log_returns):
"""
This method exponentiates a sequence of log returns to get daily returns.
:param log_returns: the log returns to exponentiated
:return: the exponentiated returns
"""
return numpy.exp(log_returns)
def convert_to_prices(param, log_returns):
@StuartGordonReid
StuartGordonReid / StochasticProcessesGrapher.py
Created June 15, 2015 14:15
Stochastic Processes Grapher -
def plot_stochastic_processes(processes, title):
"""
This method plots a list of stochastic processes with a specified title
:return: plots the graph of the two
"""
plt.style.use(['bmh'])
fig, ax = plt.subplots(1)
fig.suptitle(title, fontsize=16)
ax.set_xlabel('Time, t')
ax.set_ylabel('Simulated Asset Price')
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
@StuartGordonReid
StuartGordonReid / GeometricBrownianMotion.py
Created June 15, 2015 14:18
Geometric Brownian Motion 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
@StuartGordonReid
StuartGordonReid / JumpDiffusionProcess.py
Created June 15, 2015 14:20
Jump Diffusion Geometric Brownian Motion 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
@StuartGordonReid
StuartGordonReid / HestonStochasticVolatility.py
Last active July 26, 2019 07:57
Heston Stochastic Volatility 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
@StuartGordonReid
StuartGordonReid / CoxIngersollRoss.py
Created June 15, 2015 14:22
Cox Ingersoll Ross 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
@StuartGordonReid
StuartGordonReid / OrnsteinUhlenbeck.py
Created June 15, 2015 14:23
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