diff --git a/ReleaseNotes/12_22_2022.txt b/ReleaseNotes/12_22_2022.txt new file mode 100644 index 00000000000..ea3f40243c8 --- /dev/null +++ b/ReleaseNotes/12_22_2022.txt @@ -0,0 +1,37 @@ + +Features: + + - Composite R^1 Exponential Distribution Shell (1, 2) + - Minimum Among Exponential Distribution #1 (3, 4) + - Minimum Among Exponential Distribution #2 (5, 6, 7) + - Composite R^1 Exponential Distribution Constructor (8, 9, 10) + - Minimum of Realized Exponential Distributions (11, 12) + - Composite R^1 Rate Distribution Shell (15, 16) + - Realized R^1 Rate Distribution Standard (17, 18, 19) + - Realized R^1 Rate Distribution Constructor (20, 21, 22) + - R^1 Exponential Rate Distribution Array (23, 24, 25) + - Probability of Index as Minimum (26, 27, 28) + - Composite R^1 Order Statistics Shell (29, 30) + - Exponential IID Joint Moment #1 (31, 32, 33) + - Exponential IID Joint Moment #2 (34, 35, 36) + - Exponential IID Joint Moment #3 (37, 38, 39) + - Exponential IID Joint Moment #4 (40, 41, 42) + - Two IID Exponential Sum Shell (43, 44) + - Smaller R^1 Exponential Rate Distribution (45, 46) + - Larger R^1 Exponential Rate Distribution (47, 48) + - Two IID Exponential Sum Constructor (49, 50, 51) + - Two IID Exponential Sum Support (52) + - Two IID Exponential Sum Density (53, 54, 55) + - Two IID Sum Quadrature Count (56, 57) + - Two IID Exponential Sum Mean (58, 59, 60) + + +Bug Fixes/Re-organization: + + - Composite R^1 To Minima Realization (13, 14) + + +Samples: + + +IdeaDRIP: diff --git a/ScheduleSheet.xlsx b/ScheduleSheet.xlsx index 24338f8a20f..a535ffd72d2 100644 Binary files a/ScheduleSheet.xlsx and b/ScheduleSheet.xlsx differ diff --git a/src/main/java/org/drip/measure/exponential/CompositeR1OrderStatistics.java b/src/main/java/org/drip/measure/exponential/CompositeR1OrderStatistics.java new file mode 100644 index 00000000000..1148e406f03 --- /dev/null +++ b/src/main/java/org/drip/measure/exponential/CompositeR1OrderStatistics.java @@ -0,0 +1,175 @@ + +package org.drip.measure.exponential; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2023 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * 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. + */ + +/** + * CompositeR1OrderStatistics generates the Order Statistics for a Composite Set of R1 + * Exponential Distributions. The References are: + * + *

+ * + * + *

+ * + * + * @author Lakshmi Krishnamurthy + */ + +public class CompositeR1OrderStatistics +{ + + /** + * Compute the Joint Moment of a Set of i.i.d. Distributions + * + * @param r1RateDistribution R1 Exponential Distribution + * @param variateCount Variate Count + * @param index1 First Index + * @param index2 Second Index + * + * @return Joint Moment of a Set of i.i.d. Distributions + * + * @throws Exception Thrown if the Inputs are Invalid + */ + + public static final double IIDJointMoment ( + final R1RateDistribution r1RateDistribution, + final int variateCount, + final int index1, + final int index2) + throws Exception + { + if (null == r1RateDistribution || + 0 > index1 || index1 >= variateCount || + 0 > index2 || index2 >= variateCount || index1 == index2 + ) + { + throw new Exception ( + "CompositeR1OrderStatistics::IIDJointMoment => Invalid Inputs" + ); + } + + double expectationMaxIndex = 0.; + double expectationMinIndex = 0.; + double expectationMinIndexSquared = 0.; + int maxIndex = index1 > index2 ? index1 : index2; + int minIndex = index1 < index2 ? index1 : index2; + + double inverseRate = 1. / r1RateDistribution.rate(); + + for (int k = 0; + k < minIndex; + ++k) + { + double expectation = inverseRate / (variateCount - k); + expectationMinIndexSquared += expectation * expectation; + expectationMinIndex += expectation; + } + + for (int k = 0; + k < maxIndex; + ++k) + { + expectationMaxIndex += inverseRate / (variateCount - k); + } + + return expectationMinIndex * expectationMaxIndex + expectationMinIndexSquared + + expectationMinIndex * expectationMinIndex; + } +} diff --git a/src/main/java/org/drip/measure/exponential/R1RateDistribution.java b/src/main/java/org/drip/measure/exponential/R1RateDistribution.java index 180335b1edb..714bd7d6f8c 100644 --- a/src/main/java/org/drip/measure/exponential/R1RateDistribution.java +++ b/src/main/java/org/drip/measure/exponential/R1RateDistribution.java @@ -163,9 +163,9 @@ public R1RateDistribution ( } /** - * Retrieve the Rate Parameter Lambda + * Retrieve the Lambda * - * @return Rate Parameter Lambda + * @return Lambda */ public double lambda() @@ -174,9 +174,9 @@ public double lambda() } /** - * Retrieve the Rate Parameter Lambda + * Retrieve the Rate Parameter * - * @return Rate Parameter Lambda + * @return Rate Parameter */ public double rate() diff --git a/src/main/java/org/drip/measure/exponential/RealizedMinimaR1RateDistribution.java b/src/main/java/org/drip/measure/exponential/RealizedMinimaR1RateDistribution.java new file mode 100644 index 00000000000..eb04e04f7cb --- /dev/null +++ b/src/main/java/org/drip/measure/exponential/RealizedMinimaR1RateDistribution.java @@ -0,0 +1,215 @@ + +package org.drip.measure.exponential; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2023 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * 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. + */ + +/** + * RealizedMinimaR1RateDistribution implements the Rate Parameterization of the Realized Minimum among + * the Set of R1 Exponential Distributions. The References are: + * + *

+ * + * + *

+ * + * + * @author Lakshmi Krishnamurthy + */ + +public class RealizedMinimaR1RateDistribution + extends R1RateDistribution +{ + private R1RateDistribution[] _r1RateDistributionArray = null; + + /** + * Standard Instance of RealizedMinimaR1RateDistribution + * + * @param r1RateDistributionArray R1 Exponential Distribution Array + * + * @return Standard Instance of RealizedMinimaR1RateDistribution + */ + + public static final RealizedMinimaR1RateDistribution Standard ( + final R1RateDistribution[] r1RateDistributionArray) + throws Exception + { + if (null == r1RateDistributionArray) + { + throw new Exception ( + "RealizedMinimaR1RateDistribution Constructor => Invalid Input" + ); + } + + double compositeDistributionLambda = 0.; + int exponentialDistributionCount = r1RateDistributionArray.length; + + if (0 == exponentialDistributionCount) + { + return null; + } + + try + { + for (int distributionIndex = 0; + distributionIndex < exponentialDistributionCount; + ++distributionIndex) + { + compositeDistributionLambda += r1RateDistributionArray[distributionIndex].rate(); + } + + return new RealizedMinimaR1RateDistribution ( + r1RateDistributionArray, + compositeDistributionLambda + ); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return null; + } + + private RealizedMinimaR1RateDistribution ( + final R1RateDistribution[] r1RateDistributionArray, + final double compositeDistributionLambda) + throws Exception + { + super ( + compositeDistributionLambda + ); + + _r1RateDistributionArray = r1RateDistributionArray; + } + + /** + * Retrieve the R1 Exponential Distribution Array + * + * @return The R1 Exponential Distribution Array + */ + + public R1RateDistribution[] r1RateDistributionArray() + { + return _r1RateDistributionArray; + } + + /** + * Calculate the Probability that the specified Index corresponds to the Realized Minimum + * + * @param index Specified Index + * + * @return Probability that the specified Index corresponds to the Realized Minimum + * + * @throws Exception Thrown if the Index cannot be calculated + */ + + public double probabilityOfIndexAsMinimum ( + final int index) + throws Exception + { + if (index >= _r1RateDistributionArray.length) + { + throw new Exception ( + "RealizedMinimaR1RateDistribution::probabilityOfIndexAsMinimum => Invalid Index" + ); + } + + return _r1RateDistributionArray[index].rate() / rate(); + } +} diff --git a/src/main/java/org/drip/measure/exponential/TwoIIDSum.java b/src/main/java/org/drip/measure/exponential/TwoIIDSum.java new file mode 100644 index 00000000000..2e017e6b173 --- /dev/null +++ b/src/main/java/org/drip/measure/exponential/TwoIIDSum.java @@ -0,0 +1,308 @@ + +package org.drip.measure.exponential; + +import org.drip.function.definition.R1ToR1; +import org.drip.measure.continuous.R1Univariate; +import org.drip.numerical.integration.NewtonCotesQuadratureGenerator; +import org.drip.numerical.integration.R1ToR1Integrator; + +/* + * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + */ + +/*! + * Copyright (C) 2023 Lakshmi Krishnamurthy + * + * This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics, + * asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment + * analytics, and portfolio construction analytics within and across fixed income, credit, commodity, + * equity, FX, and structured products. It also includes auxiliary libraries for algorithm support, + * numerical analysis, numerical optimization, spline builder, model validation, statistical learning, + * graph builder/navigator, and computational support. + * + * https://lakshmidrip.github.io/DROP/ + * + * DROP is composed of three modules: + * + * - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/ + * - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/ + * - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/ + * + * DROP Product Core implements libraries for the following: + * - Fixed Income Analytics + * - Loan Analytics + * - Transaction Cost Analytics + * + * DROP Portfolio Core implements libraries for the following: + * - Asset Allocation Analytics + * - Asset Liability Management Analytics + * - Capital Estimation Analytics + * - Exposure Analytics + * - Margin Analytics + * - XVA Analytics + * + * DROP Computational Core implements libraries for the following: + * - Algorithm Support + * - Computation Support + * - Function Analysis + * - Graph Algorithm + * - Model Validation + * - Numerical Analysis + * - Numerical Optimizer + * - Spline Builder + * - Statistical Learning + * + * Documentation for DROP is Spread Over: + * + * - Main => https://lakshmidrip.github.io/DROP/ + * - Wiki => https://github.com/lakshmiDRIP/DROP/wiki + * - GitHub => https://github.com/lakshmiDRIP/DROP + * - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md + * - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html + * - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal + * - Release Versions => https://lakshmidrip.github.io/DROP/version.html + * - Community Credits => https://lakshmidrip.github.io/DROP/credits.html + * - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues + * + * 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. + */ + +/** + * TwoIIDSum implements the PDF of the Sum of Two IID Exponential Random Variables. The References + * are: + * + *

+ * + * + *

+ * + * + * @author Lakshmi Krishnamurthy + */ + +public class TwoIIDSum + extends R1Univariate +{ + private static final int QUADRATURE_POINT_COUNT = 100; + + private R1RateDistribution _largerR1RateDistribution = null; + private R1RateDistribution _smallerR1RateDistribution = null; + + /** + * TwoIIDSum Constructor + * + * @param firstR1RateDistribution First R1 Exponential Distribution + * @param secondR1RateDistribution Second R1 Exponential Distribution + * + * @throws Exception Thrown if Inputs are Invalid + */ + + public TwoIIDSum ( + final R1RateDistribution firstR1RateDistribution, + final R1RateDistribution secondR1RateDistribution) + throws Exception + { + if (null == firstR1RateDistribution || null == secondR1RateDistribution) + { + throw new Exception ( + "TwoIIDSum Constructor: Invalid Inputs" + ); + } + + double firstRate = firstR1RateDistribution.rate(); + + double secondRate = secondR1RateDistribution.rate(); + + if (firstRate > secondRate) + { + _largerR1RateDistribution = secondR1RateDistribution; + _smallerR1RateDistribution = firstR1RateDistribution; + } + else + { + _largerR1RateDistribution = firstR1RateDistribution; + _smallerR1RateDistribution = secondR1RateDistribution; + } + } + + /** + * Retrieve the Larger Exponential Distribution + * + * @return The Larger Exponential Distribution + */ + + public R1RateDistribution largerR1RateDistribution() + { + return _largerR1RateDistribution; + } + + /** + * Retrieve the Smaller Exponential Distribution + * + * @return The Smaller Exponential Distribution + */ + + public R1RateDistribution smallerR1RateDistribution() + { + return _smallerR1RateDistribution; + } + + @Override public double[] support() + { + return new double[] + { + 0., + Double.POSITIVE_INFINITY + }; + } + + @Override public double density ( + final double t) + throws Exception + { + if (!supported ( + t + )) + { + throw new Exception ( + "TwoIIDSum::density => Variate not in Range" + ); + } + + double largerRate = _largerR1RateDistribution.rate(); + + double smallerRate = _smallerR1RateDistribution.rate(); + + if (largerRate == smallerRate) + { + return smallerRate * smallerRate * t * Math.exp ( + -1. * smallerRate * t + ); + } + + return smallerRate * largerRate * ( + Math.exp ( + -1. * smallerRate * t + ) - Math.exp ( + -1. * largerRate * t + ) + ) / (largerRate - smallerRate); + } + + @Override public double mean() + throws Exception + { + return NewtonCotesQuadratureGenerator.GaussLaguerreRightDefinite ( + 0., + QUADRATURE_POINT_COUNT + ).integrate ( + new R1ToR1 ( + null + ) + { + @Override public double evaluate ( + final double z) + throws Exception + { + return z * density ( + z + ); + } + } + ); + } + + @Override public double variance() + throws Exception + { + final double mean = mean(); + + return NewtonCotesQuadratureGenerator.GaussLaguerreRightDefinite ( + 0., + QUADRATURE_POINT_COUNT + ).integrate ( + new R1ToR1 ( + null + ) + { + @Override public double evaluate ( + final double z) + throws Exception + { + return (z - mean) * (z - mean) * density ( + z + ); + } + } + ); + } + + @Override public double cumulative ( + final double upper) + throws Exception + { + if (Double.isNaN ( + upper + )) + { + throw new Exception ( + "TwoIIDSum::cumulative => Invalid Upper Variate" + ); + } + + return R1ToR1Integrator.Boole ( + new R1ToR1 ( + null + ) + { + @Override public double evaluate ( + final double z) + throws Exception + { + return density ( + z + ); + } + }, + 0., + upper + ); + } +}