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)
# -*- coding: utf-8 -*- # import local modules from pricers import anderson_lake, anderson_lake_expsinh from integration import ExpSinhQuadrature, GaussianQuadrature from models import HestonModel from options import EuropeanCallOption # ============================================================================== # === Example using the simpler function anderson_lake_expsinh # Define the model # The parameters are in order: # forward, initial volatility, kappa, theta, sigma, rho, interest rate model = HestonModel(100, 0.1197**2, 1.98937, 0.108977**2, 0.33147, 0.0258519, 0) # Define the call option # The arguments are in order: # time to maturity, strike option = EuropeanCallOption(1, 100) # Calculate the price (should return 4.171) price = anderson_lake_expsinh(model, option) 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