Exemple #1
0
    def test_european_vanilla_option_usage(self):

        european_exercise = EuropeanExercise(self.maturity)
        european_option = VanillaOption(self.payoff, european_exercise)

        analytic_european_engine = AnalyticEuropeanEngine(
            self.black_scholes_merton_process)

        european_option.set_pricing_engine(analytic_european_engine)

        self.assertAlmostEquals(3.844308, european_option.net_present_value, 6)
Exemple #2
0
    def test_bucket_analysis_option(self):

        settings = Settings()

        calendar = TARGET()

        todays_date = Date(15, May, 1998)
        settlement_date = Date(17, May, 1998)

        settings.evaluation_date = todays_date

        option_type = Put
        underlying = 40
        strike = 40
        dividend_yield = 0.00
        risk_free_rate = 0.001
        volatility = 0.20
        maturity = Date(17, May, 1999)
        daycounter = Actual365Fixed()

        underlyingH = SimpleQuote(underlying)

        payoff = PlainVanillaPayoff(option_type, strike)

        flat_term_structure = FlatForward(reference_date=settlement_date,
                                          forward=risk_free_rate,
                                          daycounter=daycounter)
        flat_dividend_ts = FlatForward(reference_date=settlement_date,
                                       forward=dividend_yield,
                                       daycounter=daycounter)

        flat_vol_ts = BlackConstantVol(settlement_date, calendar, volatility,
                                       daycounter)

        black_scholes_merton_process = BlackScholesMertonProcess(
            underlyingH, flat_dividend_ts, flat_term_structure, flat_vol_ts)

        european_exercise = EuropeanExercise(maturity)
        european_option = VanillaOption(payoff, european_exercise)
        analytic_european_engine = AnalyticEuropeanEngine(
            black_scholes_merton_process)

        european_option.set_pricing_engine(analytic_european_engine)

        ba_eo = bucket_analysis([[underlyingH]], [european_option], [1], 0.50,
                                1)

        self.assertTrue(2, ba_eo)
        self.assertTrue(type(tuple), ba_eo)
        self.assertEqual(1, len(ba_eo[0][0]))
        self.assertAlmostEqual(-0.4582666150152517, ba_eo[0][0][0])
    def test_bucket_analysis_option(self):

        settings = Settings()

        calendar = TARGET()

        todays_date = Date(15, May, 1998)
        settlement_date = Date(17, May, 1998)

        settings.evaluation_date = todays_date

        option_type = Put
        underlying = 40
        strike = 40
        dividend_yield = 0.00
        risk_free_rate = 0.001
        volatility = SimpleQuote(0.20)
        maturity = Date(17, May, 1999)
        daycounter = Actual365Fixed()

        underlyingH = SimpleQuote(underlying)

        payoff = PlainVanillaPayoff(option_type, strike)

        flat_term_structure = FlatForward(reference_date=settlement_date,
                                          forward=risk_free_rate,
                                          daycounter=daycounter)
        flat_dividend_ts = FlatForward(reference_date=settlement_date,
                                       forward=dividend_yield,
                                       daycounter=daycounter)

        flat_vol_ts = BlackConstantVol(settlement_date, calendar, volatility,
                                       daycounter)

        black_scholes_merton_process = BlackScholesMertonProcess(
            underlyingH, flat_dividend_ts, flat_term_structure, flat_vol_ts)

        european_exercise = EuropeanExercise(maturity)
        european_option = VanillaOption(payoff, european_exercise)
        analytic_european_engine = AnalyticEuropeanEngine(
            black_scholes_merton_process)

        european_option.set_pricing_engine(analytic_european_engine)

        delta, gamma = bucket_analysis([underlyingH, volatility],
                                       [european_option],
                                       shift=1e-4,
                                       type=Centered)
        self.assertAlmostEqual(delta[0], european_option.delta)
        self.assertAlmostEqual(delta[1], european_option.vega)
        self.assertAlmostEqual(gamma[0], european_option.gamma, 5)
Exemple #4
0
    def test_implied_volatility(self):

        european_exercise = EuropeanExercise(self.maturity)
        european_option = VanillaOption(self.payoff, european_exercise)

        vol = SimpleQuote(.18)
        proc = ImpliedVolatilityHelper.clone(self.black_scholes_merton_process,
                                             vol)
        analytic_european_engine = AnalyticEuropeanEngine(proc)

        implied_volatility = ImpliedVolatilityHelper.calculate(
            european_option, analytic_european_engine, vol, 3.844308, .001,
            500, .1, .5)

        self.assertAlmostEqual(.20, implied_volatility, 4)