Skip to content

Instantly share code, notes, and snippets.

View mjam03's full-sized avatar

Mark Jamison mjam03

  • Belfast / London
View GitHub Profile
@mjam03
mjam03 / part_01.py
Created April 10, 2023 20:43
Vectorisation What is it and how does it work?
x = 1
y = 2
x + y
@mjam03
mjam03 / part_01.py
Created April 1, 2023 13:28
Test Gistify Markdown
# this code block should gistify as it is >5 lines
x = np.linspace(0, 1, 101)
y = x**2
fig, ax = plt.subplots(figsize=(20,10))
plt.plot(x, y)
ax.set_title('Graph showing y=x**2')
ax.set_xlabel('x')
ax.set_ylabel('y');
@mjam03
mjam03 / part_01.py
Created April 1, 2023 13:25
Untitled
import numpy as np
x = 1+1
y = 2+2
print(x)
@mjam03
mjam03 / d1a18961-ac19-436d-a487-290f100db8dc.py
Created March 27, 2023 21:59
what_exactly_does_'vectorisation'_mean?1
# import numba
from numba import jit
# define our function to profile our compiled code
def find_instr(func, keyword, sig=0, limit=5):
count = 0
# iterate over each of the assembly instructions and check if they match our chosen string
for l in func.inspect_asm(func.signatures[sig]).split('\n'):
if keyword in l or keyword == '':
count += 1
print(l)
@mjam03
mjam03 / 7252392c-c593-4474-af04-5b1b702fe490.py
Created March 27, 2023 21:59
what_exactly_does_'vectorisation'_mean?0
import numpy as np
# python list of 100m ints
L_py = [x for x in range(0, 100_000_000)]
# nd array of 100m ints
L_np = np.arange(0, 100_000_000)
# time each
%timeit sum(L_py)
%timeit np.sum(L_np)
@mjam03
mjam03 / bba7ea7c-1a53-425d-95b6-c99b8a945d3e.py
Created May 6, 2022 08:33
fat_tails_and_their_impact_on_option_prices4
# plot them
fig, ax = plt.subplots(figsize=(25,10))
for e, op_px in op_pxs.items():
if e != 0:
ax.plot(ks, [x/y for x,y in zip(op_px, op_pxs[0])], label="e = {}".format(e))
ax.set_title("Percentage Chg Time Value for Various Option Strikes", fontsize=24)
ax.set_xlabel("Option Strike, K", fontsize=20)
ax.set_ylabel("% Change Time Value", fontsize=20)
@mjam03
mjam03 / 8a26dfa7-fdb4-4ced-885f-dd447723634a.py
Created May 6, 2022 08:33
fat_tails_and_their_impact_on_option_prices3
# set stock params
spot = 100
sigma = 0.20
n = 10000
# option strikes
ks = np.linspace(65, 165, 21)
eps = [0, 0.3, 0.6, 0.85]
# compute closing prices
pxs = {}
@mjam03
mjam03 / 773041c7-3e60-455a-a52b-b37cb6cfe183.py
Created May 6, 2022 08:33
fat_tails_and_their_impact_on_option_prices2
# 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()
@mjam03
mjam03 / ee929a79-ba6d-4fdc-bb0a-d222eb041759.py
Created May 6, 2022 08:33
fat_tails_and_their_impact_on_option_prices1
# define normal pdf
def norm_pdf(x, sigma=1):
return (1 / np.sqrt(2*np.pi)) * (1 / sigma) * np.exp(-0.5 * (x/sigma)**2)
# define x's we want to compute pdf for
xs = np.linspace(-4, 4, 8*200 + 1)
# define epsilsons
eps = [0, 0.1, 0.2, 0.5]
# create pdfs
perturbs = []
@mjam03
mjam03 / ef47f559-f5fc-42d6-a495-d75204f7beae.py
Created May 6, 2022 08:33
fat_tails_and_their_impact_on_option_prices0
# usual suspects
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
import scipy.stats as stats
import warnings
from scipy.integrate import simps
from scipy.interpolate import interp1d