Exemplo n.º 1
0
 def test_toDataFrameBig(self):
     Input = CRIF.CrifUtil.read_csv(r'..\Testdatensatz1_CRIF.csv')
     crifs = Crifs(Input)
     crif = crifs.get(next(iter(crifs)))
     imTree = StandardCalculation.calculate(crif)
     df = imTree.toDataFrame()
     imTree.printToCsv(r'..\ExampleTreeAsCsv.csv')
 def test_performance_SA(self):
     Input = CRIF.CrifUtil.read_csv(r'../NochKleineresTestportfolio.csv')
     tic = time.time()
     crif = Crif(Input)
     imTree = StandardCalculation.calculate(crif)
     imTree = StandaloneAllocation.calculate(imTree)
     toc = time.time()
     self.assertTrue((toc-tic) < 0.8)
Exemplo n.º 3
0
 def test_toDataFrameWithBothAllocations(self):
     Input = CRIF.CrifUtil.read_csv(r'..\NochKleineresTestportfolio.csv')
     crif = Crif(Input)
     imTree = StandardCalculation.calculate(crif)
     imTree = StandaloneAllocation.calculate(imTree)
     imTree = EulerAllocation.calculate(imTree)
     df = imTree.toDataFrame()
     asdf = 1
Exemplo n.º 4
0
    def test_toDataFrameOneLine(self):
        OneLineCrif = '''ValuationDate,IMLedis,tradeId,IMModel,productClass,riskType,qualifier,bucket,label1,label2,amount,amountCurrency,amountUSD,EndDate,CollectRegulations,PostRegulations
,IMLedis_NRW_Bank,DZ14788807,SIMM,RatesFX,Risk_IRCurve,EUR,1,10y,Libor3m,1000000,EUR,1000000,,EMIR,'''
        Input = CRIF.CrifUtil.read_csv(StringIO(OneLineCrif))
        crif = Crif(Input)
        imTree = StandardCalculation.calculate(crif)
        df = imTree.toDataFrame()
        asdf = 1
Exemplo n.º 5
0
def allocate_im(crif):
    if crif is None:
        raise PreventUpdate
    crif = Crif(pd.read_json(crif))
    imTree = StandardCalculation.calculate(crif)
    imTree = EulerAllocation.calculate(imTree)
    imTree = StandaloneAllocation.calculate(imTree)
    imTree = imTree.toDataFrame()
    return imTree.to_json()
 def test_performance_JPM_komplett(self):
     Input = CRIF.CrifUtil.read_csv(r'../NochKleineresTestportfolio.csv')
     tic = time.time()
     crif = Crif(Input)
     imTree = StandardCalculation.calculate(crif)
     imTree = EulerAllocation.calculate(imTree)
     toc = time.time()
     print(toc - tic)
     asfd = 1
     self.assertTrue((toc - tic) < 20)
 def test_both_allocations(self):
     Input = CRIF.CrifUtil.read_csv(r'../NochKleineresTestportfolio.csv')
     tic = time.time()
     crif = Crif(Input)
     imTree = StandardCalculation.calculate(crif)
     imTree = EulerAllocation.calculate(imTree)
     imTree = StandaloneAllocation.calculate(imTree)
     toc = time.time()
     print(toc - tic)
     asfd = 1
     self.assertTrue((toc - tic) < 40)
Exemplo n.º 8
0
    def testJsonCreatorStandardCalculation(self):
        OneLineCrif = '''ValuationDate,IMLedis,tradeId,IMModel,productClass,riskType,qualifier,bucket,label1,label2,amount,amountCurrency,amountUSD,EndDate,CollectRegulations,PostRegulations
,IMLedis_NRW_Bank,DZ14788807,SIMM,RatesFX,Risk_IRCurve,EUR,1,10y,Libor3m,1000000,EUR,1000000,,EMIR,'''
        Input = CRIF.CrifUtil.read_csv(StringIO(OneLineCrif))
        crif = Crif(Input)
        imTree = StandardCalculation.calculate(crif)
        testJson = imTree.to_json(with_data=True)
        self.assertEqual(
            testJson,
            r'''{"Total 51000000": {"children": [{"SIMM-P 51000000": {"children": [{"RatesFX 51000000": {"children": [{"Interest Rate 51000000": {"children": [{"Delta 51000000": {"children": [{"EUR 51000000": {"data": {"rowNumber": 5, "Level": 6, "levelName": "Bucket", "ExposureAmount": 51000000.0, "manifestation": "EUR", "identifier": "SIMM-P_RatesFX_Interest Rate_Delta_EUR"}}}], "data": {"rowNumber": 4, "Level": 5, "levelName": "Sensitivity Type", "ExposureAmount": 51000000.0, "manifestation": "Delta", "identifier": "SIMM-P_RatesFX_Interest Rate_Delta"}}}], "data": {"rowNumber": 3, "Level": 4, "levelName": "Risk Class", "ExposureAmount": 51000000.0, "manifestation": "Interest Rate", "identifier": "SIMM-P_RatesFX_Interest Rate"}}}], "data": {"rowNumber": 2, "Level": 3, "levelName": "Silo", "ExposureAmount": 51000000.0, "manifestation": "RatesFX", "identifier": "SIMM-P_RatesFX"}}}], "data": {"rowNumber": 1, "Level": 2, "levelName": "ImModel", "ExposureAmount": 51000000.0, "manifestation": "SIMM-P", "identifier": "SIMM-P"}}}], "data": {"rowNumber": 0, "Level": 1, "levelName": "Total", "ExposureAmount": 51000000.0, "manifestation": "Total", "identifier": ""}}}'''
        )
Exemplo n.º 9
0
 def test_calculate_initial_margin(self):
     # To streamline it is only possible to create an IM Tree from which the Overall Initial Margin may be extracted
     # afterwards.
     # The structure of the IM Tree has been adopted from the open source acadiasoft engine.
     csvLocation = 'test/NochKleineresTestportfolio.csv'
     crif = Crif(CRIF.CrifUtil.read_csv(csvLocation, sep=','))
     # call StandardCalculation.calculate(crif) to calculate the Initial Margin and create an IM Tree
     imTree = StandardCalculation.calculate(crif)
     imTree = EulerAllocation.calculate(imTree)
     imTree = StandaloneAllocation.calculate(imTree)
     # The resulting IM Tree can be displayed relatively conveniently with print
     print(imTree)
     # Alternatively it may be transformed into a DataFrame to simplify analysis of the result in Python
     imTree_asDataFrame = imTree.toDataFrame()
     print(imTree_asDataFrame.head(10))
     print(imTree_asDataFrame.columns)
     # If you want to analyse further outside of python you can save the imTree as a .csv File
     imTree.printToCsv('./ExampleTreeAsCsv.csv')
     # Finally, you can extract the overall Initial Margin as follows:
     im = imTree.getMargin()
     print('The initial Margin of ' + str(crif) + ' is ' +
           '{:,.2f}'.format(im) + ' USD.')
     # By default the calculationCurrency and the currency in which the margin is returned is USD
     asdf = 1
Exemplo n.º 10
0
def calculate_IM(crif):
    if crif is None:
        raise PreventUpdate
    crif = Crif(pd.read_json(crif))
    imTree = StandardCalculation.calculate(crif)
    return imTree.toDataFrame().to_json()
Exemplo n.º 11
0
 def test_ScheduleOnly(self):
     df = CRIF.CrifUtil.read_csv('../ScheduleTestSet.csv')
     crif = Crifs(df)['Contract_1_collect_EMIR']
     imTree = StandardCalculation.calculate(crif)
     self.assertEqual(round(imTree.get_node(0).data.ExposureAmount,0), 50400)
 def testNettingsAsExpectedPv(self):
     crifs = Crifs(CRIF.CrifUtil.read_csv('..\ScheduleTestSet.csv'))
     crif = crifs['NettingsAsExpectedPv_collect_EMIR']
     imTree = StandardCalculation.calculate(crif)
     self.assertEqual(10, imTree.getMargin())
 def testNettingAndAbsoluteNotional(self):
     crifs = Crifs(CRIF.CrifUtil.read_csv('..\ScheduleTestSet.csv'))
     crif = crifs['NettingAndAbsoluteNotional_collect_EMIR']
     imTree = StandardCalculation.calculate(crif)
     self.assertAlmostEquals(8, imTree.getMargin(), places=5)
Exemplo n.º 14
0
 def test_toDataFrameMultiLine(self):
     Input = CRIF.CrifUtil.read_csv(r'..\NochKleineresTestportfolio.csv')
     crif = Crif(Input)
     imTree = StandardCalculation.calculate(crif)
     df = imTree.toDataFrame()