InterestRate20.java

  1. package org.drip.sample.simmsettings;

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

  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.rates.IRSettingsContainer20;
  8. import org.drip.simm.rates.IRSystemics20;
  9. import org.drip.simm.rates.IRWeight;

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

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

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

  75. public class InterestRate20
  76. {

  77.     private static final void RegularVolatility()
  78.         throws Exception
  79.     {
  80.         System.out.println ("\t||-----------------------------------------------------------------------------------||");

  81.         System.out.println ("\t||               2.0 REGULAR VOLATILITY CURRENCY SET and RISK WEIGHTS                ||");

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

  83.         System.out.println (
  84.             "\t|| Currency Set => " +
  85.             IRSettingsContainer20.RegularVolatilityCurrencySet() + " ||"
  86.         );

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

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

  90.         IRWeight usdRiskWeight = IRSettingsContainer20.RiskWeight ("USD");

  91.         String tenorWeightSequence = "\t|| ";

  92.         for (Map.Entry<String, Double> tenorWeightEntry : usdRiskWeight.tenorDelta().entrySet())
  93.         {
  94.             tenorWeightSequence = tenorWeightSequence + " " + tenorWeightEntry.getKey() + " => " +
  95.                 FormatUtil.FormatDouble (tenorWeightEntry.getValue(), 1, 0, 1.) + " |";
  96.         }

  97.         System.out.println (tenorWeightSequence + "|");

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

  100.         System.out.println();
  101.     }

  102.     private static final void LowVolatility()
  103.         throws Exception
  104.     {
  105.         System.out.println ("\t||-----------------------------------------------------------------------------------||");

  106.         System.out.println ("\t||                 2.0 LOW VOLATILITY CURRENCY SET and RISK WEIGHTS                  ||");

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

  108.         System.out.println (
  109.             "\t|| Currency Set => " +
  110.             IRSettingsContainer20.LowVolatilityCurrencySet()
  111.         );

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

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

  115.         IRWeight jpyRiskWeight = IRSettingsContainer20.RiskWeight ("JPY");

  116.         String tenorWeightSequence = "\t|| ";

  117.         for (Map.Entry<String, Double> tenorWeightEntry : jpyRiskWeight.tenorDelta().entrySet())
  118.         {
  119.             tenorWeightSequence = tenorWeightSequence + " " + tenorWeightEntry.getKey() + " => " +
  120.                 FormatUtil.FormatDouble (tenorWeightEntry.getValue(), 1, 0, 1.) + " |";
  121.         }

  122.         System.out.println (tenorWeightSequence + "|");

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

  125.         System.out.println();
  126.     }

  127.     private static final void HighVolatility()
  128.         throws Exception
  129.     {
  130.         System.out.println ("\t||-----------------------------------------------------------------------------------||");

  131.         System.out.println ("\t||                2.0 HIGH VOLATILITY CURRENCY SET and RISK WEIGHTS                  ||");

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

  133.         System.out.println (
  134.             "\t|| Currency Set => " +
  135.             IRSettingsContainer20.HighVolatilityCurrencySet()
  136.         );

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

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

  140.         IRWeight inrRiskWeight = IRSettingsContainer20.RiskWeight ("INR");

  141.         String tenorWeightSequence = "\t|| ";

  142.         for (Map.Entry<String, Double> tenorWeightEntry : inrRiskWeight.tenorDelta().entrySet())
  143.         {
  144.             tenorWeightSequence = tenorWeightSequence + " " + tenorWeightEntry.getKey() + " => " +
  145.                 FormatUtil.FormatDouble (tenorWeightEntry.getValue(), 1, 0, 1.) + " |";
  146.         }

  147.         System.out.println (tenorWeightSequence + "|");

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

  150.         System.out.println();
  151.     }

  152.     private static final void SingleCurrencyTenorCorrelation()
  153.         throws Exception
  154.     {
  155.         LabelCorrelation singleCurveTenorCorrelation = IRSettingsContainer20.SingleCurveTenorCorrelation();

  156.         List<String> tenorList = singleCurveTenorCorrelation.labelList();

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

  159.         System.out.println
  160.             ("\t||                          INTEREST RATE CROSS TENOR CORRELATION                           ||");

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

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

  164.         for (String tenor : tenorList)
  165.         {
  166.             rowDump = rowDump + "  " + tenor + "  ";
  167.         }

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

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

  171.         for (String innerTenor : tenorList)
  172.         {
  173.             rowDump = "\t|| " + innerTenor + " ";

  174.             for (String outerTenor : tenorList)
  175.             {
  176.                 rowDump = rowDump + " " +
  177.                     FormatUtil.FormatDouble (
  178.                         singleCurveTenorCorrelation.entry (
  179.                             innerTenor,
  180.                             outerTenor
  181.                         ),
  182.                     3, 0, 100.) + "% ";
  183.             }

  184.             System.out.println (rowDump + " ||");
  185.         }

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

  188.         System.out.println();
  189.     }

  190.     private static final void StaticParametersDump()
  191.         throws Exception
  192.     {
  193.         System.out.println ("\t||-------------------------------------------------------------------------------||");

  194.         System.out.println ("\t||                SYSTEMATIC FACTOR RISK WEIGHTS AND CORRELATIONS                ||");

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

  196.         System.out.println (
  197.             "\t|| Single Currency Inflation Risk Weight                               => " +
  198.             FormatUtil.FormatDouble (
  199.                 IRSystemics20.SINGLE_CURRENCY_CURVE_INFLATION_RISK_WEIGHT, 2, 2, 1.
  200.             ) + " ||"
  201.         );

  202.         System.out.println (
  203.             "\t|| Single Currency Basis Swap Spread Risk Weight                       => " +
  204.             FormatUtil.FormatDouble (
  205.                 IRSystemics20.SINGLE_CURRENCY_CURVE_BASIS_SWAP_SPREAD_RISK_WEIGHT, 2, 2, 1.
  206.             ) + " ||"
  207.         );

  208.         System.out.println (
  209.             "\t|| Single Currency Vega Risk Weight                                    => " +
  210.             FormatUtil.FormatDouble (
  211.                 IRSystemics20.VEGA_RISK_WEIGHT, 2, 2, 1.
  212.             ) + " ||"
  213.         );

  214.         System.out.println (
  215.             "\t|| Single Currency Cross Curve Correlation                             => " +
  216.             FormatUtil.FormatDouble (
  217.                 IRSystemics20.SINGLE_CURRENCY_CROSS_CURVE_CORRELATION, 2, 2, 1.
  218.             ) + " ||"
  219.         );

  220.         System.out.println (
  221.             "\t|| Single Currency Curve Inflation Correlation                         => " +
  222.             FormatUtil.FormatDouble (
  223.                 IRSystemics20.SINGLE_CURRENCY_CURVE_INFLATION_CORRELATION, 2, 2, 1.
  224.             ) + " ||"
  225.         );

  226.         System.out.println (
  227.             "\t|| Single Currency Curve Volatility Inflation Volatility Correlation   => " +
  228.             FormatUtil.FormatDouble (
  229.                 IRSystemics20.SINGLE_CURRENCY_CURVE_VOLATILITY_INFLATION_VOLATILITY_CORRELATION, 2, 2, 1.
  230.             ) + " ||"
  231.         );

  232.         System.out.println (
  233.             "\t|| Single Currency Curve Basis Swap Spread Correlation                 => " +
  234.             FormatUtil.FormatDouble (
  235.                 IRSystemics20.SINGLE_CURRENCY_CURVE_BASIS_SWAP_SPREAD_CORRELATION, 2, 2, 1.
  236.             ) + " ||"
  237.         );

  238.         System.out.println (
  239.             "\t|| Single Currency Basis Swap Spread Inflation Correlation             => " +
  240.             FormatUtil.FormatDouble (
  241.                 IRSystemics20.SINGLE_CURRENCY_BASIS_SWAP_SPREAD_INFLATION_CORRELATION, 2, 2, 1.
  242.             ) + " ||"
  243.         );

  244.         System.out.println (
  245.             "\t|| Cross Currency Correlation                                          => " +
  246.             FormatUtil.FormatDouble (
  247.                 IRSystemics20.CROSS_CURRENCY_CORRELATION, 2, 2, 1.
  248.             ) + " ||"
  249.         );

  250.         System.out.println ("\t||-------------------------------------------------------------------------------||");
  251.     }

  252.     public final static void main (
  253.         final String[] args)
  254.         throws Exception
  255.     {
  256.         EnvManager.InitEnv ("");

  257.         RegularVolatility();

  258.         LowVolatility();

  259.         HighVolatility();

  260.         SingleCurrencyTenorCorrelation();

  261.         StaticParametersDump();

  262.         EnvManager.TerminateEnv();
  263.     }
  264. }