CommodityParameters21.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.commodity.CTBucket;
  8. import org.drip.simm.commodity.CTSettingsContainer21;
  9. import org.drip.simm.commodity.CTSystemics21;

  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.  * CommodityParameters21 demonstrates the Extraction and Display of ISDA SIMM 2.1 Single/Cross Currency
  55.  *  Commodity Bucket Risk Weights, Correlations, and Systemics. 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 CommodityParameters21
  76. {

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

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

  82.         System.out.println
  83.             ("\t||                                    2.1 COMMODITY BUCKETS RISK WEIGHT                                        ||");

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

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

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

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

  92.         System.out.println
  93.             ("\t||                - Bucket Risk Weight                                                                         ||");

  94.         System.out.println
  95.             ("\t||                - Bucket Member Correlation                                                                  ||");

  96.         System.out.println
  97.             ("\t||                - Bucket Entity                                                                              ||");

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

  100.         for (int bucketIndex : bucketIndexSet)
  101.         {
  102.             CTBucket commodityBucket = CTSettingsContainer21.Bucket (bucketIndex);

  103.             System.out.println (
  104.                 "\t||" + FormatUtil.FormatDouble (commodityBucket.number(), 2, 0, 1.) + " | " +
  105.                 FormatUtil.FormatDouble (commodityBucket.deltaRiskWeight(), 3, 0, 1.) + " | " +
  106.                 FormatUtil.FormatDouble (commodityBucket.memberCorrelation(), 2, 1, 100.) + "% | " +
  107.                 commodityBucket.entity()
  108.             );
  109.         }

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

  112.         System.out.println();
  113.     }

  114.     private static final void Systemics()
  115.     {
  116.         System.out.println ("\t||----------------------------------------------------------------||");

  117.         System.out.println ("\t||                      COMMODITY SYSTEMICS                       ||");

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

  119.         System.out.println (
  120.             "\t|| Historical Volatility Ratio                         => " +
  121.             FormatUtil.FormatDouble (
  122.                 CTSystemics21.HISTORICAL_VOLATILITY_RATIO, 3, 2, 1.
  123.             ) + " ||"
  124.         );

  125.         System.out.println (
  126.             "\t|| Vega Risk Weight                                    => " +
  127.             FormatUtil.FormatDouble (
  128.                 CTSystemics21.VEGA_RISK_WEIGHT, 3, 2, 1.
  129.             ) + " ||"
  130.         );

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

  132.         System.out.println();
  133.     }

  134.     private static final void CrossBucketCorrelation()
  135.         throws Exception
  136.     {
  137.         LabelCorrelation crossBucketCorrelation = CTSettingsContainer21.CrossBucketCorrelation();

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

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

  141.         System.out.println
  142.             ("\t||                                               CROSS BUCKET TENOR CORRELATION                                                ||");

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

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

  146.         for (String tenor : bucketList)
  147.         {
  148.             rowDump = rowDump + "   " + tenor + "  ";
  149.         }

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

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

  153.         for (String innerBucket : bucketList)
  154.         {
  155.             rowDump = "\t|| " + innerBucket + "  ";

  156.             for (String outerBucket : bucketList)
  157.             {
  158.                 rowDump = rowDump + " " +
  159.                     FormatUtil.FormatDouble (
  160.                         crossBucketCorrelation.entry (
  161.                             innerBucket,
  162.                             outerBucket
  163.                         ), 3, 0, 100.
  164.                     ) + "% ";
  165.             }

  166.             System.out.println (rowDump + " ||");
  167.         }

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

  170.         System.out.println();
  171.     }

  172.     public static final void main (
  173.         final String[] args)
  174.         throws Exception
  175.     {
  176.         EnvManager.InitEnv ("");

  177.         RiskWeights();

  178.         Systemics();

  179.         CrossBucketCorrelation();

  180.         EnvManager.TerminateEnv();
  181.     }
  182. }