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 = BlackScholesModel(300 * np.exp(0.03 * 1), 0.15, 0.03)
        option = EuropeanCallOption(1, 250)

        result = bs_option_price(model, option)
        expected = 58.82

        self.assertAlmostEqual(result, expected, 2)
 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)
Exemple #6
0
def main():
    args = parser.parse_args()
    print("Welcome to Quantum Pricing Power!\n")
    val = input("Enter your option (Call /Put):").lower()
    while (val != str("call") and val != str("put")):
        val = input(
            "Oops! The option was wrong. Try again...\nEnter your option (call / put): "
        ).lower()

    print('Option selected:', val, '\n')

    spot_price = input("Enter spot price:")
    while (isinstance(spot_price, int)):
        spot_price = input(
            "Oops! The spot price was wrong. Try again...\nEnter spot price: ")

    volatility = input("Enter volatility:")
    while (isinstance(volatility, float)):
        volatility = input(
            "Oops! The volatility was wrong. Try again...\nEnter volatility: ")

    int_rate = input("Enter interest rate:")
    while (isinstance(int_rate, float)):
        int_rate = input(
            "Oops! The interest rate was wrong. Try again...\nEnter interest rate: "
        )

    days = input("Enter days to maturity:")
    while (isinstance(days, int)):
        days = input(
            "Oops! Days to maturity was wrong. Try again...\nEnter days to maturity: "
        )

    strike_price = input("Enter strike price:")
    while (isinstance(strike_price, float)):
        strike_price = input(
            "Oops! The strike price was wrong. Try again...\nEnter strike price: "
        )

    print('Initialize algorithm...\n')
    european_option = EuropeanCallOption(val, spot_price, volatility, int_rate,
                                         days, strike_price)
    print('Plotting probability distribution... \n')
    european_option.plot_probability_distribution()
    print('Plotting payoff function... \n')
    european_option.plot_payoff_function()

    european_option.print_exact_values()
    print('Evaluating expected payoff... \n')
    european_option.evaluate_expected_payoff()
    print('Plotting estimated data values... \n')
    european_option.plot_estimated_data_values()
    print('Evaluating delta values... \n')
    european_option.evaluate_delta()
    print('Plotting delta values... \n')
    european_option.plot_estimated_delta_values()
Exemple #7
0
def main():
    print("Welcome to Quantum Pricing Power!\n")
    x = re.compile('\d+(\.\d+)?')
    val = input("Enter your option (Call /Put):").lower()
    while (val != str("call") and val != str("put")):
        val = input(
            "Oops! The option type was wrong. Try again...\nEnter your option (call / put): "
        ).lower()

    print('Option selected:', val, '\n')

    spot_price = input('Enter the spot price:')
    while x.match(spot_price) == None:
        print('Oops! The spot price must be a positive number! Try again...')
        spot_price = input()

    volatility = input("Enter the implied volatility:")
    while x.match(volatility) == None:
        volatility = input(
            "Oops! The volatility was wrong. Try again...\nEnter volatility: ")

    int_rate = input("Enter interest rate:")
    while x.match(int_rate) == None:
        int_rate = input(
            "Oops! The interest rate was wrong. Try again...\nEnter interest rate: "
        )

    days = input("Enter days to maturity:")
    while x.match(days) == None:
        days = input(
            "Oops! Days to maturity was wrong. Try again...\nEnter days to maturity: "
        )

    strike_price = input("Enter strike price:")
    while x.match(strike_price) == None:
        strike_price = input(
            "Oops! The strike price was wrong. Try again...\nEnter strike price: "
        )

    print('Initialize algorithm...\n')
    european_option = EuropeanCallOption(val, spot_price, volatility, int_rate,
                                         days, strike_price)
    print('Plotting probability distribution... \n')
    european_option.plot_probability_distribution()
    print('Plotting payoff function... \n')
    european_option.plot_payoff_function()

    european_option.print_exact_values()
    print('Evaluating expected payoff... \n')
    european_option.evaluate_expected_payoff()
    print('Plotting estimated data values... \n')
    european_option.plot_estimated_data_values()
    print('Evaluating delta values... \n')
    european_option.evaluate_delta()
    print('Plotting delta values... \n')
    european_option.plot_estimated_delta_values()
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
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)