Exemplo n.º 1
0
 def get_vm(self):
     vm = 0
     for t in self.trades:
         vm += fxConvert(fromCcy=t.currency,
                         toCcy=self.vm_currency,
                         amount=t.get_price())
     return vm
Exemplo n.º 2
0
    def get_simm_sensis_equityvol(self):
        sensis = []
        volHandle = EquityVolatility[self.underlying.name].value
        volQuotes = EquityVolatilityQuotes[self.underlying.name].value
        p0 = self.get_price()

        simmBase2 = self.simmBaseDict.copy()
        simmBase2[CrifColumn.Qualifier.value] = EquityStaticData[
            self.underlying.name].value[CrifColumn.Qualifier]
        simmBase2[CrifColumn.Bucket.value] = EquityStaticData[
            self.underlying.name].value[CrifColumn.Bucket]
        simmBase2[CrifColumn.RiskType.value] = RiskType.Risk_EquityVol.value
        for optionMaturity in volQuotes.optionMaturities:
            sensiDict = simmBase2.copy()
            volHandle.linkTo(
                volQuotes.get_atm_shifted_surface_abs_one_pct(optionMaturity))
            amount = self.get_price() - p0
            sensiDict[CrifColumn.Label1.value] = periodToLabel1(optionMaturity)
            sensiDict[CrifColumn.Amount.value] = '%.10f' % amount
            sensiDict[CrifColumn.AmountUSD.value] = '%.10f' % fxConvert(
                self.currency, Currency.USD, amount)
            sensis.append(sensiDict)

        volHandle.linkTo(volQuotes.ql_BlackVarianceSurface)
        return sensis
Exemplo n.º 3
0
 def get_V(self):
     if self.sync_sa_ccr_model == False:
         raise (Exception(
             'Dangerous to call get_V if SA_CCR and CA are not synced.'))
     v = 0
     for t in self.trades:
         v += fxConvert(fromCcy=t.currency,
                        toCcy=self.margin_currency,
                        amount=t.get_price())
     return v
Exemplo n.º 4
0
    def get_simm_sensis_fx(self) -> List[Dict]:
        sensiList = []
        sensiDict = self.simmBaseDict.copy()
        sensiDict[CrifColumn.RiskType.value] = RiskType.Risk_FX.value
        sensiDict[CrifColumn.Qualifier.value] = self.currency.value

        # these are all single currency interest rate trades. Their fx sensi according to ISDA SIMM is 1 per cent of their NPV.
        amount = self.get_price() * 0.01
        sensiDict[CrifColumn.Amount.value] = '%.10f' % amount
        sensiDict[CrifColumn.AmountUSD.value] = '%.10f' % fxConvert(
            self.currency, Currency.USD, amount)
        sensiList.append(sensiDict)

        return sensiList
Exemplo n.º 5
0
 def get_simm_sensis_ircurve(self, curve: Union[LiborCurve, OisCurve]):
     sensiList = []
     quotes = InterestRateCurveQuotes[curve.name].value
     for period, quote in quotes.items():
         sensiDict = self.simmBaseDict.copy()
         amount = utilities.sensiCalc.dv01_abs_one_bp([quote], self)
         sensiDict[CrifColumn.Amount.value] = '%.10f' % amount
         sensiDict[CrifColumn.RiskType.value] = RiskType.Risk_IRCurve.value
         sensiDict[CrifColumn.Qualifier.value] = self.currency.name
         sensiDict[CrifColumn.Label1.value] = periodToLabel1(period)
         sensiDict[CrifColumn.Label2.value] = indexToLabel2[curve.name]
         sensiDict[CrifColumn.AmountUSD.value] = '%.10f' % fxConvert(
             self.currency, Currency.USD, amount)
         sensiList.append(sensiDict)
     return sensiList
 def get_simm_sensis_equity(self) -> List[Dict]:
     sensiList = []
     sensiDict = self.simmBaseDict.copy()
     sensiDict[CrifColumn.RiskType.value] = RiskType.Risk_Equity.value
     sensiDict[CrifColumn.Qualifier.value] = EquityStaticData[
         self.underlying.name].value[CrifColumn.Qualifier]
     sensiDict[CrifColumn.Bucket.value] = EquityStaticData[
         self.underlying.name].value[CrifColumn.Bucket]
     quote = EquitySpotQuote[self.underlying.name].value
     amount = dv01_rel_one_percent([quote], self)
     sensiDict[CrifColumn.Amount.value] = '%.10f' % amount
     sensiDict[CrifColumn.AmountUSD.value] = '%.10f' % fxConvert(
         self.currency, Currency.USD, amount)
     sensiList.append(sensiDict)
     return sensiList
Exemplo n.º 7
0
    def get_simm_sensis_irvol(self):
        sensiList = []
        indexname = self.underlying_swap.index.name
        currency = IRSConventions[indexname].value['Currency']
        swvolquotes = SwaptionVolatilityQuotes[currency.name].value

        for optionTenor in swvolquotes.optionTenors:
            volQuotes = swvolquotes[optionTenor]
            amount = 0
            for volQuote in volQuotes:
                amount += volQuote.value() * fd_simple_quotes([volQuote], self)
            sensiDict = self.simmBaseDict.copy()
            sensiDict[CrifColumn.Amount.value] = '%.10f' % amount
            sensiDict[CrifColumn.RiskType.value] = RiskType.Risk_IRVol.value
            sensiDict[CrifColumn.Qualifier.value] = self.currency.name
            sensiDict[CrifColumn.Label1.value] = periodToLabel1(optionTenor)
            sensiDict[CrifColumn.AmountUSD.value] = '%.10f' % fxConvert(
                self.currency, Currency.USD, amount)
            sensiList.append(sensiDict)

        return sensiList
Exemplo n.º 8
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]
Exemplo n.º 9
0
def test_oneWay():
    fxspot = FxSpot.EURUSD.value
    eur = 10
    usd = fxspot*eur
    assert usd == fxConvert(Currency.EUR, Currency.USD, eur)