CTCrossBucketPrincipal.java

  1. package org.drip.sample.simmvariance;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.numerical.common.NumberUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.simm.commodity.CTSettingsContainer20;
  6. import org.drip.simm.commodity.CTSettingsContainer21;
  7. import org.drip.simm.foundation.RiskGroupPrincipalCovariance;

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

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

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

  73. public class CTCrossBucketPrincipal
  74. {

  75.     private static final void PrintBucketPrincipalCovariance (
  76.         final String simmVersion,
  77.         final String displayLabel,
  78.         final RiskGroupPrincipalCovariance riskGroupPrincipalCovariance)
  79.         throws Exception
  80.     {
  81.         System.out.println ("\t||------------------------------------||");

  82.         System.out.println ("\t||    " + simmVersion + " CROSS BUCKET COVARIANCE     ||");

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

  84.         System.out.println (
  85.             "\t|| Cross Group Correlation => " +
  86.             FormatUtil.FormatDouble (riskGroupPrincipalCovariance.extraGroupCorrelation(), 1, 4, 1.) + " ||"
  87.         );

  88.         System.out.println (
  89.             "\t|| Principal Eigenvalue    => " +
  90.             FormatUtil.FormatDouble (
  91.                 riskGroupPrincipalCovariance.principalEigenComponent().eigenValue(), 1, 4, 1.
  92.             ) + " ||"
  93.         );

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

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

  97.         System.out.println
  98.             ("\t||                                                          ADJUSTED CURVE PRINCIPAL COVARIANCE                                                          |");

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

  101.         NumberUtil.PrintMatrix (
  102.             "\t|| " + displayLabel,
  103.             riskGroupPrincipalCovariance.adjustedCovariance()
  104.         );

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

  107.         System.out.println();
  108.     }

  109.     public static final void main (
  110.         final String[] argumentArray)
  111.         throws Exception
  112.     {
  113.         EnvManager.InitEnv ("");

  114.         PrintBucketPrincipalCovariance (
  115.             "2.0",
  116.             "CT CROSS BUCKET",
  117.             CTSettingsContainer20.CrossBucketPrincipalCovariance()
  118.         );

  119.         PrintBucketPrincipalCovariance (
  120.             "2.1",
  121.             "CT CROSS BUCKET",
  122.             CTSettingsContainer21.CrossBucketPrincipalCovariance()
  123.         );

  124.         EnvManager.TerminateEnv();
  125.     }
  126. }