Exemplo n.º 1
0
def test_EURIBOR6M_initiation(initialize_test):
    tts = ql.Period(2, ql.Days)
    tte = ql.Period(10, ql.Years)

    swap = IRS(100, tts, tte, SwapDirection.PAYER, InterestRateIndex.EURIBOR6M)
    swap.get_price()
    swap.get_fixed_rate()
    swap.get_delta()
Exemplo n.º 2
0
def test_get_bumped_copy():
    bumpsize = 0.01
    option = IRS(notional = 100000,
                 timeToSwapStart=ql.Period(1, ql.Years),
                 timeToSwapEnd=ql.Period(5, ql.Years),
                 swapDirection=SwapDirection.PAYER,
                 index=InterestRateIndex.EURIBOR6M,
                 fixed_rate=0.01)
    option_copy = option.get_bumped_copy(bumpsize)
    assert option_copy.notional == option.notional * (1 + bumpsize)
    assert approx(option_copy.get_price(), abs=0.000001) == option.get_price() * (1 + bumpsize)
    asdf = 1
    for option_sensi, option_copy_sensi in zip(option.get_simm_sensis(), option_copy.get_simm_sensis()):
        assert approx(float(option_sensi['amountUSD']) * (1 + bumpsize), abs=0.000001) == float(
            option_copy_sensi['amountUSD'])
Exemplo n.º 3
0
def test_syncing_and_desyncing():
    ca = CollateralAgreement(margining=Margining.MARGINED,
                             initialMargining=InitialMargining.SIMM)
    ca.link_sa_ccr_instance(SA_CCR(ca))

    trade1 = EquityOption(maturity=ql.Period(1, ql.Years),
                          strike=EquitySpot.ADS.value.value() - 5)
    trade2 = IRS(notional=100,
                 timeToSwapStart=ql.Period(2, ql.Days),
                 timeToSwapEnd=ql.Period(1, ql.Years),
                 swapDirection=SwapDirection.RECEIVER,
                 index=InterestRateIndex.EURIBOR6M,
                 fixed_rate=0.00)
    trade3 = IRS(notional=100,
                 timeToSwapStart=ql.Period(2, ql.Days),
                 timeToSwapEnd=ql.Period(1, ql.Years),
                 swapDirection=SwapDirection.RECEIVER,
                 index=InterestRateIndex.USDLIBOR3M,
                 fixed_rate=0.01)

    ca.add_trades(trade1)
    ca.sync_im_model = False
    assert ca.vm_model.trades == [trade1]
    assert ca.im_model.trades == [trade1]
    ca.add_trades(trade2)
    assert ca.vm_model.trades == [trade1, trade2]
    assert ca.im_model.trades == [trade1]
    ca.sync_im_model = True
    assert ca.im_model.trades == [trade1, trade2]
    ca.add_trades(trade3)
    assert ca.vm_model.trades == [trade1, trade2, trade3]
    assert ca.im_model.trades == [trade1, trade2, trade3]

    # now check if the calculations also add up at least for VM

    ca = CollateralAgreement(margining=Margining.MARGINED,
                             initialMargining=InitialMargining.NO_IM)
    ca.link_sa_ccr_instance(SA_CCR(ca))

    npv_1 = fxConvert(trade1.currency, Currency.USD, trade1.get_price())
    npv_2 = fxConvert(trade2.currency, Currency.USD, trade2.get_price())
    npv_3 = fxConvert(trade3.currency, Currency.USD, trade3.get_price())

    ca.add_trades(trade1)
    ca.sync_vm_model = False
    assert ca.get_C() == ca.get_vm_model().get_vm() == npv_1 != 0
    ca.add_trades(trade2)
    assert ca.get_C() == npv_1
    ca.sync_vm_model = True
    assert ca.get_C() == npv_1 + npv_2
    ca.add_trades(trade3)
    assert ca.get_C() == npv_1 + npv_2 + npv_3

    # a few sanity checks for SA_CCR

    ca = CollateralAgreement(margining=Margining.MARGINED,
                             initialMargining=InitialMargining.SIMM)
    local_sa_ccr_model = SA_CCR(ca)
    ca.link_sa_ccr_instance(local_sa_ccr_model)

    assert local_sa_ccr_model.get_ead() == 0
    ca.add_trades(trade1)
    ca.sync_im_model = False
    ca.sync_vm_model = False
    test_value = local_sa_ccr_model.get_ead()
    assert test_value > 0
    assert local_sa_ccr_model.trades == [trade1]
    ca.add_trades(trade2)
    test_value_2 = local_sa_ccr_model.get_ead()
    assert ca.vm_model.trades == [trade1]
    assert ca.im_model.trades == [trade1]
    ca.sync_vm_model = True
    ca.sync_im_model = True
    ca.sync_sa_ccr_model = True
    test_value_3 = local_sa_ccr_model.get_ead()
    assert test_value_2 != test_value_3
    assert local_sa_ccr_model.trades == [trade1, trade2]
    assert ca.vm_model.trades == [trade1, trade2]
    assert ca.im_model.trades == [trade1, trade2]
    ca.add_trades(trade3)
    test_value_4 = local_sa_ccr_model.get_ead()
    assert test_value_4 != test_value_3
    assert local_sa_ccr_model.trades == [trade1, trade2, trade3]
    assert ca.vm_model.trades == [trade1, trade2, trade3]
    assert ca.im_model.trades == [trade1, trade2, trade3]