def pricer(self, S0, K, r, T, N, sigma, is_call=True, div=0., is_eu=False): model = TrinomialLattice(S0, K, r, T, N, {"sigma": sigma, "div": div, "is_call": is_call, "is_eu": is_eu}) return model.price()
for i in range(self.M)[1:]: self.STs[i] = self.STs[i - 1] * self.d def _initialize_payoffs_tree_(self): return np.maximum(0, (self.STs - self.K) if self.is_call else (self.K - self.STs)) def __check_early_exercise__(self, payoffs, node): self.STs = self.STs[1:-1] # Shorten the ends of the list early_ex_payoffs = \ (self.STs-self.K) if self.is_call \ else(self.K-self.STs) payoffs = np.maximum(payoffs, early_ex_payoffs) return payoffs if __name__ == "__main__": from TrinomialLattice import TrinomialLattice eu_option = TrinomialLattice(50, 50, 0.05, 0.5, 2, { "sigma": 0.3, "is_call": False }) print("European put: %s" % eu_option.price()) am_option = TrinomialLattice(50, 50, 0.05, 0.5, 2, { "sigma": 0.3, "is_call": False, "is_eu": False }) print("American put: %s" % am_option.price())
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 _initialize_payoffs_tree_(self): return np.maximum( 0, (self.STs-self.K) if self.is_call else(self.K-self.STs)) def __check_early_exercise__(self, payoffs, node): self.STs = self.STs[1:-1] # Shorten the ends of the list early_ex_payoffs = \ (self.STs-self.K) if self.is_call \ else(self.K-self.STs) payoffs = np.maximum(payoffs, early_ex_payoffs) return payoffs if __name__ == "__main__": from TrinomialLattice import TrinomialLattice eu_option = TrinomialLattice( 50, 50, 0.05, 0.5, 2, {"sigma": 0.3, "is_call":False}) print ("European put: %s" % eu_option.price()) am_option = TrinomialLattice( 50, 50, 0.05, 0.5, 2, {"sigma": 0.3, "is_call": False, "is_eu": False}) print ("American put: %s" % am_option.price())