This file contains hidden or 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
| get_ipython().run_line_magic('load_ext', 'autoreload') | |
| get_ipython().run_line_magic('autoreload', '2') | |
This file contains hidden or 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 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()] |
This file contains hidden or 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
| # 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') |
This file contains hidden or 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
| # 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}') |
This file contains hidden or 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
| 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 | |
This file contains hidden or 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
| 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)) | |
This file contains hidden or 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 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 |
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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 | |
This file contains hidden or 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
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | |
| <properties> | |
| <maven.compiler.source>1.6</maven.compiler.source> | |
| <maven.compiler.target>1.6</maven.compiler.target> | |
| </properties> | |
| <repositories> | |
| </repositories> | |
| <modelVersion>4.0.0</modelVersion> | |
| <groupId>com.mycompany.app</groupId> |