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
x = 1 | |
y = 2 | |
x + y |
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
# 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'); |
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 numpy as np | |
x = 1+1 | |
y = 2+2 | |
print(x) |
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 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) |
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 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) |
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
# 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) |
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
# 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 = {} |
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() |
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 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 = [] |
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
# 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 |
NewerOlder