diff --git a/ReleaseNotes/08_02_2018.txt b/ReleaseNotes/08_02_2018.txt new file mode 100644 index 000000000000..0c0548eb9062 --- /dev/null +++ b/ReleaseNotes/08_02_2018.txt @@ -0,0 +1,28 @@ + +Features: + + - Risk Class Sensitivity Aggregate #1 (1, 2) + - Risk Class Sensitivity Aggregate #2 (3, 4) + - Risk Class Sensitivity Aggregate #3 (5, 6) + - Risk Class Sensitivity Aggregate #4 (7, 8) + - Risk Class Sensitivity Aggregate #5 (9, 10) + - Bucket Aggregate Bounded Weighted Sensitivity (11, 12) + - Risk Class Sensitivity Aggregate #6 (13, 14) + - Risk Class Sensitivity Aggregate #7 (15, 16) + - SIMM 2.0 Risk Factor Aggregate Margin (25) + - Equity Delta Vega Threshold Map (26, 27) + - Equity Bucket Risk Weight Correlation (28, 29) + - Equity Risk Cross Bucket Correlation (30) + - Residual Equity Bucket Settings Entry (31) + - ISDA Bucket Sensitivity Settings Map (32, 33) + - Equity Bucket Delta Risk Weight (34, 35) + + +Bug Fixes/Clean-up: + +Samples: + + - FX Delta Margin #1 (17, 18) + - FX Delta Margin #2 (19, 20) + - FX Delta Margin #3 (21, 22) + - FX Delta Margin #4 (23, 24) diff --git a/src/main/java/org/drip/sample/simm20estimates/FXDeltaMargin.java b/src/main/java/org/drip/sample/simm20estimates/FXDeltaMargin.java index ca32e3139557..ddd05f383ad8 100644 --- a/src/main/java/org/drip/sample/simm20estimates/FXDeltaMargin.java +++ b/src/main/java/org/drip/sample/simm20estimates/FXDeltaMargin.java @@ -11,6 +11,7 @@ import org.drip.simm20.margin.BucketAggregate; import org.drip.simm20.parameters.RiskClassSensitivitySettings; import org.drip.simm20.product.BucketSensitivity; +import org.drip.simm20.product.RiskClassSensitivity; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -213,6 +214,8 @@ public static final void main ( CategoryRiskFactorSensitivity (categorySensitivityMap); + Map bucketSensitivityMap = new TreeMap(); + System.out.println ("\t|--------------------||"); System.out.println ("\t| BUCKET AGGREGATE ||"); @@ -237,13 +240,18 @@ public static final void main ( BucketSensitivity bucketSensitivity = new BucketSensitivity (categorySensitivityMapEntry.getValue()); - BucketAggregate bucketDigest = bucketSensitivity.augment - (riskClassSensitivitySettings.bucketSettingsMap().get (bucketIndex)); + bucketSensitivityMap.put ( + bucketIndex, + bucketSensitivity + ); + + BucketAggregate bucketDigest = bucketSensitivity.aggregate + (riskClassSensitivitySettings.bucketSensitivitySettingsMap().get (bucketIndex)); System.out.println ("\t| " + bucketIndex + " => " + FormatUtil.FormatDouble (Math.sqrt (bucketDigest.weightedSensitivityVariance()), 4, 0, 1.) + " | " + - FormatUtil.FormatDouble (bucketDigest.cumulativeRiskFactorSensitivity(), 4, 0, 1.) + " ||" + FormatUtil.FormatDouble (bucketDigest.cumulativeRiskFactorSensitivity(), 4, 0, 1.) + " ||" ); } @@ -251,6 +259,21 @@ public static final void main ( System.out.println(); + System.out.println ("\t|----------------------------------||"); + + System.out.println ("\t| RISK CLASS DELTA MARGIN => " + + FormatUtil.FormatDouble ( + Math.sqrt ( + new RiskClassSensitivity (bucketSensitivityMap).aggregate + (riskClassSensitivitySettings).deltaSBA() + ), + 4, 0, 1.) + " ||" + ); + + System.out.println ("\t|----------------------------------||"); + + System.out.println(); + EnvManager.TerminateEnv(); } } diff --git a/src/main/java/org/drip/sample/simm20settings/EquitySettings.java b/src/main/java/org/drip/sample/simm20settings/EquitySettings.java index 5912c88a2c34..17a06b850ecb 100644 --- a/src/main/java/org/drip/sample/simm20settings/EquitySettings.java +++ b/src/main/java/org/drip/sample/simm20settings/EquitySettings.java @@ -142,7 +142,7 @@ private static final void RiskWeights() "\t||" + FormatUtil.FormatDouble (equityBucket.number(), 2, 0, 1.) + " | " + equityBucket.size() + " | " + equityBucket.region() + " | " + - FormatUtil.FormatDouble (equityBucket.riskWeight(), 3, 0, 1.) + " | " + + FormatUtil.FormatDouble (equityBucket.deltaRiskWeight(), 3, 0, 1.) + " | " + FormatUtil.FormatDouble (equityBucket.memberCorrelation(), 2, 0, 100.) + "% | " + FormatUtil.FormatDouble (equityBucket.vegaRiskWeight(), 1, 2, 1.) + " | {" + sectorArrayDump + "}" diff --git a/src/main/java/org/drip/simm20/equity/EQBucket.java b/src/main/java/org/drip/simm20/equity/EQBucket.java index 2cd4ad0f8b4e..10244a49abf7 100644 --- a/src/main/java/org/drip/simm20/equity/EQBucket.java +++ b/src/main/java/org/drip/simm20/equity/EQBucket.java @@ -75,8 +75,8 @@ public class EQBucket private java.lang.String _size = ""; private java.lang.String _region = ""; private java.lang.String[] _sectorArray = null; - private double _riskWeight = java.lang.Double.NaN; private double _vegaRiskWeight = java.lang.Double.NaN; + private double _deltaRiskWeight = java.lang.Double.NaN; private double _memberCorrelation = java.lang.Double.NaN; /** @@ -86,9 +86,9 @@ public class EQBucket * @param size Bucket Equity Market Capitalization Size * @param region Buket Region * @param sectorArray Bucket Sector Array - * @param riskWeight Bucket Risk Weight + * @param deltaRiskWeight Bucket Delta Risk Weight * @param memberCorrelation Bucket Member Correlation - * @param vegaRiskWeight The Vega Risk Weight + * @param vegaRiskWeight The Bucket Vega Risk Weight * * @throws java.lang.Exception Thrown if the Inputs are Invalid */ @@ -98,7 +98,7 @@ public EQBucket ( final java.lang.String size, final java.lang.String region, final java.lang.String[] sectorArray, - final double riskWeight, + final double deltaRiskWeight, final double memberCorrelation, final double vegaRiskWeight) throws java.lang.Exception @@ -106,7 +106,7 @@ public EQBucket ( if (null == (_size = size) || _size.isEmpty() || null == (_region = region) || _region.isEmpty() || null == (_sectorArray = sectorArray) || 0 == _sectorArray.length || - !org.drip.quant.common.NumberUtil.IsValid (_riskWeight = riskWeight) || + !org.drip.quant.common.NumberUtil.IsValid (_deltaRiskWeight = deltaRiskWeight) || !org.drip.quant.common.NumberUtil.IsValid (_memberCorrelation = memberCorrelation) || !org.drip.quant.common.NumberUtil.IsValid (_vegaRiskWeight = vegaRiskWeight)) { @@ -161,14 +161,14 @@ public java.lang.String[] sectorArray() } /** - * Retrieve the Bucket Risk Weight + * Retrieve the Bucket Delta Risk Weight * - * @return The Bucket Risk Weight + * @return The Bucket Delta Risk Weight */ - public double riskWeight() + public double deltaRiskWeight() { - return _riskWeight; + return _deltaRiskWeight; } /** diff --git a/src/main/java/org/drip/simm20/margin/BucketAggregate.java b/src/main/java/org/drip/simm20/margin/BucketAggregate.java index fef356e55175..7206645c08af 100644 --- a/src/main/java/org/drip/simm20/margin/BucketAggregate.java +++ b/src/main/java/org/drip/simm20/margin/BucketAggregate.java @@ -73,7 +73,7 @@ public class BucketAggregate { private double _weightedSensitivityVariance = java.lang.Double.NaN; private double _cumulativeRiskFactorSensitivity = java.lang.Double.NaN; - private java.util.Map + private java.util.Map _augmentedRiskFactorSensitivityMap = null; /** @@ -87,7 +87,7 @@ public class BucketAggregate */ public BucketAggregate ( - final java.util.Map + final java.util.Map augmentedRiskFactorSensitivityMap, final double weightedSensitivityVariance, final double cumulativeRiskFactorSensitivity) @@ -110,7 +110,7 @@ public BucketAggregate ( * @return The Augmented Risk Factor Sensitivity Map */ - public java.util.Map + public java.util.Map augmentedRiskFactorSensitivityMap() { return _augmentedRiskFactorSensitivityMap; @@ -137,4 +137,23 @@ public double cumulativeRiskFactorSensitivity() { return _cumulativeRiskFactorSensitivity; } + + /** + * Compute the Bounded Weighted Sensitivity + * + * @return The Bounded Weighted Sensitivity + */ + + public double boundedWeightedSensitivity() + { + double weightedSensitivity = java.lang.Math.sqrt (_weightedSensitivityVariance); + + return java.lang.Math.max ( + java.lang.Math.min ( + _cumulativeRiskFactorSensitivity, + weightedSensitivity + ), + -1. * weightedSensitivity + ); + } } diff --git a/src/main/java/org/drip/simm20/margin/AugmentedRiskFactorSensitivity.java b/src/main/java/org/drip/simm20/margin/RiskFactorAggregate.java similarity index 91% rename from src/main/java/org/drip/simm20/margin/AugmentedRiskFactorSensitivity.java rename to src/main/java/org/drip/simm20/margin/RiskFactorAggregate.java index c9540ef4dbf9..d840a05ae4a6 100644 --- a/src/main/java/org/drip/simm20/margin/AugmentedRiskFactorSensitivity.java +++ b/src/main/java/org/drip/simm20/margin/RiskFactorAggregate.java @@ -47,8 +47,8 @@ */ /** - * AugmentedRiskFactorSensitivity holds the Weighted and Normalized Bucket Risk Factor Sensitivity along with - * the Normalization Factors. The References are: + * RiskFactorAggregate holds the Weighted and Normalized Bucket Risk Factor Sensitivity along with the + * Normalization Factors. The References are: * * - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin, * https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN. @@ -69,13 +69,13 @@ * @author Lakshmi Krishnamurthy */ -public class AugmentedRiskFactorSensitivity +public class RiskFactorAggregate { private double _weightedAndNormalized = java.lang.Double.NaN; private double _concentrationRiskFactor = java.lang.Double.NaN; /** - * AugmentedRiskFactorSensitivity Constructor + * RiskFactorAggregate Constructor * * @param weightedAndNormalized The Weighted and Normalized Bucket Sensitivity * @param concentrationRiskFactor The Bucket Concentration Risk Factor @@ -83,7 +83,7 @@ public class AugmentedRiskFactorSensitivity * @throws java.lang.Exception Thrown if the Inputs are Invalid */ - public AugmentedRiskFactorSensitivity ( + public RiskFactorAggregate ( final double weightedAndNormalized, final double concentrationRiskFactor) throws java.lang.Exception @@ -91,7 +91,7 @@ public AugmentedRiskFactorSensitivity ( if (!org.drip.quant.common.NumberUtil.IsValid (_weightedAndNormalized = weightedAndNormalized) || !org.drip.quant.common.NumberUtil.IsValid (_concentrationRiskFactor = concentrationRiskFactor)) { - throw new java.lang.Exception ("AugmentedRiskFactorSensitivity Constructor => Invalid Inputs"); + throw new java.lang.Exception ("RiskFactorAggregate Constructor => Invalid Inputs"); } } diff --git a/src/main/java/org/drip/simm20/parameters/EQSensitivitySettings.java b/src/main/java/org/drip/simm20/parameters/EQSensitivitySettings.java index f42ac57fde0b..6885bcf6cbef 100644 --- a/src/main/java/org/drip/simm20/parameters/EQSensitivitySettings.java +++ b/src/main/java/org/drip/simm20/parameters/EQSensitivitySettings.java @@ -98,7 +98,7 @@ public static final EQSensitivitySettings ISDA() bucketSettingsMap.put ( -1, new org.drip.simm20.parameters.EQBucketSensitivitySettings ( - bucketMap.get (-1).riskWeight(), + bucketMap.get (-1).deltaRiskWeight(), deltaVegaRiskMap.get (-1).delta() ) ); @@ -108,7 +108,7 @@ public static final EQSensitivitySettings ISDA() bucketSettingsMap.put ( i, new org.drip.simm20.parameters.EQBucketSensitivitySettings ( - bucketMap.get (i).riskWeight(), + bucketMap.get (i).deltaRiskWeight(), deltaVegaRiskMap.get (i).delta() ) ); diff --git a/src/main/java/org/drip/simm20/parameters/FlatSensitivitySettings.java b/src/main/java/org/drip/simm20/parameters/FlatSensitivitySettings.java index 3b270436921a..2e1a09f7142a 100644 --- a/src/main/java/org/drip/simm20/parameters/FlatSensitivitySettings.java +++ b/src/main/java/org/drip/simm20/parameters/FlatSensitivitySettings.java @@ -94,7 +94,7 @@ public static final FlatSensitivitySettings EQ ( { return null == equityBucket || null == deltaVegaThreshold ? null : new FlatSensitivitySettings ( - equityBucket.riskWeight(), + equityBucket.deltaRiskWeight(), deltaVegaThreshold.delta() ); } diff --git a/src/main/java/org/drip/simm20/parameters/RiskClassSensitivitySettings.java b/src/main/java/org/drip/simm20/parameters/RiskClassSensitivitySettings.java index d4de4afafc0d..3d1880eb268c 100644 --- a/src/main/java/org/drip/simm20/parameters/RiskClassSensitivitySettings.java +++ b/src/main/java/org/drip/simm20/parameters/RiskClassSensitivitySettings.java @@ -73,7 +73,66 @@ public class RiskClassSensitivitySettings { private org.drip.measure.stochastic.LabelCorrelation _crossBucketCorrelation = null; private java.util.Map - _bucketSettingsMap = null; + _bucketSensitivitySettingsMap = null; + + /** + * Construct an ISDA EQ Standard Instance of RiskClassSensitivitySettings + * + * @return ISDA EQ Standard Instance of RiskClassSensitivitySettings + */ + + public static final RiskClassSensitivitySettings ISDA_EQ() + { + java.util.Map + bucketSensitivitySettingsMap = new java.util.HashMap(); + + java.util.Map + eqConcentrationThresholdMap = + org.drip.simm20.equity.EQRiskThresholdContainer.DeltaVegaThresholdMap(); + + java.util.Map bucketMap = + org.drip.simm20.equity.EQSettingsContainer.BucketMap(); + + org.drip.simm20.equity.EQBucket residualEquityBucket = bucketMap.get (-1); + + try + { + bucketSensitivitySettingsMap.put ( + -1, + new org.drip.simm20.parameters.BucketSensitivitySettings ( + residualEquityBucket.deltaRiskWeight(), + eqConcentrationThresholdMap.get (-1).delta(), + residualEquityBucket.memberCorrelation() + ) + ); + + for (int bucketIndex = 1; bucketIndex <= 12; ++bucketIndex) + { + org.drip.simm20.equity.EQBucket equityBucket = bucketMap.get (bucketIndex); + + bucketSensitivitySettingsMap.put ( + bucketIndex, + new org.drip.simm20.parameters.BucketSensitivitySettings ( + equityBucket.deltaRiskWeight(), + eqConcentrationThresholdMap.get (bucketIndex).delta(), + equityBucket.memberCorrelation() + ) + ); + } + + return new RiskClassSensitivitySettings ( + bucketSensitivitySettingsMap, + org.drip.simm20.equity.EQSettingsContainer.CrossBucketCorrelation() + ); + } + catch (java.lang.Exception e) + { + e.printStackTrace(); + } + + return null; + } /** * Construct an ISDA FX Standard Instance of RiskClassSensitivitySettings @@ -84,7 +143,7 @@ public class RiskClassSensitivitySettings public static final RiskClassSensitivitySettings ISDA_FX() { java.util.Map - bucketSettingsMap = new java.util.HashMap(); java.util.Map fxConcentrationCategoryDeltaMap = @@ -100,7 +159,7 @@ public static final RiskClassSensitivitySettings ISDA_FX() { categoryList.add ("" + categoryIndex); - bucketSettingsMap.put ( + bucketSensitivitySettingsMap.put ( categoryIndex, new org.drip.simm20.parameters.BucketSensitivitySettings ( org.drip.simm20.fx.FXSystemics.RISK_WEIGHT, @@ -118,7 +177,7 @@ public static final RiskClassSensitivitySettings ISDA_FX() } return new RiskClassSensitivitySettings ( - bucketSettingsMap, + bucketSensitivitySettingsMap, new org.drip.measure.stochastic.LabelCorrelation ( categoryList, crossBucketCorrelationMatrix @@ -136,7 +195,7 @@ public static final RiskClassSensitivitySettings ISDA_FX() /** * RiskClassSensitivitySettings Constructor * - * @param bucketSettingsMap The Bucket Settings Map + * @param bucketSensitivitySettingsMap The Bucket Sensitivity Settings Map * @param crossBucketCorrelation The Cross Bucket Correlation * * @throws java.lang.Exception Thrown if the Inputs are Invalid @@ -144,11 +203,12 @@ public static final RiskClassSensitivitySettings ISDA_FX() public RiskClassSensitivitySettings ( final java.util.Map - bucketSettingsMap, + bucketSensitivitySettingsMap, final org.drip.measure.stochastic.LabelCorrelation crossBucketCorrelation) throws java.lang.Exception { - if (null == (_bucketSettingsMap = bucketSettingsMap) || 0 == _bucketSettingsMap.size() || + if (null == (_bucketSensitivitySettingsMap = bucketSensitivitySettingsMap) || + 0 == _bucketSensitivitySettingsMap.size() || null == (_crossBucketCorrelation = crossBucketCorrelation)) { throw new java.lang.Exception ("RiskClassSensitivitySettings Constructor => Invalid Inputs"); @@ -173,8 +233,8 @@ public org.drip.measure.stochastic.LabelCorrelation crossBucketCorrelation() */ public java.util.Map - bucketSettingsMap() + bucketSensitivitySettingsMap() { - return _bucketSettingsMap; + return _bucketSensitivitySettingsMap; } } diff --git a/src/main/java/org/drip/simm20/product/BucketSensitivity.java b/src/main/java/org/drip/simm20/product/BucketSensitivity.java index 6312581e4410..6c4352a8be04 100644 --- a/src/main/java/org/drip/simm20/product/BucketSensitivity.java +++ b/src/main/java/org/drip/simm20/product/BucketSensitivity.java @@ -109,7 +109,7 @@ public java.util.Map riskFactorDeltaMap() * @return Map of Weighted and Adjusted Input Sensitivities */ - public org.drip.simm20.margin.BucketAggregate augment ( + public org.drip.simm20.margin.BucketAggregate aggregate ( final org.drip.simm20.parameters.BucketSensitivitySettings bucketSensitivitySettings) { if (null == bucketSensitivitySettings) @@ -126,9 +126,9 @@ public org.drip.simm20.margin.BucketAggregate augment ( double concentrationNormalizer = 1. / bucketSensitivitySettings.concentrationThreshold(); - java.util.Map + java.util.Map augmentedBucketSensitivityMap = new - org.drip.analytics.support.CaseInsensitiveHashMap(); + org.drip.analytics.support.CaseInsensitiveHashMap(); for (java.util.Map.Entry riskFactorDeltaMapEntry : _riskFactorDeltaMap.entrySet()) @@ -147,7 +147,7 @@ public org.drip.simm20.margin.BucketAggregate augment ( { augmentedBucketSensitivityMap.put ( riskFactorDeltaMapEntry.getKey(), - new org.drip.simm20.margin.AugmentedRiskFactorSensitivity ( + new org.drip.simm20.margin.RiskFactorAggregate ( riskFactorSensitivity, concentrationRiskFactor ) @@ -161,10 +161,10 @@ public org.drip.simm20.margin.BucketAggregate augment ( } } - for (java.util.Map.Entry + for (java.util.Map.Entry augmentedBucketSensitivityMapOuterEntry : augmentedBucketSensitivityMap.entrySet()) { - org.drip.simm20.margin.AugmentedRiskFactorSensitivity augmentedRiskFactorSensitivityOuter = + org.drip.simm20.margin.RiskFactorAggregate augmentedRiskFactorSensitivityOuter = augmentedBucketSensitivityMapOuterEntry.getValue(); double riskFactorSensitivityOuter = augmentedRiskFactorSensitivityOuter.weightedAndNormalized(); @@ -174,10 +174,10 @@ public org.drip.simm20.margin.BucketAggregate augment ( java.lang.String riskFactorKeyOuter = augmentedBucketSensitivityMapOuterEntry.getKey(); - for (java.util.Map.Entry + for (java.util.Map.Entry augmentedBucketSensitivityMapInnerEntry : augmentedBucketSensitivityMap.entrySet()) { - org.drip.simm20.margin.AugmentedRiskFactorSensitivity augmentedRiskFactorSensitivityInner = + org.drip.simm20.margin.RiskFactorAggregate augmentedRiskFactorSensitivityInner = augmentedBucketSensitivityMapInnerEntry.getValue(); double concentrationRiskFactorInner = diff --git a/src/main/java/org/drip/simm20/product/FXSensitivity.java b/src/main/java/org/drip/simm20/product/FXSensitivity.java deleted file mode 100644 index 79fb30bcbb6d..000000000000 --- a/src/main/java/org/drip/simm20/product/FXSensitivity.java +++ /dev/null @@ -1,141 +0,0 @@ - -package org.drip.simm20.product; - -/* - * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - */ - -/*! - * Copyright (C) 2018 Lakshmi Krishnamurthy - * - * This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model - * libraries targeting analysts and developers - * https://lakshmidrip.github.io/DRIP/ - * - * DRIP is composed of four main libraries: - * - * - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/ - * - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/ - * - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/ - * - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/ - * - * - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options, - * Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA - * Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV - * Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM - * Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics. - * - * - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy - * Incorporator, Holdings Constraint, and Transaction Costs. - * - * - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality. - * - * - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * FXSensitivity holds the ISDA SIMM 2.0 Bucket Sensitivities across FX Risk Factor Buckets. The References - * are: - * - * - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin, - * https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN. - * - * - Albanese, C., S. Caenazzo, and O. Frankel (2017): Regression Sensitivities for Initial Margin - * Calculations, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2763488, eSSRN. - * - * - Anfuso, F., D. Aziz, P. Giltinan, and K. Loukopoulus (2017): A Sound Modeling and Back-testing - * Framework for Forecasting Initial Margin Requirements, - * https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2716279, eSSRN. - * - * - Caspers, P., P. Giltinan, R. Lichters, and N. Nowaczyk (2017): Forecasting Initial Margin Requirements - * - A Model Evaluation https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2911167, eSSRN. - * - * - International Swaps and Derivatives Association (2017): SIMM v2.0 Methodology, - * https://www.isda.org/a/oFiDE/isda-simm-v2.pdf. - * - * @author Lakshmi Krishnamurthy - */ - -public class FXSensitivity -{ - private java.util.Map _bucketMap = null; - - /** - * Generate an FX Sensitivity Instance with ZERO Currency Sensitivity - * - * @param currencySet The CUrrency Set - * - * @return The FX Sensitivity Instance with ZERO Currency Sensitivity - */ - - public static final FXSensitivity Insensitive ( - final java.util.Set currencySet) - { - if (null == currencySet || 0 == currencySet.size()) - { - return null; - } - - java.util.Map bucketMap = new - org.drip.analytics.support.CaseInsensitiveHashMap(); - - try - { - for (java.lang.String currency : currencySet) - { - bucketMap.put ( - currency, - 0. - ); - } - } - catch (java.lang.Exception e) - { - e.printStackTrace(); - } - - return null; - } - - /** - * FXSensitivity COnstructor - * - * @param bucketMap The FX Sensitivity Bucket Map - * - * @throws java.lang.Exception Thrown if the Inputs are Invalid - */ - - public FXSensitivity ( - final java.util.Map bucketMap) - throws java.lang.Exception - { - if (null == (_bucketMap = bucketMap) || 0 == _bucketMap.size()) - { - throw new java.lang.Exception ("FXSensitivity Constructor => Invalid Inputs"); - } - } - - /** - * Retrieve the FX Sensitivity Bucket Map - * - * @return The FX Sensitivity Bucket Map - */ - - public java.util.Map bucketMap() - { - return _bucketMap; - } -} diff --git a/src/main/java/org/drip/simm20/product/RiskClassSensitivity.java b/src/main/java/org/drip/simm20/product/RiskClassSensitivity.java index f88e366f23a8..24e3c9f72cd3 100644 --- a/src/main/java/org/drip/simm20/product/RiskClassSensitivity.java +++ b/src/main/java/org/drip/simm20/product/RiskClassSensitivity.java @@ -103,4 +103,95 @@ public java.util.Map bucketAggregateMap = new + java.util.TreeMap(); + + java.util.Map + bucketSensitivitySettingsMap = riskClassSensitivitySettings.bucketSensitivitySettingsMap(); + + org.drip.measure.stochastic.LabelCorrelation crossBucketCorrelation = + riskClassSensitivitySettings.crossBucketCorrelation(); + + for (java.util.Map.Entry + bucketSensitivityMapEntry : _bucketSensitivityMap.entrySet()) + { + int bucketIndex = bucketSensitivityMapEntry.getKey(); + + org.drip.simm20.product.BucketSensitivity bucketSensitivity = + bucketSensitivityMapEntry.getValue(); + + org.drip.simm20.margin.BucketAggregate bucketAggregate = bucketSensitivity.aggregate + (bucketSensitivitySettingsMap.get (bucketIndex)); + + if (null == bucketAggregate) + { + return null; + } + + bucketAggregateMap.put ( + bucketIndex, + bucketAggregate + ); + } + + try + { + for (java.util.Map.Entry + bucketAggregateMapOuterEntry : bucketAggregateMap.entrySet()) + { + int outerKey = bucketAggregateMapOuterEntry.getKey(); + + org.drip.simm20.margin.BucketAggregate bucketAggregateOuter = + bucketAggregateMapOuterEntry.getValue(); + + double weightedSensitivityVarianceOuter = bucketAggregateOuter.weightedSensitivityVariance(); + + double boundedWeightedSensitivityOuter = bucketAggregateOuter.boundedWeightedSensitivity(); + + for (java.util.Map.Entry + bucketAggregateMapInnerEntry : bucketAggregateMap.entrySet()) + { + int innerKey = bucketAggregateMapInnerEntry.getKey(); + + deltaSBA = deltaSBA + ( outerKey == innerKey ? weightedSensitivityVarianceOuter : + crossBucketCorrelation.entry ( + "" + outerKey, + "" + innerKey + ) * boundedWeightedSensitivityOuter * + bucketAggregateMapInnerEntry.getValue().boundedWeightedSensitivity() + ); + } + } + + return new org.drip.simm20.margin.RiskClassAggregate ( + bucketAggregateMap, + deltaSBA + ); + } + catch (java.lang.Exception e) + { + e.printStackTrace(); + } + + return null; + } }