Ejemplo n.º 1
0
    def test_put_option(self):
        spot = 100
        strike = 110
        risk_free = 0.05
        expiry = 1
        vol = 0.2

        stock = ConstantVolatilityStock(spot, vol)
        option = EuropeanStockOption([stock], risk_free, expiry, False, strike)

        solver = AnalyticEuropeanStockOptionSolver()

        put_value = black_scholes(spot, strike, risk_free, 0, vol, expiry, 'put')
        self.assertAlmostEqual(put_value, 10.6753248248)

        self.assertAlmostEqual(solver.solve_option_price(option),
                               10.6753248248)
Ejemplo n.º 2
0
    def test_option_pricing(self):
        spot = 100
        strike = 110
        risk_free = 0.05
        expiry = 1
        vol = 0.2

        stock = ConstantVolatilityStock(spot, vol)
        # is_call = True
        option = EuropeanStockOption([stock], risk_free, expiry, True, strike)

        solver = AnalyticEuropeanStockOptionSolver()

        call_value = black_scholes(spot, strike, risk_free, 0, vol, expiry, 'call')
        self.assertAlmostEqual(call_value, 6.04008812972)

        self.assertAlmostEqual(solver.solve_option_price(option),
                               6.04008812972)
Ejemplo n.º 3
0
    def test_put_option(self):
        spot = 100
        strike = 110
        risk_free = 0.05
        expiry = 1
        vol = 0.2

        stock = ConstantVolatilityStock(spot, vol)
        option = EuropeanStockOption([stock], risk_free, expiry, False, strike)

        interval = 0.1
        expected = 10.6753248248
        lower_bound = expected - interval
        upper_bound = expected + interval
        solver = NaiveMCOptionSolver(interval)
        n_runs = 20

        in_bound_count = sum(
            1 for _ in xrange(n_runs)
            if lower_bound <= solver.solve_option_price(option) <= upper_bound
        )

        self.assertGreaterEqual(in_bound_count, 0.95*n_runs)
Ejemplo n.º 4
0
    def test_call_option(self):
        spot = 100
        strike = 110
        risk_free = 0.05
        expiry = 1
        vol = 0.2

        stock = ConstantVolatilityStock(spot, vol)
        option = EuropeanStockOption([stock], risk_free, expiry, True, strike)

        interval = 0.1
        expected = 6.04008812972
        lower_bound = expected - interval
        upper_bound = expected + interval
        solver = SimpleLayeredMCOptionSolver(interval)
        n_runs = 20

        in_bound_count = sum(
            1 for _ in xrange(n_runs)
            if lower_bound <= solver.solve_option_price(option) <= upper_bound
        )

        self.assertGreaterEqual(in_bound_count, 0.95*n_runs)
Ejemplo n.º 5
0
 def test_valuation_for_put(self):
     stock = ConstantVolatilityStock(10, 1)
     sut = EuropeanStockOption([stock], 0.05, 1, False, 10)
     self.assertEqual(sut.determine_payoff(6), 4)
     self.assertEqual(sut.determine_payoff(15), 0)