Jump Diffusion Geometric Brownian Motion 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 jump_diffusion_process(param): | |
""" | |
This method produces a sequence of Jump Sizes which represent a jump diffusion process. These jumps are combined | |
with a geometric brownian motion (log returns) to produce the Merton model. | |
:param param: the model parameters object | |
:return: jump sizes for each point in time (mostly zeroes if jumps are infrequent) | |
""" | |
assert isinstance(param, ModelParameters) | |
s_n = time = 0 | |
small_lamda = -(1.0 / param.lamda) | |
jump_sizes = [] | |
for k in range(0, param.all_time): | |
jump_sizes.append(0.0) | |
while s_n < param.all_time: | |
s_n += small_lamda * math.log(random.uniform(0, 1)) | |
for j in range(0, param.all_time): | |
if time * param.all_delta <= s_n * param.all_delta <= (j + 1) * param.all_delta: | |
# print("was true") | |
jump_sizes[j] += random.normalvariate(param.jumps_mu, param.jumps_sigma) | |
break | |
time += 1 | |
return jump_sizes | |
def geometric_brownian_motion_jump_diffusion_log_returns(param): | |
""" | |
This method constructs combines a geometric brownian motion process (log returns) with a jump diffusion process | |
(log returns) to produce a sequence of gbm jump returns. | |
:param param: model parameters object | |
:return: returns a GBM process with jumps in it | |
""" | |
assert isinstance(param, ModelParameters) | |
jump_diffusion = jump_diffusion_process(param) | |
geometric_brownian_motion = geometric_brownian_motion_log_returns(param) | |
return numpy.add(jump_diffusion, geometric_brownian_motion) | |
def geometric_brownian_motion_jump_diffusion_levels(param): | |
""" | |
This method converts a sequence of gbm jmp returns into a price sequence which evolves according to a geometric | |
brownian motion but can contain jumps at any point in time. | |
:param param: model parameters object | |
:return: the price levels | |
""" | |
return convert_to_prices(param, geometric_brownian_motion_jump_diffusion_log_returns(param)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment