PyMPDATA_examples.Arabas_and_Farhat_2020.setup2_american_put
1import numpy as np 2import PyMPDATA_examples.Arabas_and_Farhat_2020.Bjerksund_and_Stensland_1993 as BS93 3import PyMPDATA_examples.Arabas_and_Farhat_2020.Black_Scholes_1973 as BS73 4from pystrict import strict 5 6 7@strict 8class Settings: 9 amer = True 10 l2_opt = 2.05 11 S_min = 0.05 12 S_max = 500 13 K = 100 14 r = 0.08 15 sigma = 0.2 16 n_iters = 2 17 18 def __init__(self, *, T: float, C_opt: float, S0: float): 19 self.T = T 20 self.C_opt = C_opt 21 self.S0 = S0 22 self.S_match = S0 23 24 def payoff(self, S: np.ndarray): 25 return np.exp(-self.r * self.T) * (np.maximum(0, self.K - S)) 26 27 def analytical_solution(self, S: [np.ndarray, float], amer=True): 28 if not amer: 29 return BS73.p_euro( 30 S, K=self.K, T=self.T, r=self.r, b=self.r, sgma=self.sigma 31 ) 32 return BS93.p_amer(S, K=self.K, T=self.T, r=self.r, b=self.r, sgma=self.sigma)
@strict
class
Settings:
8@strict 9class Settings: 10 amer = True 11 l2_opt = 2.05 12 S_min = 0.05 13 S_max = 500 14 K = 100 15 r = 0.08 16 sigma = 0.2 17 n_iters = 2 18 19 def __init__(self, *, T: float, C_opt: float, S0: float): 20 self.T = T 21 self.C_opt = C_opt 22 self.S0 = S0 23 self.S_match = S0 24 25 def payoff(self, S: np.ndarray): 26 return np.exp(-self.r * self.T) * (np.maximum(0, self.K - S)) 27 28 def analytical_solution(self, S: [np.ndarray, float], amer=True): 29 if not amer: 30 return BS73.p_euro( 31 S, K=self.K, T=self.T, r=self.r, b=self.r, sgma=self.sigma 32 ) 33 return BS93.p_amer(S, K=self.K, T=self.T, r=self.r, b=self.r, sgma=self.sigma)