def setUp(self): T = 9 B = Annuity(T, [8], 4, 100, 0.5) P = Time(PutV(T, 105), [2, 4, 5, 6]) C = Time(CallVR(T, 110), [3, 4, 6, 7]) S = Time(CallA(T, 0), [1, 2, 3, 4, 9]) self.payoff = Stack([B, P, C, S]) Ssect = [ np.linspace(0, 0.25, 10), np.linspace(0.25, -0.25, 10), np.linspace(-0.25, 0.75, 10), np.linspace(0.75, 1, 9, endpoint=False), ] Vsect = [ np.linspace(0, -0.25, 10), np.linspace(-0.25, 0.25, 10), np.linspace(0.25, 0.50, 10), np.linspace(0.50, 1, 9, endpoint=False), ] Ssect = np.array(sum((list(i) for i in Ssect), [])) Vsect = np.array(sum((list(i) for i in Vsect), [])) critical = [10, 50, 100, 105, 110, 200] S = [] V = [] for i in range(len(critical) - 1): l, u = critical[i : i + 2] lu = u - l S.extend(Ssect * lu + l) V.extend(Vsect * lu + l) self.S = np.array(S) self.V = np.array(V)
def test_terminal(self): """Test value of terminal for American call with time restrictions.""" S = np.linspace(S0 - 10, S0 + 10, 21) V = np.maximum(S - K, 0) payoff = Time(CallE(T, K), (T,)) self.assertTrue((payoff.terminal(S) == V).all()) payoff = Time(CallE(T, K), ()) self.assertTrue((payoff.terminal(S) == np.zeros(S.shape)).all())
def test_transcient(self): """Test value of transient for American call with time restrictions.""" S = np.linspace(S0 - 10, S0 + 10, 21) V = np.linspace(S0 + 10, S0 - 10, 21) times = list(np.linspace(0, 1, N // 4, endpoint=False)) + [(0.5, 1)] Vm = np.maximum(S - K, V) payoff = Time(CallA(T, K), times) for t in np.linspace(0, 1, N, endpoint=False): if float(t) in times or t > 0.5: self.assertTrue((payoff.transient(t, V, S) == Vm).all()) else: self.assertTrue((payoff.transient(t, V, S) == V).all()) self.assertRaises(AssertionError, payoff.transient, T, V, S)
def test_default(self): """Test default value of American call with time restrictions.""" S = np.linspace(S0 - 10, S0 + 10, 21) times = list(np.linspace(0, 1, N // 4, endpoint=False)) + [(0.5, 1)] Vd = np.maximum(S - K, 0) Vo = np.zeros(S.shape) payoff = Time(CallA(T, K), times) for t in np.linspace(0, 1, N, endpoint=False): if float(t) in times or t > 0.5: self.assertTrue((payoff.default(t, S) == Vd).all()) else: self.assertTrue((payoff.default(t, S) == Vo).all()) self.assertRaises(AssertionError, payoff.default, T, S)
def setUp(self): T = 9 B = Annuity(T, [8], 4, 100, 0.5) P = Time(PutV(T, 105), [2, 4, 5, 6]) C = Time(CallVR(T, 110), [3, 4, 6, 7]) S = Time(CallA(T, 0), [1, 2, 3, 4, 9]) self.payoff = Stack([B, P, C, S]) Ssect = [ np.linspace(0, 0.25, 10), np.linspace(0.25, -.25, 10), np.linspace(-.25, 0.75, 10), np.linspace(0.75, 1, 9, endpoint=False) ] Vsect = [ np.linspace(0, -.25, 10), np.linspace(-.25, 0.25, 10), np.linspace(0.25, 0.50, 10), np.linspace(0.50, 1, 9, endpoint=False) ] Ssect = np.array(sum((list(i) for i in Ssect), [])) Vsect = np.array(sum((list(i) for i in Vsect), [])) critical = [10, 50, 100, 105, 110, 200] S = [] V = [] for i in range(len(critical) - 1): l, u = critical[i:i + 2] lu = u - l S.extend(Ssect * lu + l) V.extend(Vsect * lu + l) self.S = np.array(S) self.V = np.array(V)
def test_terminal(self): """Test value of terminal for American call with time restrictions.""" S = np.linspace(S0 - 10, S0 + 10, 21) V = np.maximum(S - K, 0) payoff = Time(CallE(T, K), (T, )) self.assertTrue((payoff.terminal(S) == V).all()) payoff = Time(CallE(T, K), ()) self.assertTrue((payoff.terminal(S) == np.zeros(S.shape)).all())
dS_typical = WienerJumpProcess(r=0.05, sigma=0.2, lambd_=0.02, eta=0.3) # Partial default (default = 0%) dS_partial = WienerJumpProcess(r=0.05, sigma=0.2, lambd_=0.02, eta=0) # No default dS = WienerJumpProcess(r=0.05, sigma=0.2) # Bond # Nominal value = 100 # Semi-annual coupon = 4 # Recovery factor = 0 A = Annuity(T, np.arange(0.5, T + 0.5, 0.5), C=4, N=100, R=0) # American put option on portfolio # Strike = 105 # Time = 3 P = Time(Put(T, 105, A), times=[3]) # Reversed American call option on portfolio # Strike = 110 # Time = [2, 5] C = Time(Call(T, 110, A), times=[(2, 5)]) # Stock option (conversion option into stock for portfolio) S = Time(CallA(T, 0), times=[(0, 5)]) # Bond component of convertible bond B = Stack([A, P, C]) # Equity component of convertible bond E = S
# Variable hazard (a=-1.2), total default dS_var = WienerJumpProcess(r=0.05, sigma=0.25, lambd_=lambda S: 0.062 * (S / 50)**-0.5, eta=1) # Bond # Nominal value = 100 # Semi-annual coupon = 4 # Recovery factor = 40% A = Annuity(T, np.arange(0.5, T + 0.5, 0.5), C=4, N=100, R=0.4) # American put option on portfolio # Strike = 105 # Time = 3 P = Time(Put(T, 105, A), times=[3]) # Reversed American call option on portfolio # Strike = 110 # Time = [2, 5] C = Time(Call(T, 110, A), times=[(2, 5)]) # Stock option (conversion option into stock for portfolio) S = CallA(T, 0) # Bond component of convertible bond B = Stack([A, P, C]) # Equity component of convertible bond E = S