April 2019
Intermediate to advanced
426 pages
11h 13m
English
Let's create a class named FDCnDo that inherits from the FDCnEu class we discussed earlier. We will take into account the barrier price in the constructor method, while leaving the rest of the Crank-Nicolson implementation in the FDCnEu class unchanged:
In [ ]: import numpy as np """ Price a down-and-out option by the Crank-Nicolson method of finite differences. """ class FDCnDo(FDCnEu): def __init__( self, S0, K, r=0.05, T=1, sigma=0, Sbarrier=0, Smax=1, M=1, N=1, is_put=False ): super(FDCnDo, self).__init__( S0, K, r=r, T=T, sigma=sigma, Smax=Smax, M=M, N=N, is_put=is_put ) self.barrier = Sbarrier self.boundary_conds = np.linspace(Sbarrier, ...
Read now
Unlock full access