Created
May 6, 2022 08:33
-
-
Save mjam03/783adeafc5d51adfd9d270f3173c67f1 to your computer and use it in GitHub Desktop.
fat_tails_and_their_impact_on_option_prices2
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
# define our gaussian look-a-like distribution | |
class cust_dist(stats.rv_continuous): | |
# define init with sigma deviation param e | |
def __init__(self, e, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
# init our variance divergence | |
self.e = e | |
# init our cdf and ppf functions | |
self.cdf_func, self.ppf_func = self.create_cdf_ppf() | |
# function to return normal distribution pdf | |
def norm_p(self, x, loc=0, scale=1): | |
return np.exp(-0.5 * ((x - loc )/ scale)**2) / (scale * 2.5066282746310002) | |
# function to normalise the pdf over chosen domain | |
def normalisation(self, x): | |
return simps(self.pdf(x), x) | |
# function to | |
def create_cdf_ppf(self): | |
# define domain as +/-25 sigma | |
xs = np.linspace(-25, 25, 10000001) | |
# normalise our pdf to sum to 1 so it satisfies a distribution | |
norm_constant = self.normalisation(xs) | |
# compute pdfs to be summed to form cdf | |
my_pdfs = self.pdf(xs) / norm_constant | |
# cumsum to form cdf | |
my_cdf = np.cumsum(my_pdfs) | |
# make sure cdf bounded on [0,1] | |
my_cdf = my_cdf / my_cdf[-1] | |
# create cdf and ppf | |
func_cdf = interp1d(xs, my_cdf) | |
func_ppf = interp1d(my_cdf, xs, fill_value='extrapolate') | |
return func_cdf, func_ppf | |
# pdf function for averaged normals | |
def _pdf(self, x): | |
# define lower var distribution prob | |
low = self.norm_p(x, scale=(1 - self.e)**0.5) | |
# define higher var distribution prob | |
high = self.norm_p(x, scale=(1 + self.e)**0.5) | |
return 0.5 * (low + high) | |
# cdf function | |
def _cdf(self, x): | |
return self.cdf_func(x) | |
# inverse cdf function | |
def _ppf(self, x): | |
return self.ppf_func(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment