BucketCurvatureSettings.java

  1. package org.drip.simm.parameters;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  *
  10.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  11.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  12.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  13.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  14.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  15.  *      and computational support.
  16.  *  
  17.  *      https://lakshmidrip.github.io/DROP/
  18.  *  
  19.  *  DROP is composed of three modules:
  20.  *  
  21.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  22.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  23.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  24.  *
  25.  *  DROP Product Core implements libraries for the following:
  26.  *  - Fixed Income Analytics
  27.  *  - Loan Analytics
  28.  *  - Transaction Cost Analytics
  29.  *
  30.  *  DROP Portfolio Core implements libraries for the following:
  31.  *  - Asset Allocation Analytics
  32.  *  - Asset Liability Management Analytics
  33.  *  - Capital Estimation Analytics
  34.  *  - Exposure Analytics
  35.  *  - Margin Analytics
  36.  *  - XVA Analytics
  37.  *
  38.  *  DROP Computational Core implements libraries for the following:
  39.  *  - Algorithm Support
  40.  *  - Computation Support
  41.  *  - Function Analysis
  42.  *  - Model Validation
  43.  *  - Numerical Analysis
  44.  *  - Numerical Optimizer
  45.  *  - Spline Builder
  46.  *  - Statistical Learning
  47.  *
  48.  *  Documentation for DROP is Spread Over:
  49.  *
  50.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  51.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  52.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  53.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  54.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  55.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  56.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  57.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  58.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  59.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  60.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  61.  *
  62.  *  Licensed under the Apache License, Version 2.0 (the "License");
  63.  *      you may not use this file except in compliance with the License.
  64.  *  
  65.  *  You may obtain a copy of the License at
  66.  *      http://www.apache.org/licenses/LICENSE-2.0
  67.  *  
  68.  *  Unless required by applicable law or agreed to in writing, software
  69.  *      distributed under the License is distributed on an "AS IS" BASIS,
  70.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  71.  *  
  72.  *  See the License for the specific language governing permissions and
  73.  *      limitations under the License.
  74.  */

  75. /**
  76.  * <i>BucketCurvatureSettings</i> holds the ISDA SIMM Curvature Settings for Interest Rates, Qualifying and
  77.  * Non-qualifying Credit, Equity, Commodity, and Foreign Exchange. The References are:
  78.  *
  79.  * <br><br>
  80.  *  <ul>
  81.  *      <li>
  82.  *          Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial
  83.  *              Margin https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156 <b>eSSRN</b>
  84.  *      </li>
  85.  *      <li>
  86.  *          Albanese, C., S. Caenazzo, and O. Frankel (2017): Regression Sensitivities for Initial Margin
  87.  *              Calculations https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2763488 <b>eSSRN</b>
  88.  *      </li>
  89.  *      <li>
  90.  *          Anfuso, F., D. Aziz, P. Giltinan, and K. Loukopoulus (2017): A Sound Modeling and Back-testing
  91.  *              Framework for Forecasting Initial Margin Requirements
  92.  *                  https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279 <b>eSSRN</b>
  93.  *      </li>
  94.  *      <li>
  95.  *          Caspers, P., P. Giltinan, R. Lichters, and N. Nowaczyk (2017): Forecasting Initial Margin
  96.  *              Requirements - A Model Evaluation https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2911167
  97.  *                  <b>eSSRN</b>
  98.  *      </li>
  99.  *      <li>
  100.  *          International Swaps and Derivatives Association (2017): SIMM v2.0 Methodology
  101.  *              https://www.isda.org/a/oFiDE/isda-simm-v2.pdf
  102.  *      </li>
  103.  *  </ul>
  104.  *
  105.  * <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/MarginAnalyticsLibrary.md">Initial and Variation Margin Analytics</a></li>
  109.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/simm/README.md">Initial Margin Analytics based on ISDA SIMM and its Variants</a></li>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/simm/parameters/README.md">ISDA SIMM Risk Factor Parameters</a></li>
  111.  *  </ul>
  112.  * <br><br>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class BucketCurvatureSettings extends org.drip.simm.parameters.BucketVegaSettings
  117. {
  118.     private double _tenorScalingFactor = java.lang.Double.NaN;

  119.     /**
  120.      * Construct the ISDA Standard BucketCurvatureSettings
  121.      *
  122.      * @param riskWeight The Vega Risk Weight
  123.      * @param memberCorrelation The Member Correlation
  124.      * @param impliedVolatility The Implied Volatility
  125.      * @param vegaDurationDays The Bucket Vega Duration in Days
  126.      *
  127.      * @return The ISDA Standard BucketCurvatureSettings
  128.      */

  129.     public static final BucketCurvatureSettings ISDA (
  130.         final double riskWeight,
  131.         final double memberCorrelation,
  132.         final double impliedVolatility,
  133.         final int vegaDurationDays)
  134.     {
  135.         try
  136.         {
  137.             return new BucketCurvatureSettings (
  138.                 riskWeight,
  139.                 memberCorrelation,
  140.                 impliedVolatility,
  141.                 org.drip.function.r1tor1.ISDABucketCurvatureTenorScaler.Standard().evaluate
  142.                     (vegaDurationDays)
  143.             );
  144.         }
  145.         catch (java.lang.Exception e)
  146.         {
  147.             e.printStackTrace();
  148.         }

  149.         return null;
  150.     }

  151.     /**
  152.      * Construct the Standard ISDA 2.0 EQ Bucket Curvature Settings
  153.      *
  154.      * @param bucketIndex The Bucket Index
  155.      * @param vegaDurationDays The Vega Duration Days
  156.      *
  157.      * @return The Standard ISDA 2.0 EQ Bucket Curvature Settings
  158.      */

  159.     public static BucketCurvatureSettings ISDA_EQ_20 (
  160.         final int bucketIndex,
  161.         final int vegaDurationDays)
  162.     {
  163.         org.drip.simm.equity.EQBucket equityBucket =
  164.             org.drip.simm.equity.EQSettingsContainer20.BucketMap().get (bucketIndex);

  165.         try
  166.         {
  167.             return null == equityBucket ? null : BucketCurvatureSettings.ISDA (
  168.                 equityBucket.vegaRiskWeight() * equityBucket.deltaRiskWeight(),
  169.                 equityBucket.memberCorrelation(),
  170.                 java.lang.Math.sqrt (365. / 14.) /
  171.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  172.                 vegaDurationDays
  173.             );
  174.         }
  175.         catch (java.lang.Exception e)
  176.         {
  177.             e.printStackTrace();
  178.         }

  179.         return null;
  180.     }

  181.     /**
  182.      * Construct the Standard ISDA 2.1 EQ Bucket Curvature Settings
  183.      *
  184.      * @param bucketIndex The Bucket Index
  185.      * @param vegaDurationDays The Vega Duration Days
  186.      *
  187.      * @return The Standard ISDA 2.1 EQ Bucket Curvature Settings
  188.      */

  189.     public static BucketCurvatureSettings ISDA_EQ_21 (
  190.         final int bucketIndex,
  191.         final int vegaDurationDays)
  192.     {
  193.         org.drip.simm.equity.EQBucket equityBucket =
  194.             org.drip.simm.equity.EQSettingsContainer21.BucketMap().get (bucketIndex);

  195.         try
  196.         {
  197.             return null == equityBucket ? null : BucketCurvatureSettings.ISDA (
  198.                 equityBucket.vegaRiskWeight() * equityBucket.deltaRiskWeight(),
  199.                 equityBucket.memberCorrelation(),
  200.                 java.lang.Math.sqrt (365. / 14.) /
  201.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  202.                 vegaDurationDays
  203.             );
  204.         }
  205.         catch (java.lang.Exception e)
  206.         {
  207.             e.printStackTrace();
  208.         }

  209.         return null;
  210.     }

  211.     /**
  212.      * Construct the Standard ISDA 2.0 CT Bucket Curvature Settings
  213.      *
  214.      * @param bucketIndex The Bucket Index
  215.      * @param vegaDurationDays The Vega Duration Days
  216.      *
  217.      * @return The Standard ISDA 2.0 CT Bucket Curvature Settings
  218.      */

  219.     public static BucketCurvatureSettings ISDA_CT_20 (
  220.         final int bucketIndex,
  221.         final int vegaDurationDays)
  222.     {
  223.         org.drip.simm.commodity.CTBucket commodityBucket =
  224.             org.drip.simm.commodity.CTSettingsContainer20.BucketMap().get (bucketIndex);

  225.         try
  226.         {
  227.             return null == commodityBucket ? null : BucketCurvatureSettings.ISDA (
  228.                 org.drip.simm.commodity.CTSystemics20.VEGA_RISK_WEIGHT * commodityBucket.deltaRiskWeight(),
  229.                 commodityBucket.memberCorrelation(),
  230.                 java.lang.Math.sqrt (365. / 14.) /
  231.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  232.                 vegaDurationDays
  233.             );
  234.         }
  235.         catch (java.lang.Exception e)
  236.         {
  237.             e.printStackTrace();
  238.         }

  239.         return null;
  240.     }

  241.     /**
  242.      * Construct the Standard ISDA 2.1 CT Bucket Curvature Settings
  243.      *
  244.      * @param bucketIndex The Bucket Index
  245.      * @param vegaDurationDays The Vega Duration Days
  246.      *
  247.      * @return The Standard ISDA 2.1 CT Bucket Curvature Settings
  248.      */

  249.     public static BucketCurvatureSettings ISDA_CT_21 (
  250.         final int bucketIndex,
  251.         final int vegaDurationDays)
  252.     {
  253.         org.drip.simm.commodity.CTBucket commodityBucket =
  254.             org.drip.simm.commodity.CTSettingsContainer21.BucketMap().get (bucketIndex);

  255.         try
  256.         {
  257.             return null == commodityBucket ? null : BucketCurvatureSettings.ISDA (
  258.                 org.drip.simm.commodity.CTSystemics21.VEGA_RISK_WEIGHT * commodityBucket.deltaRiskWeight(),
  259.                 commodityBucket.memberCorrelation(),
  260.                 java.lang.Math.sqrt (365. / 14.) /
  261.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  262.                 vegaDurationDays
  263.             );
  264.         }
  265.         catch (java.lang.Exception e)
  266.         {
  267.             e.printStackTrace();
  268.         }

  269.         return null;
  270.     }

  271.     /**
  272.      * Construct the Standard ISDA 2.0 FX Bucket Curvature Settings
  273.      *
  274.      * @param vegaCategory The Vega Category
  275.      * @param vegaDurationDays The Vega Duration Days
  276.      *
  277.      * @return The Standard ISDA 2.0 FX Bucket Curvature Settings
  278.      */

  279.     public static BucketCurvatureSettings ISDA_FX_20 (
  280.         final java.lang.String vegaCategory,
  281.         final int vegaDurationDays)
  282.     {
  283.         java.util.Map<java.lang.String, java.lang.Double> fxConcentrationCategoryVegaMap =
  284.             org.drip.simm.fx.FXRiskThresholdContainer20.CategoryVegaMap();

  285.         try {
  286.             return !fxConcentrationCategoryVegaMap.containsKey (vegaCategory) ? null :
  287.                 BucketCurvatureSettings.ISDA (
  288.                     org.drip.simm.fx.FXSystemics20.VEGA_RISK_WEIGHT *
  289.                         org.drip.simm.fx.FXSystemics20.DELTA_RISK_WEIGHT,
  290.                     org.drip.simm.fx.FXSystemics20.CORRELATION,
  291.                     java.lang.Math.sqrt (365. / 14.) /
  292.                         org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  293.                     vegaDurationDays
  294.                 );
  295.         }
  296.         catch (java.lang.Exception e)
  297.         {
  298.             e.printStackTrace();
  299.         }

  300.         return null;
  301.     }

  302.     /**
  303.      * Construct the Standard ISDA 2.1 FX Bucket Curvature Settings
  304.      *
  305.      * @param vegaCategory The Vega Category
  306.      * @param vegaDurationDays The Vega Duration Days
  307.      *
  308.      * @return The Standard ISDA 2.1 FX Bucket Curvature Settings
  309.      */

  310.     public static BucketCurvatureSettings ISDA_FX_21 (
  311.         final java.lang.String vegaCategory,
  312.         final int vegaDurationDays)
  313.     {
  314.         java.util.Map<java.lang.String, java.lang.Double> fxConcentrationCategoryVegaMap =
  315.             org.drip.simm.fx.FXRiskThresholdContainer21.CategoryVegaMap();

  316.         try {
  317.             return !fxConcentrationCategoryVegaMap.containsKey (vegaCategory) ? null :
  318.                 BucketCurvatureSettings.ISDA (
  319.                     org.drip.simm.fx.FXSystemics21.VEGA_RISK_WEIGHT *
  320.                         org.drip.simm.fx.FXSystemics21.DELTA_RISK_WEIGHT,
  321.                     org.drip.simm.fx.FXSystemics21.CORRELATION,
  322.                     java.lang.Math.sqrt (365. / 14.) /
  323.                         org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  324.                     vegaDurationDays
  325.                 );
  326.         }
  327.         catch (java.lang.Exception e)
  328.         {
  329.             e.printStackTrace();
  330.         }

  331.         return null;
  332.     }

  333.     /**
  334.      * BucketCurvatureSettings Constructor
  335.      *
  336.      * @param riskWeight The Vega Risk Weight
  337.      * @param memberCorrelation The Member Correlation
  338.      * @param impliedVolatility The Implied Volatility
  339.      * @param tenorScalingFactor The Tenor Scaling Factor
  340.      *
  341.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  342.      */

  343.     public BucketCurvatureSettings (
  344.         final double riskWeight,
  345.         final double memberCorrelation,
  346.         final double impliedVolatility,
  347.         final double tenorScalingFactor)
  348.         throws java.lang.Exception
  349.     {
  350.         super (
  351.             riskWeight,
  352.             1.,
  353.             memberCorrelation,
  354.             impliedVolatility,
  355.             1.
  356.         );

  357.         if (!org.drip.numerical.common.NumberUtil.IsValid (_tenorScalingFactor = tenorScalingFactor))
  358.         {
  359.             throw new java.lang.Exception ("BucketCurvatureSettings Constructor => Invalid Inputs");
  360.         }
  361.     }

  362.     /**
  363.      * Retrieve the Tenor Scaling Factor
  364.      *
  365.      * @return The Tenor Scaling Factor
  366.      */

  367.     public double tenorScalingFactor()
  368.     {
  369.         return _tenorScalingFactor;
  370.     }

  371.     /**
  372.      * Retrieve the Vega Risk Weight
  373.      *
  374.      * @return The Vega Risk Weight
  375.      */

  376.     public double vegaRiskWeight()
  377.     {
  378.         return super.riskWeight();
  379.     }

  380.     @Override public double riskWeight()
  381.     {
  382.         return super.riskWeight() * _tenorScalingFactor;
  383.     }
  384. }