April 2019
Intermediate to advanced
426 pages
11h 13m
English
Let's convert the binomial tree pricing into a lattice by CRR. We can inherit from the BinomialCRROption class (which in turn inherits the BinomialTreeOption class) and create a new class named BinomialCRRLattice, as follows:
In [ ]: import numpy as np class BinomialCRRLattice(BinomialCRROption): def setup_parameters(self): super(BinomialCRRLattice, self).setup_parameters() self.M = 2*self.N + 1 def init_stock_price_tree(self): self.STs = np.zeros(self.M) self.STs[0] = self.S0 * self.u**self.N for i in range(self.M)[1:]: self.STs[i] = self.STs[i-1]*self.d def init_payoffs_tree(self): odd_nodes = self.STs[::2] # Take odd nodes only if self.is_call: return np.maximum(0, odd_nodes-self.K) ...
Read now
Unlock full access