Exemplo n.º 1
0
 def test_american_option_put(self):
     """Tests that LSM price of American put option is computed as expected."""
     # This is the same example as in Section 1 of
     # Longstaff, F.A. and Schwartz, E.S., 2001. Valuing American options by
     # simulation: a simple least-squares approach. The review of financial
     # studies, 14(1), pp.113-147.
     basis_fn = lsm.make_polynomial_basis(2)
     for dtype in (np.float32, np.float64):
         payoff_fn = payoff.make_basket_put_payoff([1.1], dtype=dtype)
         # Option price
         american_put_price = lsm.least_square_mc(
             self.samples, [1, 2, 3],
             payoff_fn,
             basis_fn,
             discount_factors=self.discount_factors,
             dtype=dtype)
         self.assertAllClose(american_put_price, [0.1144],
                             rtol=1e-4,
                             atol=1e-4)
Exemplo n.º 2
0
 def test_american_basket_option_put(self):
     """Tests the LSM price of American Basket put option."""
     # This is the same example as in Section 1 of
     # Longstaff, F.A. and Schwartz, E.S., 2001. Valuing American options by
     # simulation: a simple least-squares approach. The review of financial
     # studies, 14(1), pp.113-147.
     # This is the minimum number of basis functions for the tests to pass.
     basis_fn = lsm.make_polynomial_basis(10)
     exercise_times = [1, 2, 3]
     dtype = np.float64
     payoff_fn = payoff.make_basket_put_payoff([1.1, 1.2, 1.3], dtype=dtype)
     # Create a 2-d process which is simply follows the `samples` paths:
     samples = tf.convert_to_tensor(self.samples, dtype=dtype)
     samples_2d = tf.concat([samples, samples], -1)
     # Price American basket option
     american_basket_put_price = lsm.least_square_mc(
         samples_2d,
         exercise_times,
         payoff_fn,
         basis_fn,
         discount_factors=self.discount_factors,
         dtype=dtype)
     # Since the marginal processes of `samples_2d` are 100% correlated, the
     # price should be the same as of the American option computed for
     # `samples`
     american_put_price = lsm.least_square_mc(
         self.samples,
         exercise_times,
         payoff_fn,
         basis_fn,
         discount_factors=self.discount_factors,
         dtype=dtype)
     self.assertAllClose(american_basket_put_price,
                         american_put_price,
                         rtol=1e-4,
                         atol=1e-4)
     self.assertAllEqual(american_basket_put_price.shape, [3])