CreditQualifyingParameters21.java

  1. package org.drip.sample.simmsettings;

  2. import java.util.List;
  3. import java.util.Set;

  4. import org.drip.measure.stochastic.LabelCorrelation;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.service.env.EnvManager;
  7. import org.drip.simm.credit.CRBucket;
  8. import org.drip.simm.credit.CRQBucketCorrelation21;
  9. import org.drip.simm.credit.CRQSettingsContainer21;
  10. import org.drip.simm.credit.CRQSystemics21;

  11. /*
  12.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  13.  */

  14. /*!
  15.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  16.  *
  17.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  18.  *      libraries targeting analysts and developers
  19.  *      https://lakshmidrip.github.io/DRIP/
  20.  *  
  21.  *  DRIP is composed of four main libraries:
  22.  *  
  23.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  24.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  25.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  26.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  27.  *
  28.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  29.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  30.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  31.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  32.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  33.  *
  34.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  35.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  36.  *
  37.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  38.  *
  39.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  40.  *
  41.  *  Licensed under the Apache License, Version 2.0 (the "License");
  42.  *      you may not use this file except in compliance with the License.
  43.  *  
  44.  *  You may obtain a copy of the License at
  45.  *      http://www.apache.org/licenses/LICENSE-2.0
  46.  *  
  47.  *  Unless required by applicable law or agreed to in writing, software
  48.  *      distributed under the License is distributed on an "AS IS" BASIS,
  49.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  50.  *  
  51.  *  See the License for the specific language governing permissions and
  52.  *      limitations under the License.
  53.  */

  54. /**
  55.  * CreditQualifyingParameters21 demonstrates the Extraction and Display of ISDA SIMM 2.1 Single/Cross
  56.  *  Currency Credit Qualifying Bucket Risk Weights, Systemics, and Correlations. The References are:
  57.  *  
  58.  *  - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin,
  59.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN.
  60.  *  
  61.  *  - Albanese, C., S. Caenazzo, and O. Frankel (2017): Regression Sensitivities for Initial Margin
  62.  *      Calculations, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2763488, eSSRN.
  63.  *  
  64.  *  - Anfuso, F., D. Aziz, P. Giltinan, and K. Loukopoulus (2017): A Sound Modeling and Back-testing
  65.  *      Framework for Forecasting Initial Margin Requirements,
  66.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279, eSSRN.
  67.  *  
  68.  *  - Caspers, P., P. Giltinan, R. Lichters, and N. Nowaczyk (2017): Forecasting Initial Margin Requirements
  69.  *      - A Model Evaluation https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2911167, eSSRN.
  70.  *  
  71.  *  - International Swaps and Derivatives Association (2017): SIMM v2.0 Methodology,
  72.  *      https://www.isda.org/a/oFiDE/isda-simm-v2.pdf.
  73.  *
  74.  * @author Lakshmi Krishnamurthy
  75.  */

  76. public class CreditQualifyingParameters21
  77. {

  78.     private static final void RiskWeights()
  79.     {
  80.         Set<Integer> bucketIndexSet = CRQSettingsContainer21.BucketSet();

  81.         System.out.println
  82.             ("\t||-------------------------------------------------------------------------------------------------------------||");

  83.         System.out.println
  84.             ("\t||                               2.1 CREDIT QUALIFYING BUCKETS RISK WEIGHT                                     ||");

  85.         System.out.println
  86.             ("\t||-------------------------------------------------------------------------------------------------------------||");

  87.         System.out.println
  88.             ("\t||                                                                                                             ||");

  89.         System.out.println
  90.             ("\t||        L -> R:                                                                                              ||");

  91.         System.out.println
  92.             ("\t||                - Bucket Number                                                                              ||");

  93.         System.out.println
  94.             ("\t||                - Bucket Quality                                                                             ||");

  95.         System.out.println
  96.             ("\t||                - Bucket Risk Weight                                                                         ||");

  97.         System.out.println
  98.             ("\t||                - Bucket Sector                                                                              ||");

  99.         System.out.println
  100.             ("\t||-------------------------------------------------------------------------------------------------------------");

  101.         for (int bucketIndex : bucketIndexSet)
  102.         {
  103.             CRBucket creditQualifyingBucket = CRQSettingsContainer21.Bucket (bucketIndex);

  104.             String sectorArrayDump = "";

  105.             String[] sectorArray = creditQualifyingBucket.sectorArray();

  106.             for (String sector : sectorArray)
  107.             {
  108.                 sectorArrayDump = sectorArrayDump + sector + " ,";
  109.             }

  110.             System.out.println (
  111.                 "\t||" + FormatUtil.FormatDouble (creditQualifyingBucket.number(), 2, 0, 1.) + " | " +
  112.                 creditQualifyingBucket.quality() + " | " +
  113.                 FormatUtil.FormatDouble (creditQualifyingBucket.riskWeight(), 3, 0, 1.) + " | {" +
  114.                 sectorArrayDump + "}"
  115.             );
  116.         }

  117.         System.out.println
  118.             ("\t||-------------------------------------------------------------------------------------------------------------||");

  119.         System.out.println();
  120.     }

  121.     private static final void Systemics()
  122.     {
  123.         System.out.println ("\t||----------------------------------------------------------------||");

  124.         System.out.println ("\t||                  CREDIT QUALIFYING SYSTEMICS                   ||");

  125.         System.out.println ("\t||----------------------------------------------------------------||");

  126.         System.out.println (
  127.             "\t|| Residual Bucket Risk Weight                         => " +
  128.             FormatUtil.FormatDouble (
  129.                 CRQSystemics21.RESIDUAL_BUCKET_RISK_WEIGHT, 3, 2, 1.
  130.             ) + " ||"
  131.         );

  132.         System.out.println (
  133.             "\t|| Vega Risk Wight                                     => " +
  134.             FormatUtil.FormatDouble (
  135.                 CRQSystemics21.VEGA_RISK_WEIGHT, 3, 2, 1.
  136.             ) + " ||"
  137.         );

  138.         System.out.println (
  139.             "\t|| Base Correlation Risk Weight                        => " +
  140.             FormatUtil.FormatDouble (
  141.                 CRQSystemics21.BASE_CORRELATION_RISK_WEIGHT, 3, 2, 1.
  142.             ) + " ||"
  143.         );

  144.         System.out.println (
  145.             "\t|| Cross Base Correlation Index Correlation            => " +
  146.             FormatUtil.FormatDouble (
  147.                 CRQSystemics21.BASE_CORRELATION_CORRELATION, 3, 2, 1.
  148.             ) + " ||"
  149.         );

  150.         System.out.println (
  151.             "\t|| Non-Residual Same Issuer/Seniority Correlation      => " +
  152.             FormatUtil.FormatDouble (
  153.                 CRQBucketCorrelation21.SAME_ISSUER_SENIORITY_NON_RESIDUAL, 3, 2, 1.
  154.             ) + " ||"
  155.         );

  156.         System.out.println (
  157.             "\t|| Non-Residual Different Issuer/Seniority Correlation => " +
  158.             FormatUtil.FormatDouble (
  159.                 CRQBucketCorrelation21.DIFFERENT_ISSUER_SENIORITY_NON_RESIDUAL, 3, 2, 1.
  160.             ) + " ||"
  161.         );

  162.         System.out.println (
  163.             "\t|| Residual Same Issuer/Seniority Correlation          => " +
  164.             FormatUtil.FormatDouble (
  165.                 CRQBucketCorrelation21.SAME_ISSUER_SENIORITY_RESIDUAL, 3, 2, 1.
  166.             ) + " ||"
  167.         );

  168.         System.out.println (
  169.             "\t|| Residual Different Issuer/Seniority Correlation     => " +
  170.             FormatUtil.FormatDouble (
  171.                 CRQBucketCorrelation21.DIFFERENT_ISSUER_SENIORITY_RESIDUAL, 3, 2, 1.
  172.             ) + " ||"
  173.         );

  174.         System.out.println ("\t||----------------------------------------------------------------||");

  175.         System.out.println();
  176.     }

  177.     private static final void CrossBucketCorrelation()
  178.         throws Exception
  179.     {
  180.         LabelCorrelation crossBucketCorrelation = CRQSettingsContainer21.CrossBucketCorrelation();

  181.         List<String> bucketList = crossBucketCorrelation.labelList();

  182.         System.out.println
  183.             ("\t||------------------------------------------------------------------------------------------||");

  184.         System.out.println
  185.             ("\t||                             CROSS BUCKET TENOR CORRELATION                               ||");

  186.         System.out.println
  187.             ("\t||------------------------------------------------------------------------------------------||");

  188.         String rowDump = "\t||     ";

  189.         for (String tenor : bucketList)
  190.         {
  191.             rowDump = rowDump + "   " + tenor + "  ";
  192.         }

  193.         System.out.println (rowDump + " ||");

  194.         System.out.println
  195.             ("\t||------------------------------------------------------------------------------------------||");

  196.         for (String innerBucket : bucketList)
  197.         {
  198.             rowDump = "\t|| " + innerBucket + "  ";

  199.             for (String outerBucket : bucketList)
  200.             {
  201.                 rowDump = rowDump + " " +
  202.                     FormatUtil.FormatDouble (
  203.                         crossBucketCorrelation.entry (
  204.                             innerBucket,
  205.                             outerBucket
  206.                         ), 3, 0, 100.
  207.                     ) + "% ";
  208.             }

  209.             System.out.println (rowDump + " ||");
  210.         }

  211.         System.out.println
  212.             ("\t||------------------------------------------------------------------------------------------||");

  213.         System.out.println();
  214.     }

  215.     public static final void main (
  216.         final String[] args)
  217.         throws Exception
  218.     {
  219.         EnvManager.InitEnv ("");

  220.         RiskWeights();

  221.         Systemics();

  222.         CrossBucketCorrelation();

  223.         EnvManager.TerminateEnv();
  224.     }
  225. }