diff --git a/ReleaseNotes/02_12_2018.txt b/ReleaseNotes/02_12_2018.txt new file mode 100644 index 000000000000..b313e2322179 --- /dev/null +++ b/ReleaseNotes/02_12_2018.txt @@ -0,0 +1,50 @@ + +Features: + + - Smoothing vs Shape Preserving Investigations (7, 8) + - Convert Default Builds to SMOOTH (9, 10) + - Natve Forward IE EI #1 (15, 16) + - Natve Forward IE EI #2 (17, 18) + - Latent State Tradeable - Shell Implementation (22) + - Latent State Tradeable - Repo Rate (23) + - Latent State Tradeable - Cash Rate (24) + - Tradeable Latent State Evolver Contructor (26, 27, 28) + - Latent State Evolver Tradeable Instance (29, 30) + - Tradeable Security Repoable Indicator Flag (31) + - Primary Security Container Position #1 (33, 34) + - Primary Security Container Position #2 (35, 36) + - XVA Equity Primary Security Evolver (43) + - Scaling Numeraire XVA Evolver Shell (44) + - Scaling Numeraire XVA Diffusive Evolver (45) + - Scaling Numeraire XVA Evolver Constructor (46, 47) + - XVA Evolver Primary Security Numeraire (48) + - XVA Evolver Primary Security Label (49, 50) + + +Bug Fixes/Clean-up: + + - Switch Funding Default -> Financial Spline (11, 12) + - Tradeable Latent State Evolver Rename (25) + - Tradeable to Primary Security Conversion (32) + - XVA Securities and State Evolvers (37) + - Primary Security Latent State Evolvers (38, 39) + - XVA Latent State Evolution Container (40) + - Terminal XVA Latent State Evolver (41, 42) + - Vertex Date Builder Analytics Support (44) + + +Samples: + + - Aizawl Bond Metrics #1 (1, 2) + - Aizawl Bond Metrics #2 (3, 4) + - Aizawl Bond Metrics #3 (5, 6) + - QUARTIC/QUINTIC Funding Spline Curves (13, 14) + - Aizawl Bond Metrics #4 (19, 20, 21) + - Correlated Numeraire XVA Attribution (51, 52) + - Correlated Numeraire XVA Greeks (53, 54) + - Correlated Numeraire XVA Explain (55, 56) + - Correlated Numeraire XVA Replication Portfolio (57, 58) + - Burgard 2011 XVA Explain (59, 60) + - Burgard 2011 XVA Greeks (61, 62) + - Burgard 2011 XVA Market Generation (63, 64) + - Burgard 2011 XVA Replication Portfolio (65, 66) diff --git a/src/main/java/org/drip/xva/universe/VertexDateBuilder.java b/src/main/java/org/drip/analytics/support/VertexDateBuilder.java similarity index 99% rename from src/main/java/org/drip/xva/universe/VertexDateBuilder.java rename to src/main/java/org/drip/analytics/support/VertexDateBuilder.java index 2a6afbe68509..d7c14ed53271 100644 --- a/src/main/java/org/drip/xva/universe/VertexDateBuilder.java +++ b/src/main/java/org/drip/analytics/support/VertexDateBuilder.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.analytics.support; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- diff --git a/src/main/java/org/drip/sample/bondmetrics/Aizawl.java b/src/main/java/org/drip/sample/bondmetrics/Aizawl.java new file mode 100644 index 000000000000..45cf21ae5186 --- /dev/null +++ b/src/main/java/org/drip/sample/bondmetrics/Aizawl.java @@ -0,0 +1,247 @@ + +package org.drip.sample.bondmetrics; + +import org.drip.analytics.date.*; +import org.drip.product.creator.BondBuilder; +import org.drip.product.credit.BondComponent; +import org.drip.service.env.EnvManager; +import org.drip.service.scenario.*; + +/* + * -*- 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. + */ + +/** + * Aizawl demonstrates the Analytics Calculation/Reconciliation for the Bond Aizawl. + * + * @author Lakshmi Krishnamurthy + */ + +public class Aizawl { + + public static final void main ( + final String[] astArgs) + throws Exception + { + EnvManager.InitEnv ( + "", + true + ); + + JulianDate dtSpot = DateUtil.CreateFromYMD ( + 2018, + DateUtil.JANUARY, + 30 + ); + + String[] astrDepositTenor = new String[] { + "2D" + }; + + double[] adblDepositQuote = new double[] { + 0.0130411 // 2D + }; + + double[] adblFuturesQuote = new double[] { + 0.01345, // 98.655 + 0.01470, // 98.530 + 0.01575, // 98.425 + 0.01660, // 98.340 + 0.01745, // 98.255 + 0.01845 // 98.155 + }; + + String[] astrFixFloatTenor = new String[] { + "02Y", + "03Y", + "04Y", + "05Y", + "06Y", + "07Y", + "08Y", + "09Y", + "10Y", + "11Y", + "12Y", + "15Y", + "20Y", + "25Y", + "30Y", + "40Y", + "50Y" + }; + + String[] astrGovvieTenor = new String[] { + "1Y", + "2Y", + "3Y", + "5Y", + "7Y", + "10Y", + "20Y", + "30Y" + }; + + double[] adblFixFloatQuote = new double[] { + 0.016410, // 2Y + 0.017863, // 3Y + 0.019030, // 4Y + 0.020035, // 5Y + 0.020902, // 6Y + 0.021660, // 7Y + 0.022307, // 8Y + 0.022879, // 9Y + 0.023363, // 10Y + 0.023820, // 11Y + 0.024172, // 12Y + 0.024934, // 15Y + 0.025581, // 20Y + 0.025906, // 25Y + 0.025973, // 30Y + 0.025838, // 40Y + 0.025560 // 50Y + }; + + double[] adblGovvieYield = new double[] { + 0.01219, // 1Y + 0.01391, // 2Y + 0.01590, // 3Y + 0.01937, // 5Y + 0.02200, // 7Y + 0.02378, // 10Y + 0.02677, // 20Y + 0.02927 // 30Y + }; + + String[] astrCreditTenor = new String[] { + "06M", + "01Y", + "02Y", + "03Y", + "04Y", + "05Y", + "07Y", + "10Y" + }; + + double[] adblCreditQuote = new double[] { + 60., // 6M + 68., // 1Y + 88., // 2Y + 102., // 3Y + 121., // 4Y + 138., // 5Y + 168., // 7Y + 188. // 10Y + }; + + double dblFX = 1.; + int iSettleLag = 3; + int iCouponFreq = 2; + String strName = "Aizawl"; + double dblCleanPrice = 1.028625; + double dblIssuePrice = 1.; + String strCurrency = "USD"; + double dblSpreadBump = 20.; + double dblCouponRate = 0.05; + double dblIssueAmount = 1.0; + String strTreasuryCode = "UST"; + String strCouponDayCount = "30/360"; + double dblSpreadDurationMultiplier = 5.; + + JulianDate dtEffective = DateUtil.CreateFromYMD ( + 2017, + 9, + 21 + ); + + JulianDate dtMaturity = DateUtil.CreateFromYMD ( + 2037, + 3, + 21 + ); + + BondComponent bond = BondBuilder.CreateSimpleFixed ( + strName, + strCurrency, + strName, + dblCouponRate, + iCouponFreq, + strCouponDayCount, + dtEffective, + dtMaturity, + null, + null + ); + + BondReplicator abr = BondReplicator.CorporateSenior ( + dblCleanPrice, + dblIssuePrice, + dblIssueAmount, + dtSpot, + astrDepositTenor, + adblDepositQuote, + adblFuturesQuote, + astrFixFloatTenor, + adblFixFloatQuote, + dblSpreadBump, + dblSpreadDurationMultiplier, + strTreasuryCode, + astrGovvieTenor, + adblGovvieYield, + astrCreditTenor, + adblCreditQuote, + dblFX, + Double.NaN, + iSettleLag, + bond + ); + + BondReplicationRun abrr = abr.generateRun(); + + System.out.println (abrr.display()); + + EnvManager.TerminateEnv(); + } +} diff --git a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAAttribution.java b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAAttribution.java index 8f63ed884568..f6b144ae407e 100644 --- a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAAttribution.java +++ b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAAttribution.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -215,7 +222,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -282,7 +292,8 @@ public static final void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -292,7 +303,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -302,7 +314,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -312,7 +325,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -326,7 +340,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -340,7 +355,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -399,7 +415,7 @@ public static final void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAExplain.java b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAExplain.java index 4fe493cfd797..dc80be479176 100644 --- a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAExplain.java +++ b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAExplain.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -105,7 +112,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblTime = dblTimeStart + dblTimeWidth; - TradeablesContainer tc = tes.tradeablesContainer(); + PrimarySecurityContainer tc = tes.tradeablesContainer(); double dblCollateralSchemeNumeraire = mvStart.csaReplicator(); @@ -216,7 +223,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -283,7 +293,8 @@ public static final void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -293,7 +304,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -303,7 +315,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -313,7 +326,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -327,7 +341,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -341,7 +356,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -400,7 +416,7 @@ public static final void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAGreeks.java b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAGreeks.java index 9a03baae5bf5..4c311cd3563d 100644 --- a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAGreeks.java +++ b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAGreeks.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -105,7 +112,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblTime = dblTimeStart + dblTimeWidth; - TradeablesContainer tcm = tes.tradeablesContainer(); + PrimarySecurityContainer tcm = tes.tradeablesContainer(); double dblCollateralSchemeNumeraire = mvStart.csaReplicator(); @@ -214,7 +221,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -281,7 +291,8 @@ public static final void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -291,7 +302,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -301,7 +313,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -311,7 +324,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -325,7 +339,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -339,7 +354,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -398,7 +414,7 @@ public static final void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAReplicationPortfolio.java b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAReplicationPortfolio.java index 00cdfaf51709..0e6bd7ea6b12 100644 --- a/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAReplicationPortfolio.java +++ b/src/main/java/org/drip/sample/burgard2011/CorrelatedNumeraireXVAReplicationPortfolio.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -106,7 +113,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblTime = dblTimeStart + dblTimeWidth; - TradeablesContainer tc = tes.tradeablesContainer(); + PrimarySecurityContainer tc = tes.tradeablesContainer(); BurgardKjaerEdgeRun bker = bko.edgeRun ( new MarketEdge ( @@ -214,7 +221,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -281,7 +291,8 @@ public static final void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -291,7 +302,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -301,7 +313,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -311,7 +324,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -325,7 +339,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -339,7 +354,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -398,7 +414,7 @@ public static final void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/XVAExplain.java b/src/main/java/org/drip/sample/burgard2011/XVAExplain.java index b2a6fc63cbb8..fdcc88d55938 100644 --- a/src/main/java/org/drip/sample/burgard2011/XVAExplain.java +++ b/src/main/java/org/drip/sample/burgard2011/XVAExplain.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -104,7 +111,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblTime = dblTimeStart + dblTimeWidth; - TradeablesContainer tc = tes.tradeablesContainer(); + PrimarySecurityContainer tc = tes.tradeablesContainer(); double dblCollateralSchemeNumeraire = mvStart.csaReplicator(); @@ -216,7 +223,10 @@ public static void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -283,7 +293,8 @@ public static void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -293,7 +304,8 @@ public static void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -303,7 +315,8 @@ public static void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -313,7 +326,8 @@ public static void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -327,7 +341,8 @@ public static void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -341,7 +356,8 @@ public static void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -400,7 +416,7 @@ public static void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/XVAGreeks.java b/src/main/java/org/drip/sample/burgard2011/XVAGreeks.java index aeb9c318693c..282126264fc8 100644 --- a/src/main/java/org/drip/sample/burgard2011/XVAGreeks.java +++ b/src/main/java/org/drip/sample/burgard2011/XVAGreeks.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -104,7 +111,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblTime = dblTimeStart + dblTimeWidth; - TradeablesContainer tc = tes.tradeablesContainer(); + PrimarySecurityContainer tc = tes.tradeablesContainer(); double dblCollateralSchemeNumeraire = mvStart.csaReplicator(); @@ -205,7 +212,10 @@ public static void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -272,7 +282,8 @@ public static void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -282,7 +293,8 @@ public static void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -292,7 +304,8 @@ public static void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -302,7 +315,8 @@ public static void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -316,7 +330,8 @@ public static void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -330,7 +345,8 @@ public static void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -389,7 +405,7 @@ public static void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/XVAMarketGeneration.java b/src/main/java/org/drip/sample/burgard2011/XVAMarketGeneration.java index ea320b43a24e..7727baf222b7 100644 --- a/src/main/java/org/drip/sample/burgard2011/XVAMarketGeneration.java +++ b/src/main/java/org/drip/sample/burgard2011/XVAMarketGeneration.java @@ -2,12 +2,19 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.universe.*; /* @@ -86,7 +93,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -149,7 +159,8 @@ public static final void main ( double dblCounterPartyRecoveryRateVolatility = 0.0; double dblCounterPartyRecoveryRateInitial = 0.30; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -159,7 +170,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -169,7 +181,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -179,7 +192,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -193,7 +207,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -207,7 +222,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -269,7 +285,7 @@ public static final void main ( MarketVertexGenerator mvg = new MarketVertexGenerator ( iSpotDate, aiVertexDate, - new TradeablesContainer ( + new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2011/XVAReplicationPortfolio.java b/src/main/java/org/drip/sample/burgard2011/XVAReplicationPortfolio.java index 9461d8ee45ed..f41999a2baf7 100644 --- a/src/main/java/org/drip/sample/burgard2011/XVAReplicationPortfolio.java +++ b/src/main/java/org/drip/sample/burgard2011/XVAReplicationPortfolio.java @@ -2,6 +2,7 @@ package org.drip.sample.burgard2011; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; @@ -9,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -106,7 +113,7 @@ private static final EvolutionTrajectoryVertex RunStep ( double dblCollateralSchemeNumeraire = mvStart.csaReplicator(); - TradeablesContainer tc = tes.tradeablesContainer(); + PrimarySecurityContainer tc = tes.tradeablesContainer(); BurgardKjaerEdgeRun bker = bko.edgeRun ( new MarketEdge ( @@ -215,7 +222,10 @@ public static void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -282,7 +292,8 @@ public static void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -292,7 +303,8 @@ public static void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -302,7 +314,8 @@ public static void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -312,7 +325,8 @@ public static void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -326,7 +340,8 @@ public static void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -340,7 +355,8 @@ public static void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -399,7 +415,7 @@ public static void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/burgard2012/EulerTrajectoryEvolutionScheme.java b/src/main/java/org/drip/sample/burgard2012/EulerTrajectoryEvolutionScheme.java index 705f90b1c020..8e6ae410fd9c 100644 --- a/src/main/java/org/drip/sample/burgard2012/EulerTrajectoryEvolutionScheme.java +++ b/src/main/java/org/drip/sample/burgard2012/EulerTrajectoryEvolutionScheme.java @@ -2,14 +2,21 @@ package org.drip.sample.burgard2012; import org.drip.analytics.date.*; +import org.drip.analytics.support.VertexDateBuilder; import org.drip.measure.discrete.SequenceGenerator; import org.drip.measure.dynamics.*; import org.drip.measure.process.*; import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.definition.*; import org.drip.xva.derivative.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.pde.*; import org.drip.xva.universe.*; @@ -90,7 +97,10 @@ public static final void main ( { EnvManager.InitEnv (""); + String bank = "WFC"; int iNumVertex = 24; + String currency = "USD"; + String counterParty = "BAC"; int iSimulationDuration = 365; double[][] aadblCorrelationMatrix = new double[][] { @@ -157,7 +167,8 @@ public static final void main ( double dblSensitivityShiftFactor = 0.001; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift - dblAssetNumeraireDividend, @@ -167,7 +178,8 @@ public static final void main ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -177,7 +189,8 @@ public static final void main ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -187,7 +200,8 @@ public static final void main ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -201,7 +215,8 @@ public static final void main ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -215,7 +230,8 @@ public static final void main ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -274,7 +290,7 @@ public static final void main ( iNumVertex ); - TradeablesContainer tc = new TradeablesContainer ( + PrimarySecurityContainer tc = new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/sample/funding/ShapePreservingZeroSmooth.java b/src/main/java/org/drip/sample/funding/ShapePreservingZeroSmooth.java new file mode 100644 index 000000000000..efe07cf160b4 --- /dev/null +++ b/src/main/java/org/drip/sample/funding/ShapePreservingZeroSmooth.java @@ -0,0 +1,662 @@ + +package org.drip.sample.funding; + +import org.drip.analytics.date.*; +import org.drip.analytics.definition.LatentStateStatic; +import org.drip.function.r1tor1.QuadraticRationalShapeControl; +import org.drip.market.otc.*; +import org.drip.param.creator.*; +import org.drip.param.valuation.*; +import org.drip.product.creator.*; +import org.drip.product.definition.CalibratableComponent; +import org.drip.product.rates.*; +import org.drip.quant.common.FormatUtil; +import org.drip.service.env.EnvManager; +import org.drip.spline.basis.*; +import org.drip.spline.params.*; +import org.drip.spline.pchip.LocalMonotoneCkGenerator; +import org.drip.spline.stretch.*; +import org.drip.state.creator.ScenarioDiscountCurveBuilder; +import org.drip.state.discount.*; +import org.drip.state.estimator.*; +import org.drip.state.identifier.*; +import org.drip.state.inference.*; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2018 Lakshmi Krishnamurthy + * Copyright (C) 2017 Lakshmi Krishnamurthy + * Copyright (C) 2016 Lakshmi Krishnamurthy + * Copyright (C) 2015 Lakshmi Krishnamurthy + * Copyright (C) 2014 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. + */ + +/** + * ShapePreservingZeroSmooth demonstrates the usage of different shape preserving and smoothing techniques + * involved in the funding curve creation. It shows the following: + * - Construct the Array of Cash/Swap Instruments and their Quotes from the given set of parameters. + * - Construct the Cash/Swap Instrument Set Stretch Builder. + * - Set up the Linear Curve Calibrator using the following parameters: + * - Cubic Exponential Mixture Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Set up the Global Curve Control parameters as follows: + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Set up the Local Curve Control parameters as follows: + * - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array of + * Cash and Swap Stretches. + * - Construct the Globally Smoothened Discount Curve by applying the linear curve calibrator and the Global + * Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving discount + * curve. + * - Construct the Locally Smoothened Discount Curve by applying the linear curve calibrator and the Local + * Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving discount + * curve. + * - Cross-Comparison of the Cash/Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies. + * - Cross-Comparison of the Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies for a sequence of bespoke swap instruments. + * + * @author Lakshmi Krishnamurthy + */ + +public class ShapePreservingZeroSmooth { + + private static final FixFloatComponent OTCIRS ( + final JulianDate dtSpot, + final String strCurrency, + final String strMaturityTenor, + final double dblCoupon) + { + FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction ( + strCurrency, + "ALL", + strMaturityTenor, + "MAIN" + ); + + return ffConv.createFixFloatComponent ( + dtSpot, + strMaturityTenor, + dblCoupon, + 0., + 1. + ); + } + + /* + * Construct the Array of Deposit Instruments from the given set of parameters + * + * USE WITH CARE: This sample ignores errors and does not handle exceptions. + */ + + private static final SingleStreamComponent[] DepositInstrumentsFromMaturityDays ( + final JulianDate dtEffective, + final String strCurrency, + final int[] aiDay) + throws Exception + { + SingleStreamComponent[] aDeposit = new SingleStreamComponent[aiDay.length]; + + for (int i = 0; i < aiDay.length; ++i) + aDeposit[i] = SingleStreamComponentBuilder.Deposit ( + dtEffective, + dtEffective.addBusDays ( + aiDay[i], + strCurrency + ), + ForwardLabel.Create ( + "USD", + "3M" + ) + ); + + return aDeposit; + } + + /* + * Construct the Array of Swap Instruments from the given set of parameters + * + * USE WITH CARE: This sample ignores errors and does not handle exceptions. + */ + + private static final FixFloatComponent[] SwapInstrumentsFromMaturityTenor ( + final JulianDate dtSpot, + final String strCurrency, + final String[] astrMaturityTenor) + throws Exception + { + FixFloatComponent[] aIRS = new FixFloatComponent[astrMaturityTenor.length]; + + for (int i = 0; i < astrMaturityTenor.length; ++i) { + FixFloatComponent irs = OTCIRS ( + dtSpot, + strCurrency, + astrMaturityTenor[i], + 0. + ); + + irs.setPrimaryCode ("IRS." + astrMaturityTenor[i] + "." + strCurrency); + + aIRS[i] = irs; + } + + return aIRS; + } + + /* + * This sample demonstrates the usage of different shape preserving and smoothing techniques involved in + * the discount curve creation. It shows the following: + * - Construct the Array of Cash/Swap Instruments and their Quotes from the given set of parameters. + * - Construct the Cash/Swap Instrument Set Stretch Builder. + * - Set up the Linear Curve Calibrator using the following parameters: + * - Cubic Exponential Mixture Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Set up the Global Curve Control parameters as follows: + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Set up the Local Curve Control parameters as follows: + * - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + * - Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array + * of Cash and Swap Stretches. + * - Construct the Globally Smoothened Discount Curve by applying the linear curve calibrator and the + * Global Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving + * discount curve. + * - Construct the Locally Smoothened Discount Curve by applying the linear curve calibrator and the + * Local Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving + * discount curve. + * - Cross-Comparison of the Cash/Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies. + * - Cross-Comparison of the Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies for a sequence of bespoke swap instruments. + * + * USE WITH CARE: This sample ignores errors and does not handle exceptions. + */ + + private static final void ShapePreservingDFZeroSmoothSample ( + final JulianDate dtSpot, + final String strCurrency) + throws Exception + { + /* + * Construct the Array of Deposit Instruments and their Quotes from the given set of parameters + */ + + SingleStreamComponent[] aDepositComp = DepositInstrumentsFromMaturityDays ( + dtSpot, + strCurrency, + new int[] { + 2, + 7, + 14, + 30, + 60 + } + ); + + double[] adblDepositQuote = new double[] { + 0.0013, + 0.0017, + 0.0018, + 0.0020, + 0.0023 + }; + + /* + * Construct the Deposit Instrument Set Stretch Builder + */ + + LatentStateStretchSpec depositStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec ( + "DEPOSIT", + aDepositComp, + "ForwardRate", + adblDepositQuote + ); + + /* + * Construct the Array of EDF Instruments and their Quotes from the given set of parameters + */ + + SingleStreamComponent[] aEDFComp = SingleStreamComponentBuilder.ForwardRateFuturesPack ( + dtSpot, + 8, + strCurrency + ); + + double[] adblEDFQuote = new double[] { + 0.0027, + 0.0032, + 0.0041, + 0.0054, + 0.0077, + 0.0104, + 0.0134, + 0.0160 + }; + + /* + * Construct the EDF Instrument Set Stretch Builder + */ + + LatentStateStretchSpec edfStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec ( + "EDF", + aEDFComp, + "ForwardRate", + adblEDFQuote + ); + + /* + * Construct the Array of Swap Instruments and their Quotes from the given set of parameters + */ + + FixFloatComponent[] aSwapComp = SwapInstrumentsFromMaturityTenor ( + dtSpot, + strCurrency, + new java.lang.String[] { + "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y", "25Y", "30Y", "40Y", "50Y" + } + ); + + double[] adblSwapQuote = new double[] { + 0.0166, 0.0206, 0.0241, 0.0269, 0.0292, 0.0311, 0.0326, 0.0340, 0.0351, 0.0375, 0.0393, 0.0402, 0.0407, 0.0409, 0.0409 + }; + + /* + * Construct the Swap Instrument Set Stretch Builder + */ + + LatentStateStretchSpec swapStretch = LatentStateStretchBuilder.ForwardFundingStretchSpec ( + "SWAP", + aSwapComp, + "SwapRate", + adblSwapQuote + ); + + LatentStateStretchSpec[] aStretchSpec = new LatentStateStretchSpec[] {depositStretch, edfStretch, swapStretch}; + + /* + * Set up the Linear Curve Calibrator using the following parameters: + * - Cubic Exponential Mixture Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + */ + + LinearLatentStateCalibrator lcc = new LinearLatentStateCalibrator ( + new SegmentCustomBuilderControl ( + MultiSegmentSequenceBuilder.BASIS_SPLINE_EXPONENTIAL_MIXTURE, + new ExponentialMixtureSetParams ( + new double[] { + 0.01, + 0.05, + 0.25 + } + ), + SegmentInelasticDesignControl.Create ( + 2, + 2 + ), + new ResponseScalingShapeControl ( + true, + new QuadraticRationalShapeControl (0.) + ), + null + ), + BoundarySettings.NaturalStandard(), + MultiSegmentSequence.CALIBRATE, + null, + null + ); + + /* + * Set up the Global Curve Control parameters as follows: + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + */ + + GlobalControlCurveParams gccp = new GlobalControlCurveParams ( + LatentStateStatic.DISCOUNT_QM_ZERO_RATE, + new SegmentCustomBuilderControl ( + MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, + new PolynomialFunctionSetParams (4), + SegmentInelasticDesignControl.Create ( + 2, + 2 + ), + new ResponseScalingShapeControl ( + true, + new QuadraticRationalShapeControl (0.) + ), + null + ), + BoundarySettings.NaturalStandard(), + MultiSegmentSequence.CALIBRATE, + null, + null + ); + + /* + * Set up the Local Curve Control parameters as follows: + * - C1 Bessel Monotone Smoothener with no spurious extrema elimination and no monotone filter + * - Zero Rate Quantification Metric + * - Cubic Polynomial Basis Spline Set + * - Ck = 2, Segment Curvature Penalty = 2 + * - Quadratic Rational Shape Controller + * - Natural Boundary Setting + */ + + LocalControlCurveParams lccp = new LocalControlCurveParams ( + LocalMonotoneCkGenerator.C1_BESSEL, + LatentStateStatic.DISCOUNT_QM_ZERO_RATE, + new SegmentCustomBuilderControl ( + MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL, + new PolynomialFunctionSetParams (4), + SegmentInelasticDesignControl.Create ( + 2, + 2 + ), + new ResponseScalingShapeControl ( + true, + new QuadraticRationalShapeControl (0.) + ), + null + ), + MultiSegmentSequence.CALIBRATE, + null, + null, + false, + false + ); + + ValuationParams valParams = new ValuationParams ( + dtSpot, + dtSpot, + strCurrency + ); + + /* + * Construct the Shape Preserving Discount Curve by applying the linear curve calibrator to the array + * of Deposit, Futures, and Swap Stretches. + */ + + MergedDiscountForwardCurve dcShapePreserving = ScenarioDiscountCurveBuilder.ShapePreservingDFBuild ( + strCurrency, + lcc, + aStretchSpec, + valParams, + null, + null, + null, + 1. + ); + + /* + * Construct the Globally Smoothened Discount Curve by applying the linear curve calibrator and the + * Global Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving + * discount curve. + */ + + MergedDiscountForwardCurve dcGloballySmooth = ScenarioDiscountCurveBuilder.SmoothingGlobalControlBuild ( + dcShapePreserving, + lcc, + gccp, + valParams, + null, + null, + null + ); + + /* + * Construct the Locally Smoothened Discount Curve by applying the linear curve calibrator and the + * Local Curve Control parameters to the array of Cash and Swap Stretches and the shape preserving + * discount curve. + */ + + MergedDiscountForwardCurve dcLocallySmooth = ScenarioDiscountCurveBuilder.SmoothingLocalControlBuild ( + dcShapePreserving, + lcc, + lccp, + valParams, + null, + null, + null + ); + + /* + * Cross-Comparison of the Deposit Calibration Instrument "Rate" metric across the different curve + * construction methodologies. + */ + + System.out.println ("\n\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t DEPOSIT INSTRUMENTS CALIBRATION RECOVERY"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t SHAPE PRESERVING | SMOOTHING #1 | SMOOTHING #2 | INPUT QUOTE "); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + for (int i = 0; i < aDepositComp.length; ++i) + System.out.println ("\t[" + aDepositComp[i].maturityDate() + "] = " + + FormatUtil.FormatDouble ( + aDepositComp[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null), + null, + "Rate"), + 1, 6, 1.) + " | " + + FormatUtil.FormatDouble ( + aDepositComp[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null), + null, + "Rate"), + 1, 6, 1.) + " | " + + FormatUtil.FormatDouble ( + aDepositComp[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null), + null, + "Rate"), + 1, 6, 1.) + " | " + + FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.) + ); + + /* + * Cross-Comparison of the Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies. + */ + + System.out.println ("\n\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t SWAP INSTRUMENTS CALIBRATION RECOVERY"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t SHAPE PRESERVING | SMOOTHING #1 | SMOOTHING #2 | INPUT QUOTE "); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + for (int i = 0; i < aSwapComp.length; ++i) + System.out.println ("\t[" + aSwapComp[i].maturityDate() + "] = " + + FormatUtil.FormatDouble ( + aSwapComp[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null), + null, + "CalibSwapRate"), + 1, 6, 1.) + " | " + + /* FormatUtil.FormatDouble ( + aSwapComp[i].measureValue ( + new ValuationParams (dtToday, dtToday, "MXN"), null, + MarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null), + null, + "CalibSwapRate"), + 1, 6, 1.) + " | " + */ + FormatUtil.FormatDouble ( + aSwapComp[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null), + null, + "CalibSwapRate"), + 1, 6, 1.) + " | " + + FormatUtil.FormatDouble (adblSwapQuote[i], 1, 6, 1.) + ); + + /* + * Cross-Comparison of the Swap Calibration Instrument "Rate" metric across the different curve + * construction methodologies for a sequence of bespoke swap instruments. + */ + + CalibratableComponent[] aCC = SwapInstrumentsFromMaturityTenor ( + dtSpot, + strCurrency, + new java.lang.String[] { + "3Y", "6Y", "9Y", "12Y", "15Y", "18Y", "21Y", "24Y", "27Y", "30Y" + } + ); + + System.out.println ("\n\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t BESPOKE SWAPS PAR RATE"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t SHAPE PRESERVING | SMOOTHING #1 | SMOOTHING #2"); + + System.out.println ("\t----------------------------------------------------------------"); + + System.out.println ("\t----------------------------------------------------------------"); + + for (int i = 0; i < aCC.length; ++i) + System.out.println ("\t[" + aCC[i].maturityDate() + "] = " + + FormatUtil.FormatDouble ( + aCC[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcShapePreserving, null, null, null, null, null, null), + null, + "CalibSwapRate" + ), + 1, 6, 1.) + " | " + + /* FormatUtil.FormatDouble ( + aCC[i].measureValue (new ValuationParams (dtToday, dtToday, "MXN"), null, + MarketParamsBuilder.Create (dcGloballySmooth, null, null, null, null, null, null), + null, + "CalibSwapRate"), + 1, 6, 1.) + " | " + */ + FormatUtil.FormatDouble ( + aCC[i].measureValue ( + valParams, + null, + MarketParamsBuilder.Create (dcLocallySmooth, null, null, null, null, null, null), + null, + "CalibSwapRate" + ), + 1, 6, 1.) + ); + } + + public static final void main ( + final String[] astrArgs) + throws Exception + { + /* + * Initialize the Credit Analytics Library + */ + + EnvManager.InitEnv (""); + + JulianDate dtSpot = DateUtil.CreateFromYMD ( + 2017, + DateUtil.DECEMBER, + 21 + ); + + String strCurrency = "USD"; + + ShapePreservingDFZeroSmoothSample ( + dtSpot, + strCurrency + ); + } +} diff --git a/src/main/java/org/drip/sample/xvafixfloat/AlbaneseAndersenBaselProxy.java b/src/main/java/org/drip/sample/xvafixfloat/AlbaneseAndersenBaselProxy.java index d65757a6b312..388d2cc39453 100644 --- a/src/main/java/org/drip/sample/xvafixfloat/AlbaneseAndersenBaselProxy.java +++ b/src/main/java/org/drip/sample/xvafixfloat/AlbaneseAndersenBaselProxy.java @@ -10,8 +10,14 @@ import org.drip.quant.common.FormatUtil; import org.drip.quant.linearalgebra.Matrix; import org.drip.service.env.EnvManager; +import org.drip.state.identifier.CreditLabel; +import org.drip.state.identifier.CreditSupportAnnexLabel; +import org.drip.state.identifier.EquityLabel; +import org.drip.state.identifier.OvernightLabel; import org.drip.xva.cpty.*; import org.drip.xva.dynamics.*; +import org.drip.xva.evolver.PrimarySecurity; +import org.drip.xva.evolver.PrimarySecurityContainer; import org.drip.xva.holdings.*; import org.drip.xva.set.*; import org.drip.xva.universe.*; @@ -86,12 +92,16 @@ public class AlbaneseAndersenBaselProxy { - private static final TradeablesContainer GenerateTradeablesContainer ( + private static final PrimarySecurityContainer GenerateTradeablesContainer ( final String eventTenor, final int eventCount, final int iTerminationDate) throws Exception { + String bank = "WFC"; + String currency = "USD"; + String counterParty = "BAC"; + double dblAssetNumeraireDrift = 0.0; double dblAssetNumeraireVolatility = 0.25; double dblAssetNumeraireRepo = 0.0; @@ -126,9 +136,10 @@ private static final TradeablesContainer GenerateTradeablesContainer ( double dblCounterPartyRecoveryRateInitial = 0.30; - Tradeable tAsset = new Tradeable ( + PrimarySecurity tAsset = new PrimarySecurity ( + EquityLabel.Standard ("AAPL"), new DiffusionEvolver ( - DiffusionEvaluatorLinear.Standard ( + DiffusionEvaluatorLogarithmic.Standard ( dblAssetNumeraireDrift, dblAssetNumeraireVolatility ) @@ -136,7 +147,8 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblAssetNumeraireRepo ); - Tradeable tOvernightIndex = new Tradeable ( + PrimarySecurity tOvernightIndex = new PrimarySecurity ( + OvernightLabel.Create (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblOvernightIndexNumeraireDrift, @@ -146,7 +158,8 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblOvernightIndexNumeraireRepo ); - Tradeable tCollateralScheme = new Tradeable ( + PrimarySecurity tCollateralScheme = new PrimarySecurity ( + CreditSupportAnnexLabel.ISDA (currency), new DiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCollateralSchemeNumeraireDrift, @@ -156,7 +169,8 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblCollateralSchemeNumeraireRepo ); - Tradeable tBankSeniorFunding = new Tradeable ( + PrimarySecurity tBankSeniorFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSeniorFundingNumeraireDrift, @@ -170,7 +184,8 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblBankSeniorFundingNumeraireRepo ); - Tradeable tBankSubordinateFunding = new Tradeable ( + PrimarySecurity tBankSubordinateFunding = new PrimarySecurity ( + CreditLabel.Standard (bank), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblBankSubordinateFundingNumeraireDrift, @@ -184,7 +199,8 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblBankSubordinateFundingNumeraireRepo ); - Tradeable tCounterPartyFunding = new Tradeable ( + PrimarySecurity tCounterPartyFunding = new PrimarySecurity ( + CreditLabel.Standard (counterParty), new JumpDiffusionEvolver ( DiffusionEvaluatorLogarithmic.Standard ( dblCounterPartyFundingNumeraireDrift, @@ -198,7 +214,7 @@ private static final TradeablesContainer GenerateTradeablesContainer ( dblCounterPartyFundingNumeraireRepo ); - return new TradeablesContainer ( + return new PrimarySecurityContainer ( tAsset, tOvernightIndex, tCollateralScheme, diff --git a/src/main/java/org/drip/service/scenario/BondReplicator.java b/src/main/java/org/drip/service/scenario/BondReplicator.java index dc3cfdf2af85..dc36811421d4 100644 --- a/src/main/java/org/drip/service/scenario/BondReplicator.java +++ b/src/main/java/org/drip/service/scenario/BondReplicator.java @@ -484,7 +484,7 @@ public BondReplicator ( _valParams = new org.drip.param.valuation.ValuationParams (_dtSpot, _dtSettle, strCurrency); org.drip.state.discount.MergedDiscountForwardCurve mdfc = - org.drip.service.template.LatentMarketStateBuilder.ShapePreservingFundingCurve (_dtSpot, + org.drip.service.template.LatentMarketStateBuilder.SmoothFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", _astrFixFloatTenor, _adblFixFloatQuote, "SwapRate"); @@ -534,7 +534,7 @@ public BondReplicator ( } if (null == (_csqcFunding01Up = org.drip.param.creator.MarketParamsBuilder.Create - (org.drip.service.template.LatentMarketStateBuilder.ShapePreservingFundingCurve (_dtSpot, + (org.drip.service.template.LatentMarketStateBuilder.SmoothFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, org.drip.analytics.support.Helper.ParallelNodeBump (_adblDepositQuote, 0.0001), "ForwardRate", org.drip.analytics.support.Helper.ParallelNodeBump (_adblFuturesQuote, 0.0001), @@ -556,7 +556,7 @@ public BondReplicator ( } if (null == (_csqcFundingEuroDollar = org.drip.param.creator.MarketParamsBuilder.Create - (org.drip.service.template.LatentMarketStateBuilder.ShapePreservingFundingCurve (_dtSpot, + (org.drip.service.template.LatentMarketStateBuilder.SmoothFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", null, null, "SwapRate"), gc, null, null, null, null, null))) throw new java.lang.Exception ("BondReplicator Constructor => Invalid Inputs"); @@ -578,7 +578,7 @@ public BondReplicator ( org.drip.service.template.LatentMarketStateBuilder.BumpedForwardFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", _astrFixFloatTenor, _adblFixFloatQuote, "SwapRate", - org.drip.service.template.LatentMarketStateBuilder.SHAPE_PRESERVING, 0.0001 * + org.drip.service.template.LatentMarketStateBuilder.SMOOTH, 0.0001 * _dblTenorBump, false); java.util.Map @@ -586,7 +586,7 @@ public BondReplicator ( org.drip.service.template.LatentMarketStateBuilder.BumpedForwardFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", _astrFixFloatTenor, _adblFixFloatQuote, "SwapRate", - org.drip.service.template.LatentMarketStateBuilder.SHAPE_PRESERVING, -0.0001 * + org.drip.service.template.LatentMarketStateBuilder.SMOOTH, -0.0001 * _dblTenorBump, false); if (null == mapTenorForwardFundingUp || null == mapTenorForwardFundingDown) @@ -616,14 +616,14 @@ public BondReplicator ( mapTenorFundingUp = org.drip.service.template.LatentMarketStateBuilder.BumpedFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", _astrFixFloatTenor, _adblFixFloatQuote, "SwapRate", - org.drip.service.template.LatentMarketStateBuilder.SHAPE_PRESERVING, 0.0001 * + org.drip.service.template.LatentMarketStateBuilder.SMOOTH, 0.0001 * _dblTenorBump, false); java.util.Map mapTenorFundingDown = org.drip.service.template.LatentMarketStateBuilder.BumpedFundingCurve (_dtSpot, strCurrency, _astrDepositTenor, _adblDepositQuote, "ForwardRate", _adblFuturesQuote, "ForwardRate", _astrFixFloatTenor, _adblFixFloatQuote, "SwapRate", - org.drip.service.template.LatentMarketStateBuilder.SHAPE_PRESERVING, -0.0001 * + org.drip.service.template.LatentMarketStateBuilder.SMOOTH, -0.0001 * _dblTenorBump, false); if (null == mapTenorFundingUp || null == mapTenorFundingDown) diff --git a/src/main/java/org/drip/spline/stretch/CalibratableMultiSegmentSequence.java b/src/main/java/org/drip/spline/stretch/CalibratableMultiSegmentSequence.java index 846d8153af66..4036b104bf39 100644 --- a/src/main/java/org/drip/spline/stretch/CalibratableMultiSegmentSequence.java +++ b/src/main/java/org/drip/spline/stretch/CalibratableMultiSegmentSequence.java @@ -376,7 +376,9 @@ public CalibratableMultiSegmentSequence ( return calcRightEdgeDerivative (bs.rightDerivOrder()); if (org.drip.spline.stretch.BoundarySettings.BOUNDARY_CONDITION_FINANCIAL == iBC) + { return calcRightEdgeDerivative (bs.rightDerivOrder()); + } if (org.drip.spline.stretch.BoundarySettings.BOUNDARY_CONDITION_NOT_A_KNOT == iBC) return calcRightEdgeDerivative (bs.rightDerivOrder()) - calcLeftEdgeDerivative diff --git a/src/main/java/org/drip/state/discount/DiscountCurve.java b/src/main/java/org/drip/state/discount/DiscountCurve.java index 8b5f3fc57ad2..422f216b1769 100644 --- a/src/main/java/org/drip/state/discount/DiscountCurve.java +++ b/src/main/java/org/drip/state/discount/DiscountCurve.java @@ -281,7 +281,7 @@ public org.drip.state.nonlinear.FlatForwardDiscountCurve flatNativeForwardEI ( adblForwardRate[i] = ((df (iStartDate) / df (aiDate[i])) - 1.) / org.drip.analytics.daycount.Convention.YearFraction (iStartDate, aiDate[i], strDayCount, - false, aap, strCurrency) + (aiDate[i] >= iDateLeft && aiDate[i] < iDateRight ? + false, aap, strCurrency) + (aiDate[i] > iDateLeft && aiDate[i] <= iDateRight ? dblBump : 0.); } diff --git a/src/main/java/org/drip/xva/universe/Equity.java b/src/main/java/org/drip/xva/evolver/Equity.java similarity index 95% rename from src/main/java/org/drip/xva/universe/Equity.java rename to src/main/java/org/drip/xva/evolver/Equity.java index 25a5e22b62b2..647772c4c1ea 100644 --- a/src/main/java/org/drip/xva/universe/Equity.java +++ b/src/main/java/org/drip/xva/evolver/Equity.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.xva.evolver; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -70,13 +70,14 @@ * @author Lakshmi Krishnamurthy */ -public class Equity extends org.drip.xva.universe.Tradeable +public class Equity extends org.drip.xva.evolver.PrimarySecurity { private double _dividendRate = java.lang.Double.NaN; /** * Equity Constructor * + * @param label The Latent State Label * @param evolver The Equity Price Evolver * @param dblRepoRate The Equity Repo Rate * @param dividendRate The Equity Dividend Rate @@ -85,18 +86,22 @@ public class Equity extends org.drip.xva.universe.Tradeable */ public Equity ( + final org.drip.state.identifier.LatentStateLabel label, final org.drip.measure.process.DiffusionEvolver evolver, final double dblRepoRate, final double dividendRate) throws java.lang.Exception { super ( + label, evolver, dblRepoRate ); if (!org.drip.quant.common.NumberUtil.IsValid (_dividendRate = dividendRate)) + { throw new java.lang.Exception ("Equity Constructor => Invalid Inputs"); + } } /** diff --git a/src/main/java/org/drip/xva/evolver/Numeraire.java b/src/main/java/org/drip/xva/evolver/Numeraire.java new file mode 100644 index 000000000000..f9e183c39490 --- /dev/null +++ b/src/main/java/org/drip/xva/evolver/Numeraire.java @@ -0,0 +1,103 @@ + +package org.drip.xva.evolver; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2018 Lakshmi Krishnamurthy + * Copyright (C) 2017 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. + */ + +/** + * Numeraire holds Parameters that guide the Diffusion of a Numeraire. The References are: + * + * - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk + * and Funding Costs, Journal of Credit Risk, 7 (3) 1-19. + * + * - Cesari, G., J. Aquilina, N. Charpillon, X. Filipovic, G. Lee, and L. Manda (2009): Modeling, Pricing, + * and Hedging Counter-party Credit Exposure - A Technical Guide, Springer Finance, New York. + * + * - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90. + * + * - Li, B., and Y. Tang (2007): Quantitative Analysis, Derivatives Modeling, and Trading Strategies in the + * Presence of Counter-party Credit Risk for the Fixed Income Market, World Scientific Publishing, + * Singapore. + * + * - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk + * 21 (2) 97-102. + * + * @author Lakshmi Krishnamurthy + */ + +public class Numeraire +{ + private org.drip.measure.process.DiffusionEvolver _evolver = null; + + /** + * Numeraire Constructor + * + * @param evolver Numeraire Diffusion Evolver + * + * @throws java.lang.Exception Thrown if the Inputs are Invalid + */ + + public Numeraire ( + final org.drip.measure.process.DiffusionEvolver evolver) + throws java.lang.Exception + { + if (null == (_evolver = evolver)) + { + throw new java.lang.Exception ("Numeraire Constructor => Invalid Inputs!"); + } + } + + /** + * Retrieve the Numeraire Evolver + * + * @return The Numeraire Evolver + */ + + public org.drip.measure.process.DiffusionEvolver evolver() + { + return _evolver; + } +} diff --git a/src/main/java/org/drip/xva/universe/Tradeable.java b/src/main/java/org/drip/xva/evolver/PrimarySecurity.java similarity index 78% rename from src/main/java/org/drip/xva/universe/Tradeable.java rename to src/main/java/org/drip/xva/evolver/PrimarySecurity.java index ed7428451a18..59c04b7e3963 100644 --- a/src/main/java/org/drip/xva/universe/Tradeable.java +++ b/src/main/java/org/drip/xva/evolver/PrimarySecurity.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.xva.evolver; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -48,8 +48,8 @@ */ /** - * Tradeable holds Definitions and Parameters that specify a Tradeable Entity in XVA Terms. The References - * are: + * PrimarySecurity holds Definitions and Parameters that specify a Primary Security in XVA Terms. The + * References are: * * - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk * and Funding Costs, Journal of Credit Risk, 7 (3) 1-19. @@ -69,39 +69,44 @@ * @author Lakshmi Krishnamurthy */ -public class Tradeable +public class PrimarySecurity extends org.drip.xva.evolver.Numeraire { private double _repoRate = java.lang.Double.NaN; - private org.drip.measure.process.DiffusionEvolver _evolver = null; + private org.drip.state.identifier.LatentStateLabel _label = null; /** - * Tradeable Constructor + * PrimarySecurity Constructor * - * @param evolver The Tradeable Evolver + * @param label The Latent State Label + * @param evolver The Primary Security Evolver * @param repoRate The Repo Rate * * @throws java.lang.Exception Thrown if the Inputs are Invalid */ - public Tradeable ( + public PrimarySecurity ( + final org.drip.state.identifier.LatentStateLabel label, final org.drip.measure.process.DiffusionEvolver evolver, final double repoRate) throws java.lang.Exception { - if (null == (_evolver = evolver) || - !org.drip.quant.common.NumberUtil.IsValid (_repoRate = repoRate)) - throw new java.lang.Exception ("Tradeable Constructor => Invalid Inputs"); + super (evolver); + + if (!org.drip.quant.common.NumberUtil.IsValid (_repoRate = repoRate)) + { + throw new java.lang.Exception ("PrimarySecurity Constructor => Invalid Inputs"); + } } /** - * Retrieve the Evolver + * Retrieve the Latent State Label * - * @return The Evolver + * @return The Latent State Label */ - public org.drip.measure.process.DiffusionEvolver evolver() + public org.drip.state.identifier.LatentStateLabel label() { - return _evolver; + return _label; } /** @@ -115,6 +120,17 @@ public double repoRate() return _repoRate; } + /** + * Indicate if the PrimarySecurity is Repo-able + * + * @return TRUE - The PrimarySecurity is Repo-able + */ + + public boolean isRepoable() + { + return 0. != _repoRate; + } + /** * Retrieve the Cash Accumulation Rate * diff --git a/src/main/java/org/drip/xva/universe/TradeablesContainer.java b/src/main/java/org/drip/xva/evolver/PrimarySecurityContainer.java similarity index 60% rename from src/main/java/org/drip/xva/universe/TradeablesContainer.java rename to src/main/java/org/drip/xva/evolver/PrimarySecurityContainer.java index 05f381380d94..60f153b21058 100644 --- a/src/main/java/org/drip/xva/universe/TradeablesContainer.java +++ b/src/main/java/org/drip/xva/evolver/PrimarySecurityContainer.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.xva.evolver; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -48,7 +48,7 @@ */ /** - * TradeablesContainer describes the Economy with the following Traded Assets - the Overnight Index + * PrimarySecurityContainer holds the Economy with the following Traded Assets - the Overnight Index * Numeraire, the Collateral Scheme Numeraire, the Default-able Bank Bond Numeraire, the Array of * Default-able Counter-party Numeraires, and an Asset that follows Brownian Motion. The References are: * @@ -68,109 +68,111 @@ * @author Lakshmi Krishnamurthy */ -public class TradeablesContainer +public class PrimarySecurityContainer { - private org.drip.xva.universe.Tradeable _csa = null; - private org.drip.xva.universe.Tradeable _overnight = null; - private org.drip.xva.universe.Tradeable _positionManifest = null; - private org.drip.xva.universe.Tradeable _bankSeniorFunding = null; - private org.drip.xva.universe.Tradeable _counterPartyFunding = null; - private org.drip.xva.universe.Tradeable _bankSubordinateFunding = null; + private org.drip.xva.evolver.PrimarySecurity _csa = null; + private org.drip.xva.evolver.PrimarySecurity _position = null; + private org.drip.xva.evolver.PrimarySecurity _overnight = null; + private org.drip.xva.evolver.PrimarySecurity _bankSeniorFunding = null; + private org.drip.xva.evolver.PrimarySecurity _counterPartyFunding = null; + private org.drip.xva.evolver.PrimarySecurity _bankSubordinateFunding = null; /** - * LatentStateDynamicsContainer Constructor + * PrimarySecurityContainer Constructor * - * @param positionManifest The Position Tradeable Manifest - * @param overnight The Overnight Index Tradeable - * @param csa The CSA Tradeable - * @param bankSeniorFunding Bank Senior Funding Tradeable - * @param bankSubordinateFunding Bank Subordinate Funding Tradeable - * @param counterPartyFunding Counter Party Funding Tradeable + * @param position The Position Primary Security + * @param overnight The Overnight Index Primary Security + * @param csa The CSA Primary Security + * @param bankSeniorFunding Bank Senior Funding Primary Security + * @param bankSubordinateFunding Bank Subordinate Funding Primary Security + * @param counterPartyFunding Counter Party Funding Primary Security * * @throws java.lang.Exception Thrown if the Inputs are Invalid */ - public TradeablesContainer ( - final org.drip.xva.universe.Tradeable positionManifest, - final org.drip.xva.universe.Tradeable overnight, - final org.drip.xva.universe.Tradeable csa, - final org.drip.xva.universe.Tradeable bankSeniorFunding, - final org.drip.xva.universe.Tradeable bankSubordinateFunding, - final org.drip.xva.universe.Tradeable counterPartyFunding) + public PrimarySecurityContainer ( + final org.drip.xva.evolver.PrimarySecurity position, + final org.drip.xva.evolver.PrimarySecurity overnight, + final org.drip.xva.evolver.PrimarySecurity csa, + final org.drip.xva.evolver.PrimarySecurity bankSeniorFunding, + final org.drip.xva.evolver.PrimarySecurity bankSubordinateFunding, + final org.drip.xva.evolver.PrimarySecurity counterPartyFunding) throws java.lang.Exception { if (null == (_overnight = overnight) || null == (_csa = csa) || null == (_bankSeniorFunding = bankSeniorFunding) || null == (_counterPartyFunding = counterPartyFunding)) - throw new java.lang.Exception ("LatentStateDynamicsContainer Constructor => Invalid Inputs"); + { + throw new java.lang.Exception ("PrimarySecurityContainer Constructor => Invalid Inputs"); + } - _positionManifest = positionManifest; + _position = position; _bankSubordinateFunding = bankSubordinateFunding; } /** - * Retrieve the Position Tradeable Manifest + * Retrieve the Position Primary Security * - * @return The Position Tradeable Manifest + * @return The Position Primary Security */ - public org.drip.xva.universe.Tradeable positionManifest() + public org.drip.xva.evolver.PrimarySecurity position() { - return _positionManifest; + return _position; } /** - * Retrieve the Overnight Index Tradeable + * Retrieve the Overnight Index Primary Security * - * @return The Overnight Index Tradeable + * @return The Overnight Index Primary Security */ - public org.drip.xva.universe.Tradeable overnight() + public org.drip.xva.evolver.PrimarySecurity overnight() { return _overnight; } /** - * Retrieve the CSA Tradeable + * Retrieve the CSA Primary Security * - * @return The CSA Tradeable + * @return The CSA Primary Security */ - public org.drip.xva.universe.Tradeable csa() + public org.drip.xva.evolver.PrimarySecurity csa() { return _csa; } /** - * Retrieve the Bank Senior Funding Tradeable + * Retrieve the Bank Senior Funding Primary Security * - * @return The Bank Senior Funding Tradeable + * @return The Bank Senior Funding Primary Security */ - public org.drip.xva.universe.Tradeable bankSeniorFunding() + public org.drip.xva.evolver.PrimarySecurity bankSeniorFunding() { return _bankSeniorFunding; } /** - * Retrieve the Bank Subordinate Funding Tradeable + * Retrieve the Bank Subordinate Funding Primary Security * - * @return The Bank Subordinate Funding Tradeable + * @return The Bank Subordinate Funding Primary Security */ - public org.drip.xva.universe.Tradeable bankSubordinateFunding() + public org.drip.xva.evolver.PrimarySecurity bankSubordinateFunding() { return _bankSubordinateFunding; } /** - * Retrieve the Counter Party Funding Tradeable + * Retrieve the Counter Party Funding Primary Security * - * @return The Counter Party Funding Tradeable + * @return The Counter Party Funding Primary Security */ - public org.drip.xva.universe.Tradeable counterPartyFunding() + public org.drip.xva.evolver.PrimarySecurity counterPartyFunding() { return _counterPartyFunding; } diff --git a/src/main/java/org/drip/xva/universe/LatentStateEvolver.java b/src/main/java/org/drip/xva/evolver/TerminalLatentState.java similarity index 91% rename from src/main/java/org/drip/xva/universe/LatentStateEvolver.java rename to src/main/java/org/drip/xva/evolver/TerminalLatentState.java index 6332d3797bbc..e9549fb04180 100644 --- a/src/main/java/org/drip/xva/universe/LatentStateEvolver.java +++ b/src/main/java/org/drip/xva/evolver/TerminalLatentState.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.xva.evolver; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -47,8 +47,8 @@ */ /** - * LatentStateEvolver contains the Latent State Label and the corresponding Diffusion Evolver. The References - * are:

+ * TerminalLatentState contains the Latent State Label and the corresponding Terminal Diffusion Evolver. The + * References are:

* * - Burgard, C., and M. Kjaer (2013): Funding Strategies, Funding Costs Risk 24 (12) * 82-87.

@@ -67,13 +67,13 @@ * @author Lakshmi Krishnamurthy */ -public class LatentStateEvolver +public class TerminalLatentState { private org.drip.state.identifier.LatentStateLabel _label = null; private org.drip.measure.process.DiffusionEvolver _diffusionEvolver = null; /** - * LatentStateEvolver Constructor + * TerminalLatentState Constructor * * @param label The Latest State Label * @param diffusionEvolver The Latent State Diffusion Evolver @@ -81,7 +81,7 @@ public class LatentStateEvolver * @throws java.lang.Exception Thrown if the Inputs are Invalid */ - public LatentStateEvolver ( + public TerminalLatentState ( final org.drip.state.identifier.LatentStateLabel label, final org.drip.measure.process.DiffusionEvolver diffusionEvolver) throws java.lang.Exception @@ -89,7 +89,7 @@ public LatentStateEvolver ( if (null == (_label = label) || (null == (_diffusionEvolver = diffusionEvolver))) { - throw new java.lang.Exception ("LatentStateEvolver Constructor => Invalid Inputs"); + throw new java.lang.Exception ("TerminalLatentState Constructor => Invalid Inputs"); } } diff --git a/src/main/java/org/drip/xva/universe/LatentStateEvolverContainer.java b/src/main/java/org/drip/xva/evolver/TerminalLatentStateContainer.java similarity index 86% rename from src/main/java/org/drip/xva/universe/LatentStateEvolverContainer.java rename to src/main/java/org/drip/xva/evolver/TerminalLatentStateContainer.java index 14c5eac7c988..44a54b841e5f 100644 --- a/src/main/java/org/drip/xva/universe/LatentStateEvolverContainer.java +++ b/src/main/java/org/drip/xva/evolver/TerminalLatentStateContainer.java @@ -1,5 +1,5 @@ -package org.drip.xva.universe; +package org.drip.xva.evolver; /* * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- @@ -47,8 +47,8 @@ */ /** - * LatentStateEvolverContainer holds the Latent States and their Jump Diffusion Evolvers. The References - * are:

+ * TerminalLatentStateContainer holds the Latent States and their Terminal Jump Diffusion Evolvers. The + * References are:

* * - Burgard, C., and M. Kjaer (2013): Funding Strategies, Funding Costs Risk 24 (12) * 82-87.

@@ -67,16 +67,16 @@ * @author Lakshmi Krishnamurthy */ -public class LatentStateEvolverContainer +public class TerminalLatentStateContainer { - private java.util.Map _evolverMap = - new org.drip.analytics.support.CaseInsensitiveHashMap(); + private java.util.Map _evolverMap = + new org.drip.analytics.support.CaseInsensitiveHashMap(); /** - * Empty LatentStateEvolverContainer Constructor + * Empty TerminalLatentStateContainer Constructor */ - public LatentStateEvolverContainer() + public TerminalLatentStateContainer() { } @@ -86,7 +86,7 @@ public LatentStateEvolverContainer() * @return The Jump Diffusion Evolver Map */ - public java.util.Map evolverMap() + public java.util.Map evolverMap() { return _evolverMap; } @@ -100,7 +100,7 @@ public java.util.Map */ public boolean addEvolver ( - final org.drip.xva.universe.LatentStateEvolver latentStateEvolver) + final org.drip.xva.evolver.TerminalLatentState latentStateEvolver) { if (null == latentStateEvolver) { @@ -137,7 +137,7 @@ public boolean containsEvolver ( * @return The Latent State Evolver from the Label */ - public org.drip.xva.universe.LatentStateEvolver evolver ( + public org.drip.xva.evolver.TerminalLatentState evolver ( final org.drip.state.identifier.LatentStateLabel label) { return containsEvolver (label) ? _evolverMap.get (label.fullyQualifiedName()) : null; diff --git a/src/main/java/org/drip/xva/evolver/package-info.java b/src/main/java/org/drip/xva/evolver/package-info.java new file mode 100644 index 000000000000..f73e3833b133 --- /dev/null +++ b/src/main/java/org/drip/xva/evolver/package-info.java @@ -0,0 +1,8 @@ + +/** + * XVA Securities and States Evolvers + * + * @author Lakshmi Krishnamurthy + */ + +package org.drip.xva.evolver; diff --git a/src/main/java/org/drip/xva/pde/BurgardKjaerOperator.java b/src/main/java/org/drip/xva/pde/BurgardKjaerOperator.java index 6f3ef30a26a7..81ae99e6bf9b 100644 --- a/src/main/java/org/drip/xva/pde/BurgardKjaerOperator.java +++ b/src/main/java/org/drip/xva/pde/BurgardKjaerOperator.java @@ -72,7 +72,7 @@ public class BurgardKjaerOperator { - private org.drip.xva.universe.TradeablesContainer _tradeablesContainer = null; + private org.drip.xva.evolver.PrimarySecurityContainer _tradeablesContainer = null; private org.drip.xva.definition.PDEEvolutionControl _pdeEvolutionControl = null; /** @@ -85,7 +85,7 @@ public class BurgardKjaerOperator */ public BurgardKjaerOperator ( - final org.drip.xva.universe.TradeablesContainer tradeablesContainer, + final org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer, final org.drip.xva.definition.PDEEvolutionControl pdeEvolutionControl) throws java.lang.Exception { @@ -102,7 +102,7 @@ public BurgardKjaerOperator ( * @return The Universe of Trade-able Assets */ - public org.drip.xva.universe.TradeablesContainer tradeablesContainer() + public org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer() { return _tradeablesContainer; } @@ -169,7 +169,7 @@ public org.drip.xva.pde.BurgardKjaerEdgeRun edgeRun ( try { double[] bumpedThetaArray = new org.drip.xva.pde.ParabolicDifferentialOperator - (_tradeablesContainer.positionManifest()).thetaUpDown ( + (_tradeablesContainer.position()).thetaUpDown ( initialTrajectoryVertex, initialPortfolioValue, portfolioValueBump @@ -255,7 +255,7 @@ public org.drip.xva.pde.BurgardKjaerEdgeAttribution edgeRunAttribution ( try { double[] bumpedThetaArray = new org.drip.xva.pde.ParabolicDifferentialOperator - (_tradeablesContainer.positionManifest()).thetaUpDown ( + (_tradeablesContainer.position()).thetaUpDown ( initialTrajectoryVertex, initialPortfolioValue, portfolioValueBump diff --git a/src/main/java/org/drip/xva/pde/ParabolicDifferentialOperator.java b/src/main/java/org/drip/xva/pde/ParabolicDifferentialOperator.java index 36fffa78a87a..cd4dc0617316 100644 --- a/src/main/java/org/drip/xva/pde/ParabolicDifferentialOperator.java +++ b/src/main/java/org/drip/xva/pde/ParabolicDifferentialOperator.java @@ -72,7 +72,7 @@ public class ParabolicDifferentialOperator { - private org.drip.xva.universe.Tradeable _tradeable = null; + private org.drip.xva.evolver.PrimarySecurity _tradeable = null; /** * ParabolicDifferentialOperator Constructor @@ -83,7 +83,7 @@ public class ParabolicDifferentialOperator */ public ParabolicDifferentialOperator ( - final org.drip.xva.universe.Tradeable tradeable) + final org.drip.xva.evolver.PrimarySecurity tradeable) throws java.lang.Exception { if (null == (_tradeable = tradeable)) @@ -98,7 +98,7 @@ public ParabolicDifferentialOperator ( * @return The Tradeable Position */ - public org.drip.xva.universe.Tradeable asset() + public org.drip.xva.evolver.PrimarySecurity asset() { return _tradeable; } diff --git a/src/main/java/org/drip/xva/pde/TrajectoryEvolutionScheme.java b/src/main/java/org/drip/xva/pde/TrajectoryEvolutionScheme.java index 177ebfed6905..fb50ccd6ace9 100644 --- a/src/main/java/org/drip/xva/pde/TrajectoryEvolutionScheme.java +++ b/src/main/java/org/drip/xva/pde/TrajectoryEvolutionScheme.java @@ -71,7 +71,7 @@ public class TrajectoryEvolutionScheme { - private org.drip.xva.universe.TradeablesContainer _tradeablesContainer = null; + private org.drip.xva.evolver.PrimarySecurityContainer _tradeablesContainer = null; private org.drip.xva.definition.PDEEvolutionControl _pdeEvolutionControl = null; /** @@ -84,7 +84,7 @@ public class TrajectoryEvolutionScheme */ public TrajectoryEvolutionScheme ( - final org.drip.xva.universe.TradeablesContainer tradeablesContainer, + final org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer, final org.drip.xva.definition.PDEEvolutionControl pdeEvolutionControl) throws java.lang.Exception { @@ -101,7 +101,7 @@ public TrajectoryEvolutionScheme ( * @return The Universe of Tradeables */ - public org.drip.xva.universe.TradeablesContainer tradeablesContainer() + public org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer() { return _tradeablesContainer; } @@ -173,9 +173,9 @@ public org.drip.xva.derivative.CashAccountRebalancer rebalanceCash ( double timeIncrement = marketEdge.vertexIncrement() / 365.25; double portfolioCashChange = initialPortfolioHoldings * - _tradeablesContainer.positionManifest().cashAccumulationRate() * finalPortfolioValue * timeIncrement; + _tradeablesContainer.position().cashAccumulationRate() * finalPortfolioValue * timeIncrement; - org.drip.xva.universe.Tradeable counterPartyFundingTradeable = + org.drip.xva.evolver.PrimarySecurity counterPartyFundingTradeable = _tradeablesContainer.counterPartyFunding(); double counterPartyCashAccumulation = initialCounterPartyNumeraireHoldings * @@ -193,9 +193,9 @@ public org.drip.xva.derivative.CashAccountRebalancer rebalanceCash ( finalBankSubordinateFundingNumeraire; } - org.drip.xva.universe.Tradeable csaTradeable = _tradeablesContainer.csa(); + org.drip.xva.evolver.PrimarySecurity csaTradeable = _tradeablesContainer.csa(); - org.drip.xva.universe.Tradeable bankSeniorFundingTradeable = + org.drip.xva.evolver.PrimarySecurity bankSeniorFundingTradeable = _tradeablesContainer.bankSeniorFunding(); double bankCashAccumulation = cashAccountBalance * (cashAccountBalance > 0. ? @@ -341,7 +341,7 @@ public org.drip.xva.derivative.EvolutionTrajectoryEdge eulerWalk ( double bankSeniorFundingNumeraire = bankMarketVertex.seniorFundingReplicator(); - org.drip.xva.universe.Tradeable csaTradeable = _tradeablesContainer.csa(); + org.drip.xva.evolver.PrimarySecurity csaTradeable = _tradeablesContainer.csa(); try { diff --git a/src/main/java/org/drip/xva/universe/MarketVertexGenerator.java b/src/main/java/org/drip/xva/universe/MarketVertexGenerator.java index cb8715a66c7b..9196de23cf48 100644 --- a/src/main/java/org/drip/xva/universe/MarketVertexGenerator.java +++ b/src/main/java/org/drip/xva/universe/MarketVertexGenerator.java @@ -140,7 +140,7 @@ public class MarketVertexGenerator private int _spotDate = -1; private double[] _ycfWidth = null; private int[] _eventDateArray = null; - private org.drip.xva.universe.TradeablesContainer _tradeablesContainer = null; + private org.drip.xva.evolver.PrimarySecurityContainer _tradeablesContainer = null; private org.drip.xva.universe.EntityLatentStateEvolver _entityLatentStateEvolver = null; /** @@ -159,14 +159,14 @@ public static final MarketVertexGenerator PeriodHorizon ( final int spotDate, final java.lang.String periodTenor, final int periodCount, - final org.drip.xva.universe.TradeablesContainer tradeablesContainer, + final org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer, final org.drip.xva.universe.EntityLatentStateEvolver entityLatentStateEvolver) { try { return new MarketVertexGenerator ( spotDate, - org.drip.xva.universe.VertexDateBuilder.SpotDatePeriodTenor ( + org.drip.analytics.support.VertexDateBuilder.SpotDatePeriodTenor ( spotDate, periodTenor, periodCount @@ -197,7 +197,7 @@ public static final MarketVertexGenerator PeriodHorizon ( public MarketVertexGenerator ( final int spotDate, final int[] eventDateArray, - final org.drip.xva.universe.TradeablesContainer tradeablesContainer, + final org.drip.xva.evolver.PrimarySecurityContainer tradeablesContainer, final org.drip.xva.universe.EntityLatentStateEvolver entityLatentStateEvolver) throws java.lang.Exception { @@ -304,9 +304,9 @@ public org.drip.xva.universe.MarketVertex[] marketVertex ( return null; } - org.drip.xva.universe.Tradeable positionManifest = _tradeablesContainer.positionManifest(); + org.drip.xva.evolver.PrimarySecurity positionManifest = _tradeablesContainer.position(); - org.drip.xva.universe.Tradeable bankSubordinateFundingNumeraire = + org.drip.xva.evolver.PrimarySecurity bankSubordinateFundingNumeraire = _tradeablesContainer.bankSubordinateFunding(); double bankSurvivalProbabilityExponent = 0.; diff --git a/src/main/java/org/drip/xva/universe/TradeableLatentStateEvolver.java b/src/main/java/org/drip/xva/universe/TradeableLatentStateEvolver.java new file mode 100644 index 000000000000..00c88adf4a1e --- /dev/null +++ b/src/main/java/org/drip/xva/universe/TradeableLatentStateEvolver.java @@ -0,0 +1,111 @@ + +package org.drip.xva.universe; + +/* + * -*- 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. + */ + +/** + * TradeableLatentStateEvolver is a Latent State Evolver that doubles up as a Tradeable. The References + * are:

+ * + * - Burgard, C., and M. Kjaer (2013): Funding Strategies, Funding Costs Risk 24 (12) + * 82-87.

+ * + * - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk + * and Funding Costs Journal of Credit Risk 7 (3) 1-19.

+ * + * - Burgard, C., and M. Kjaer (2014): In the Balance Risk 24 (11) 72-75.

+ * + * - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk Risk 20 (2) + * 86-90.

+ * + * - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing + * Risk 21 (2) 97-102.

+ * + * @author Lakshmi Krishnamurthy + */ + +public class TradeableLatentStateEvolver extends org.drip.xva.evolver.TerminalLatentState +{ + private org.drip.xva.evolver.PrimarySecurity _tradeable = null; + + /** + * TradeableLatentStateEvolver Constructor + * + * @param label The Latest State Label + * @param diffusionEvolver The Latent State Diffusion Evolver + * @param tradeable The Tradeable Component + * + * @throws java.lang.Exception Thrown if the Inputs are Invalid + */ + + public TradeableLatentStateEvolver ( + final org.drip.state.identifier.LatentStateLabel label, + final org.drip.measure.process.DiffusionEvolver diffusionEvolver, + final org.drip.xva.evolver.PrimarySecurity tradeable) + throws java.lang.Exception + { + super ( + label, + diffusionEvolver + ); + + if (null == (_tradeable = tradeable)) + { + throw new java.lang.Exception ("TradeableLatentStateEvolver Constructor => Invalid Inputs"); + } + } + + /** + * Retrieve the Tradeable + * + * @return The Tradeable + */ + + public org.drip.xva.evolver.PrimarySecurity tradeable() + { + return _tradeable; + } +}