Beispiel #1
0
    def test_barrier_parity(self):
        current_price = 100.0
        interest_rate = 0.05
        vol = 0.2
        strike = 120.0
        barrier = 150.0
        maturity = 1.0

        put_up_in_price = util.black_scholes_up_in_put_price(
            current_price, interest_rate, vol, strike, barrier, maturity)
        put_up_out_price = util.black_scholes_up_out_put_price(
            current_price, interest_rate, vol, strike, barrier, maturity)
        put_price = util.black_scholes_put_price(current_price, interest_rate,
                                                 vol, strike, maturity)

        with self.test_session() as session:

            put_up_in_price_eval = session.run(put_up_in_price)
            put_up_out_price_eval = session.run(put_up_out_price)
            put_price_eval = session.run(put_price)

        self.assertGreater(put_up_in_price_eval, 0.0)
        self.assertGreater(put_up_out_price_eval, 0.0)
        self.assertAlmostEqual(put_up_in_price_eval + put_up_out_price_eval,
                               put_price_eval,
                               delta=1e-5)
Beispiel #2
0
    def test_call_put_parity(self):
        current_price = 100.0
        interest_rate = 0.05
        vol = 0.2
        strike = 120.0
        maturity = 1.0

        call_price = util.black_scholes_call_price(current_price,
                                                   interest_rate, vol, strike,
                                                   maturity)
        put_price = util.black_scholes_put_price(current_price, interest_rate,
                                                 vol, strike, maturity)
        total_price = current_price - strike * tf.exp(
            -interest_rate * maturity)

        with self.test_session() as session:

            call_price_eval = session.run(call_price)
            put_price_eval = session.run(put_price)
            total_price_eval = session.run(total_price)

        self.assertGreater(call_price_eval, 0.0)
        self.assertGreater(put_price_eval, 0.0)
        self.assertAlmostEqual(call_price_eval - put_price_eval,
                               total_price_eval,
                               delta=1e-5)