def test_terminal(self): """Test value of terminal for an up-and-out call.""" S = np.linspace(S0 - 10, S0 + 10, 21) V = np.maximum(S - K, 0) V[S >= L] = 0 payoff = UpAndOut(CallA(T, K), L) self.assertTrue((payoff.terminal(S) == V).all())
def test_default(self): """Test default value for American up-and-out call.""" S = np.linspace(S0 - 10, S0 + 10, 21) Vd = np.maximum(S - K, 0) Vd[S >= L] = 0 payoff = UpAndOut(CallA(T, K), L) for t in np.linspace(0, 1, N, endpoint=False): self.assertTrue((payoff.default(t, S) == Vd).all()) self.assertRaises(AssertionError, payoff.default, T, S)
def test_transcient(self): """Test value of transient for American up-and-out call.""" S = np.linspace(S0 - 10, S0 + 10, 21) V = np.linspace(S0 + 10, S0 - 10, 21) Vm = np.maximum(V, np.maximum(S - K, 0)) Vm[S >= L] = 0 payoff = UpAndOut(CallA(T, K), L) for t in np.linspace(0, 1, N, endpoint=False): self.assertTrue((payoff.transient(t, V, S) == Vm).all()) self.assertRaises(AssertionError, payoff.transient, T, V, S)