def test_low_tau_low_vol(self): model = HestonModel(100, 0.01, 2.0, 0.01, 0.01, -0.95, 0.05) option = EuropeanCallOption(0.01, 125) result = anderson_lake(model, option, self.scheme) self.assertTrue(result > 0) self.assertAlmostEqual(result, 0.0, places=100)
def test_otm(self): model = HestonModel(11, 0.2**2, 2.0, 0.2**2, 0.3, -0.8, 0) option = EuropeanCallOption(2., 10) result = anderson_lake(model, option, self.scheme) expected = 1.7475020828 # result from finite difference method self.assertAlmostEqual(result, expected, 3)
def test_itm(self): model = HestonModel(121.17361017736597, 0.1197**2, 1.98937, \ 0.108977**2, 0.33147, -0.5, np.log(1.0005)) option = EuropeanCallOption(0.50137, 150) result = anderson_lake(model, option, self.scheme) expected = 0.008644233552 self.assertAlmostEqual(result, expected)
def test_atm(self): model = HestonModel(100, 0.1197**2, 1.98937, 0.108977**2, 0.33147, \ 0.0258519, 0) option = EuropeanCallOption(1, 100) result = anderson_lake(model, option, self.scheme) expected = 4.170956582 self.assertAlmostEqual(result, expected)
print(f"Price of option using anderson_lake_expsinh: {price}.") # ============================================================================== # === Example using the less simple function anderson_lake # Define the quadrature method the function should use to integrate. Here the # one suggested in the Anderson-Lake article is used. It is implemented in # integration.py scheme = ExpSinhQuadrature(0.5, 1e-12, 1000) # Define the model and option as in the simple case. model = HestonModel(100, 0.1197**2, 1.98937, 0.108977**2, 0.33147, 0.0258519, 0) option = EuropeanCallOption(1, 100) # Calculate the price (should return 4.171) price = anderson_lake(model, option, scheme) print(f"Price of option using anderson_lake: {price}.") # ============================================================================== # === Example using the less simple function anderson_lake # Define the quadrature method the function should use to integrate. Here the # scipy implemented GaussianQuadrature is used. It is implemented in # integration.py. This is the suggested method! scheme = GaussianQuadrature(1e-12, 1e-12, 1000) # Define the model and option as in the simple case. model = HestonModel(100, 0.1197**2, 1.98937, 0.108977**2, 0.33147, 0.0258519, 0) option = EuropeanCallOption(1, 100) # Calculate the price (should return 4.171)