Skip to content

Instantly share code, notes, and snippets.

# filename, my_score, optimal_value, n_jobs, n_machines
[['data/JSPLIB/instances/abz5', 1288, 1234.0, 10, 10],
['data/JSPLIB/instances/abz6', 1006, 943.0, 10, 10],
['data/JSPLIB/instances/abz7', 785, 656.0, 20, 15],
['data/JSPLIB/instances/abz8', 824, nan, 20, 15],
['data/JSPLIB/instances/abz9', 852, nan, 20, 15],
['data/JSPLIB/instances/ft06', 60, 55.0, 6, 6],
['data/JSPLIB/instances/ft10', 1062, 930.0, 10, 10],
['data/JSPLIB/instances/ft20', 1272, 1165.0, 20, 5],
get_ipython().run_line_magic('load_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
import seaborn
import graphics
def color_palette(n_colors):
'''
returns a list of rgb-colors
'''
palettes = [seaborn.color_palette(each, 10) for each in
'cubehelix Set2 husl'.split()]
# doc: https://ipython.org/ipython-doc/3/config/extensions/autoreload.html
# to have this run ever time you start ipython, add this to the ipython config,
# which is located in ~/.ipython/profile_default/startup/0_imports.py (if this file doesn't exist, just make it)
get_ipython().run_line_magic('load_ext', 'autoreload')
get_ipython().run_line_magic('autoreload', '2')
# for oppgave 3 som tilsvarer 2a
comp_fun = lambda opt, S, V: max(0, a*S+b, V); o = Option(S=S0, K=100, T=5, r=.02, div=.07, vol=.25)
for _ in range(100):
val_hest = o.BinomHeston(50, 'call', American=True, var_var=.0, kappa=0, comp_fun=comp_fun)
print(val_hest)
utils.cprint(f'Heston valuation, 2b: [y]{val_hest:.4f}')
def BinomHeston(self, n_steps, opt_type, American=False, comp_fun=None, kappa=None, var_mean=None, var_var=None, return_Hs=False):
'''
Calculates option value with stochastic volatility according to a
discretization of the Heston model presented on p. 754
===========
n_steps: number of steps in binomial calculation
opt_type: 'call' or 'put'
American: Boolean; if True then value of a `type` American option is calculated
def BarrierAmerican(self, n_steps, opt_type, H, American=False, comp_fun=None, kappa=None, var_mean=None, var_var=None, return_Hs=False):
'''
For exercise 4c.
'''
S, K, vol, r, T, div = self.S, self.K, self.vol, self.r, self.T, self.div
S0 = S
h = T / n_steps
u = np.exp((r-div)*h + vol*np.sqrt(h))
d = np.exp((r-div)*h - vol*np.sqrt(h))
import matplotlib.pyplot as plt
import seaborn
from tqdm import tqdm
import numpy as np
plt.ion()
T_mat = 5 # years
vol0 = .3
var_mean = vol0**2
var_var=.2**2
kappa = .0
function ppwd () {
pwd > /tmp/ppwd.dat
}
function ccd () {
if [ -f /tmp/ppwd.dat ]; then
cd `cat /tmp/ppwd.dat`
pwd
else;
echo "could not do ccd command. No ppwd done."
fi
float_matrix = np.random.randint(1, 100, size=(100, 100), dtype=np.float64)
int_matrix = np.array(float_matrix, np.int64) # alternatively use np.int8 also