BucketVegaSettings.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>BucketVegaSettings</i> holds the Settings that govern the Generation of the ISDA SIMM Single Bucket
  77.  * Vega Sensitivities. 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 BucketVegaSettings extends org.drip.simm.parameters.BucketSensitivitySettings
  117. {
  118.     private double _impliedVolatility = java.lang.Double.NaN;
  119.     private double _historicalVolatilityRatio = java.lang.Double.NaN;

  120.     /**
  121.      * Retrieve the ISDA 2.0 Equity Vega Settings
  122.      *
  123.      * @param bucketIndex The Bucket Index
  124.      *
  125.      * @return The ISDA 2.0 Equity Vega Settings
  126.      */

  127.     public static BucketVegaSettings ISDA_EQ_20 (
  128.         final int bucketIndex)
  129.     {
  130.         org.drip.simm.equity.EQBucket equityBucket =
  131.             org.drip.simm.equity.EQSettingsContainer20.BucketMap().get (bucketIndex);

  132.         if (null == equityBucket)
  133.         {
  134.             return null;
  135.         }

  136.         try
  137.         {
  138.             return new BucketVegaSettings (
  139.                 equityBucket.vegaRiskWeight() * equityBucket.deltaRiskWeight(),
  140.                 org.drip.simm.equity.EQRiskThresholdContainer20.DeltaVegaThresholdMap().get
  141.                     (bucketIndex).vega(),
  142.                 equityBucket.memberCorrelation(),
  143.                 java.lang.Math.sqrt (365. / 14.) /
  144.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  145.                 org.drip.simm.equity.EQSystemics20.HISTORICAL_VOLATILITY_RATIO
  146.             );
  147.         }
  148.         catch (java.lang.Exception e)
  149.         {
  150.             e.printStackTrace();
  151.         }

  152.         return null;
  153.     }

  154.     /**
  155.      * Retrieve the ISDA 2.1 Equity Vega Settings
  156.      *
  157.      * @param bucketIndex The Bucket Index
  158.      *
  159.      * @return The ISDA 2.1 Equity Vega Settings
  160.      */

  161.     public static BucketVegaSettings ISDA_EQ_21 (
  162.         final int bucketIndex)
  163.     {
  164.         org.drip.simm.equity.EQBucket equityBucket =
  165.             org.drip.simm.equity.EQSettingsContainer21.BucketMap().get (bucketIndex);

  166.         if (null == equityBucket)
  167.         {
  168.             return null;
  169.         }

  170.         try
  171.         {
  172.             return new BucketVegaSettings (
  173.                 equityBucket.vegaRiskWeight() * equityBucket.deltaRiskWeight(),
  174.                 org.drip.simm.equity.EQRiskThresholdContainer21.DeltaVegaThresholdMap().get
  175.                     (bucketIndex).vega(),
  176.                 equityBucket.memberCorrelation(),
  177.                 java.lang.Math.sqrt (365. / 14.) /
  178.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  179.                 org.drip.simm.equity.EQSystemics21.HISTORICAL_VOLATILITY_RATIO
  180.             );
  181.         }
  182.         catch (java.lang.Exception e)
  183.         {
  184.             e.printStackTrace();
  185.         }

  186.         return null;
  187.     }

  188.     /**
  189.      * Construct the Standard ISDA 2.0 Commodity Vega Settings for the specified Bucket
  190.      *
  191.      * @param bucketIndex The Bucket Index
  192.      *
  193.      * @return The Standard ISDA 2.0 Commodity Vega Settings for the specified Bucket
  194.      */

  195.     public static BucketVegaSettings ISDA_CT_20 (
  196.         final int bucketIndex)
  197.     {
  198.         org.drip.simm.commodity.CTBucket commodityBucket =
  199.             org.drip.simm.commodity.CTSettingsContainer20.BucketMap().get (bucketIndex);

  200.         if (null == commodityBucket)
  201.         {
  202.             return null;
  203.         }

  204.         try
  205.         {
  206.             return new org.drip.simm.parameters.BucketVegaSettings (
  207.                 org.drip.simm.commodity.CTSystemics20.VEGA_RISK_WEIGHT * commodityBucket.deltaRiskWeight(),
  208.                 org.drip.simm.commodity.CTRiskThresholdContainer20.DeltaVegaThresholdMap().get
  209.                     (bucketIndex).vega(),
  210.                 commodityBucket.memberCorrelation(),
  211.                 java.lang.Math.sqrt (365. / 14.) /
  212.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  213.                 org.drip.simm.commodity.CTSystemics20.HISTORICAL_VOLATILITY_RATIO
  214.             );
  215.         }
  216.         catch (java.lang.Exception e)
  217.         {
  218.             e.printStackTrace();
  219.         }

  220.         return null;
  221.     }

  222.     /**
  223.      * Construct the Standard ISDA 2.1 Commodity Vega Settings for the specified Bucket
  224.      *
  225.      * @param bucketIndex The Bucket Index
  226.      *
  227.      * @return The Standard ISDA 2.1 Commodity Vega Settings for the specified Bucket
  228.      */

  229.     public static BucketVegaSettings ISDA_CT_21 (
  230.         final int bucketIndex)
  231.     {
  232.         org.drip.simm.commodity.CTBucket commodityBucket =
  233.             org.drip.simm.commodity.CTSettingsContainer21.BucketMap().get (bucketIndex);

  234.         if (null == commodityBucket)
  235.         {
  236.             return null;
  237.         }

  238.         try
  239.         {
  240.             return new org.drip.simm.parameters.BucketVegaSettings (
  241.                 org.drip.simm.commodity.CTSystemics21.VEGA_RISK_WEIGHT * commodityBucket.deltaRiskWeight(),
  242.                 org.drip.simm.commodity.CTRiskThresholdContainer21.DeltaVegaThresholdMap().get
  243.                     (bucketIndex).vega(),
  244.                 commodityBucket.memberCorrelation(),
  245.                 java.lang.Math.sqrt (365. / 14.) /
  246.                     org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  247.                 org.drip.simm.commodity.CTSystemics21.HISTORICAL_VOLATILITY_RATIO
  248.             );
  249.         }
  250.         catch (java.lang.Exception e)
  251.         {
  252.             e.printStackTrace();
  253.         }

  254.         return null;
  255.     }

  256.     /**
  257.      * Construct the Standard ISDA 2.0 Bucket FX Settings
  258.      *
  259.      * @param vegaCategory The Vega Category
  260.      *
  261.      * @return The Standard ISDA 2.0 Bucket FX Settings
  262.      */

  263.     public static BucketVegaSettings ISDA_FX_20 (
  264.         final java.lang.String vegaCategory)
  265.     {
  266.         java.util.Map<java.lang.String, java.lang.Double> fxConcentrationCategoryVegaMap =
  267.             org.drip.simm.fx.FXRiskThresholdContainer20.CategoryVegaMap();

  268.         try
  269.         {
  270.             return fxConcentrationCategoryVegaMap.containsKey (vegaCategory) ?
  271.                 new org.drip.simm.parameters.BucketVegaSettings (
  272.                     org.drip.simm.fx.FXSystemics20.VEGA_RISK_WEIGHT *
  273.                         org.drip.simm.fx.FXSystemics20.DELTA_RISK_WEIGHT,
  274.                     fxConcentrationCategoryVegaMap.get (vegaCategory),
  275.                     org.drip.simm.fx.FXSystemics20.CORRELATION,
  276.                     java.lang.Math.sqrt (365. / 14.) /
  277.                         org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  278.                     org.drip.simm.fx.FXSystemics20.HISTORICAL_VOLATILITY_RATIO
  279.                 ) : null;
  280.         }
  281.         catch (java.lang.Exception e)
  282.         {
  283.             e.printStackTrace();
  284.         }

  285.         return null;
  286.     }

  287.     /**
  288.      * Construct the Standard ISDA 2.1 Bucket FX Settings
  289.      *
  290.      * @param vegaCategory The Vega Category
  291.      *
  292.      * @return The Standard ISDA 2.1 Bucket FX Settings
  293.      */

  294.     public static BucketVegaSettings ISDA_FX_21 (
  295.         final java.lang.String vegaCategory)
  296.     {
  297.         java.util.Map<java.lang.String, java.lang.Double> fxConcentrationCategoryVegaMap =
  298.             org.drip.simm.fx.FXRiskThresholdContainer21.CategoryVegaMap();

  299.         try
  300.         {
  301.             return fxConcentrationCategoryVegaMap.containsKey (vegaCategory) ?
  302.                 new org.drip.simm.parameters.BucketVegaSettings (
  303.                     org.drip.simm.fx.FXSystemics21.VEGA_RISK_WEIGHT *
  304.                         org.drip.simm.fx.FXSystemics21.DELTA_RISK_WEIGHT,
  305.                     fxConcentrationCategoryVegaMap.get (vegaCategory),
  306.                     org.drip.simm.fx.FXSystemics21.CORRELATION,
  307.                     java.lang.Math.sqrt (365. / 14.) /
  308.                         org.drip.measure.gaussian.NormalQuadrature.InverseCDF (0.99),
  309.                     org.drip.simm.fx.FXSystemics21.HISTORICAL_VOLATILITY_RATIO
  310.                 ) : null;
  311.         }
  312.         catch (java.lang.Exception e)
  313.         {
  314.             e.printStackTrace();
  315.         }

  316.         return null;
  317.     }

  318.     /**
  319.      * BucketVegaSettings Constructor
  320.      *
  321.      * @param riskWeight The Vega Risk Weight
  322.      * @param concentrationFactor The Concentration Factor
  323.      * @param memberCorrelation The Member Correlation
  324.      * @param impliedVolatility The Implied Volatility
  325.      * @param historicalVolatilityRatio The Historical Volatility Ratio
  326.      *
  327.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  328.      */

  329.     public BucketVegaSettings (
  330.         final double riskWeight,
  331.         final double concentrationFactor,
  332.         final double memberCorrelation,
  333.         final double impliedVolatility,
  334.         final double historicalVolatilityRatio)
  335.         throws java.lang.Exception
  336.     {
  337.         super (
  338.             riskWeight,
  339.             concentrationFactor,
  340.             memberCorrelation
  341.         );

  342.         if (!org.drip.numerical.common.NumberUtil.IsValid (_impliedVolatility = impliedVolatility) ||
  343.                 0. > _impliedVolatility ||
  344.             !org.drip.numerical.common.NumberUtil.IsValid (_historicalVolatilityRatio =
  345.                 historicalVolatilityRatio) || 0. > _historicalVolatilityRatio)
  346.         {
  347.             throw new java.lang.Exception ("BucketVegaSettings Constructor => Invalid Inputs");
  348.         }
  349.     }

  350.     /**
  351.      * Retrieve the Implied Volatility
  352.      *
  353.      * @return The Implied Volatility
  354.      */

  355.     public double impliedVolatility()
  356.     {
  357.         return _impliedVolatility;
  358.     }

  359.     /**
  360.      * Retrieve the Historical Volatility Ratio
  361.      *
  362.      * @return The Historical Volatility Ratio
  363.      */

  364.     public double historicalVolatilityRatio()
  365.     {
  366.         return _historicalVolatilityRatio;
  367.     }

  368.     /**
  369.      * Retrieve the Raw Vega Risk Weight
  370.      *
  371.      * @return The Raw Vega Risk Weight
  372.      */

  373.     public double rawRiskWeight()
  374.     {
  375.         return super.riskWeight();
  376.     }

  377.     @Override public double riskWeight()
  378.     {
  379.         return super.riskWeight() * _impliedVolatility;
  380.     }
  381. }