diff --git a/ReleaseNotes/12_28_2022.txt b/ReleaseNotes/12_28_2022.txt new file mode 100644 index 00000000000..49b337a6e4f --- /dev/null +++ b/ReleaseNotes/12_28_2022.txt @@ -0,0 +1,39 @@ + +Features: + + - Exponential To R^1 Pareto #1 (1, 2, 3) + - Exponential To R^1 Pareto #2 (4, 5, 6) + - R^1 Exponential To Pareto Shell (9, 10) + - R^1 Exponential To Pareto Normalizer (11, 12) + - R^1 Exponential To Pareto Lambda (13, 14) + - R^1 Exponential To Pareto k (15, 16) + - R^1 Pareto Distribution Normalizer Estimation (17, 18) + - Exponential To R^1 Pareto #3 (19, 20, 21) + - R^1 Exponential To Pareto Constructor (24, 25, 26) + - R^1 Exponential To Pareto Support (27, 28) + - R^1 Exponential To Pareto Density (29, 30) + - Exponential To R^1 Pareto #4 (31, 32, 33) + - R^1 Exponential To Pareto Cumulative (34, 35, 36) + - R^1 Exponential To Pareto Mean #1 (37, 38, 39) + - R^1 Exponential To Pareto Mean #2 (40, 41, 42) + - R^1 Exponential To Pareto Variance #1 (43, 44, 45) + - R^1 Exponential To Pareto Variance #2 (46, 47, 48) + - R^1 Pareto Distribution Run Sweep (52, 53) + + +Bug Fixes/Re-organization: + + - R^1 Gamma To Maxwell Boltzmann Squared (7) + - R^1 Gamma To Exponential (8) + - Trim Pareto Distribution Normalizer (22, 23) + - Rename To R^1 Pareto Distribution (49, 50, 51) + + +Samples: + + - R^1 CDF and PDF #1 (54, 55, 56) + - R^1 CDF and PDF #2 (57, 58) + - R^1 CDF and PDF #3 (59, 60) + + +IdeaDRIP: diff --git a/src/main/java/org/drip/measure/continuous/R1ParetoDistribution.java b/src/main/java/org/drip/measure/continuous/R1ParetoDistribution.java new file mode 100644 index 00000000000..8303b6da1be --- /dev/null +++ b/src/main/java/org/drip/measure/continuous/R1ParetoDistribution.java @@ -0,0 +1,234 @@ + +package org.drip.measure.continuous; + +import org.drip.numerical.common.NumberUtil; + +/* + * -*- 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. + */ + +/** + * R1ParetoDistribution implements the R1 Pareto Distribution. The References are: + * + *

+ * + * + *

+ * + * + * @author Lakshmi Krishnamurthy + */ + +public class R1ParetoDistribution + extends R1Univariate +{ + private double _k = Double.NaN; + private double _lambda = Double.NaN; + + /** + * R1ParetoDistribution Constructor + * + * @param lambda Rate Parameter + * @param k K Parameter + * + * @throws Exception Thrown if the Inputs are invalid + */ + + public R1ParetoDistribution ( + final double lambda, + final double k) + throws Exception + { + if (!NumberUtil.IsValid ( + _lambda = lambda + ) || 0. >= _lambda || !NumberUtil.IsValid ( + _k = k + ) || 0. >= _k + ) + { + throw new Exception ( + "R1ParetoDistribution Constructor => Invalid Inputs" + ); + } + } + + /** + * Retrieve k + * + * @return k + + */ + public double k() + { + return _k; + } + + /** + * Retrieve Lambda + * + * @return Lambda + */ + + public double lambda() + { + return _lambda; + } + + @Override public double[] support() + { + return new double[] + { + _k, + Double.POSITIVE_INFINITY + }; + } + + @Override public double density ( + final double t) + throws Exception + { + if (!supported ( + t + )) + { + throw new Exception ( + "R1ParetoDistribution::density => Variate not in Range" + ); + } + + return _lambda * Math.pow ( + _k, + _lambda + ) * Math.pow ( + t, + -1. - _lambda + ); + } + + @Override public double cumulative ( + final double t) + throws Exception + { + if (!supported ( + t + )) + { + throw new Exception ( + "R1ParetoDistribution::cumulative => Variate not in Range" + ); + } + + return 1. - Math.pow ( + _k / t, + _lambda + ); + } + + @Override public double mean() + throws Exception + { + return _lambda * _k / (1. >= _lambda ? 1. - _lambda : _lambda - 1.); + } + + @Override public double variance() + throws Exception + { + double mean = mean(); + + return _lambda * _k * _k / (2. >= _lambda ? 2. - _lambda : _lambda - 2.) - mean * mean; + } +} diff --git a/src/main/java/org/drip/measure/exponential/R1RateDistribution.java b/src/main/java/org/drip/measure/exponential/R1RateDistribution.java index 714bd7d6f8c..07176176658 100644 --- a/src/main/java/org/drip/measure/exponential/R1RateDistribution.java +++ b/src/main/java/org/drip/measure/exponential/R1RateDistribution.java @@ -156,7 +156,7 @@ public R1RateDistribution ( final double lambda) throws Exception { - if (!NumberUtil.IsValid (_lambda = lambda) || 0. > _lambda) + if (!NumberUtil.IsValid (_lambda = lambda) || 0. >= _lambda) { throw new Exception ("R1RateDistribution Constructor => Invalid lambda"); } diff --git a/src/main/java/org/drip/measure/transform/GammaToR1Exponential.java b/src/main/java/org/drip/measure/transform/R1GammaToExponential.java similarity index 97% rename from src/main/java/org/drip/measure/transform/GammaToR1Exponential.java rename to src/main/java/org/drip/measure/transform/R1GammaToExponential.java index 399d87a520f..d9183f8addf 100644 --- a/src/main/java/org/drip/measure/transform/GammaToR1Exponential.java +++ b/src/main/java/org/drip/measure/transform/R1GammaToExponential.java @@ -82,7 +82,7 @@ */ /** - * GammaToR1Exponential implements the R1 Exponential Distribution in Terms of the + * R1GammaToExponential implements the R1 Exponential Distribution in Terms of the * R1 Gamma Distribution. The References are: * *

@@ -119,12 +119,12 @@ * @author Lakshmi Krishnamurthy */ -public class GammaToR1Exponential +public class R1GammaToExponential extends R1ShapeScaleDistribution { /** - * GammaToR1Exponential Constructor + * R1GammaToExponential Constructor * * @param scaleParameter Scale Parameter * @param gammaEstimator Gamma Estimator @@ -134,7 +134,7 @@ public class GammaToR1Exponential * @throws Exception Thrown if the Inputs are Invalid */ - public GammaToR1Exponential ( + public R1GammaToExponential ( final double scaleParameter, final R1ToR1 gammaEstimator, final R1ToR1 digammaEstimator, diff --git a/src/main/java/org/drip/measure/transform/GammaToMaxwellBoltzmannSquared.java b/src/main/java/org/drip/measure/transform/R1GammaToMaxwellBoltzmannSquared.java similarity index 96% rename from src/main/java/org/drip/measure/transform/GammaToMaxwellBoltzmannSquared.java rename to src/main/java/org/drip/measure/transform/R1GammaToMaxwellBoltzmannSquared.java index 6c0c1419bfe..8926b637e58 100644 --- a/src/main/java/org/drip/measure/transform/GammaToMaxwellBoltzmannSquared.java +++ b/src/main/java/org/drip/measure/transform/R1GammaToMaxwellBoltzmannSquared.java @@ -82,7 +82,7 @@ */ /** - * GammaToMaxwellBoltzmannSquared implements the Maxwell-Boltzmann Squared Distribution using the + * R1GammaToMaxwellBoltzmannSquared implements the Maxwell-Boltzmann Squared Distribution using the * R1 Gamma Distribution. The References are: * *

@@ -119,13 +119,13 @@ * @author Lakshmi Krishnamurthy */ -public class GammaToMaxwellBoltzmannSquared +public class R1GammaToMaxwellBoltzmannSquared extends R1ShapeScaleDistribution { private double _a = Double.NaN; /** - * GammaToMaxwellBoltzmannSquared Constructor + * R1GammaToMaxwellBoltzmannSquared Constructor * * @param a "A" Parameter * @param gammaEstimator Gamma Estimator @@ -135,7 +135,7 @@ public class GammaToMaxwellBoltzmannSquared * @throws java.lang.Exception Thrown if the Inputs are Invalid */ - public GammaToMaxwellBoltzmannSquared ( + public R1GammaToMaxwellBoltzmannSquared ( final double a, final R1ToR1 gammaEstimator, final R1ToR1 digammaEstimator, diff --git a/src/main/java/org/drip/sample/gammadistribution/MaxwellBoltzmannSquaredPDFEstimate.java b/src/main/java/org/drip/sample/gammadistribution/MaxwellBoltzmannSquaredPDFEstimate.java index dc0cf9db095..0afbe82ba8b 100644 --- a/src/main/java/org/drip/sample/gammadistribution/MaxwellBoltzmannSquaredPDFEstimate.java +++ b/src/main/java/org/drip/sample/gammadistribution/MaxwellBoltzmannSquaredPDFEstimate.java @@ -3,7 +3,7 @@ import org.drip.function.definition.R1ToR1; import org.drip.function.definition.R2ToR1; -import org.drip.measure.transform.GammaToMaxwellBoltzmannSquared; +import org.drip.measure.transform.R1GammaToMaxwellBoltzmannSquared; import org.drip.service.common.FormatUtil; import org.drip.service.env.EnvManager; import org.drip.specialfunction.digamma.CumulativeSeriesEstimator; @@ -239,8 +239,8 @@ public static final void main ( for (double a : aArray) { - GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = - new GammaToMaxwellBoltzmannSquared ( + R1GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = + new R1GammaToMaxwellBoltzmannSquared ( a, gammaEstimator, digammaEstimator, @@ -281,8 +281,8 @@ public static final void main ( for (double a : aArray) { - GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = - new GammaToMaxwellBoltzmannSquared ( + R1GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = + new R1GammaToMaxwellBoltzmannSquared ( a, gammaEstimator, digammaEstimator, @@ -321,8 +321,8 @@ public static final void main ( for (double a : aArray) { - GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = - new GammaToMaxwellBoltzmannSquared ( + R1GammaToMaxwellBoltzmannSquared maxwellBoltzmannSquaredDistribution = + new R1GammaToMaxwellBoltzmannSquared ( a, gammaEstimator, digammaEstimator, diff --git a/src/main/java/org/drip/sample/pareto/R1CDFAndPDF.java b/src/main/java/org/drip/sample/pareto/R1CDFAndPDF.java new file mode 100644 index 00000000000..f5f484520ea --- /dev/null +++ b/src/main/java/org/drip/sample/pareto/R1CDFAndPDF.java @@ -0,0 +1,197 @@ + +package org.drip.sample.pareto; + +import org.drip.measure.continuous.R1ParetoDistribution; +import org.drip.measure.exponential.R1RateDistribution; +import org.drip.service.common.FormatUtil; +import org.drip.service.env.EnvManager; + +/* + * -*- 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. + */ + +/** + * R1CDFAndPDF illustrates the Density and CDF Metrics Suite generated from R1 Pareto + * Distribution. The References are: + * + *

+ * + * + *

+ * + * + * @author Lakshmi Krishnamurthy + */ + +public class R1CDFAndPDF +{ + + /** + * Entry Point + * + * @param argumentArray Command Line Argument Array + * + * @throws Exception Thrown on Error/Exception Situation + */ + + public static final void main ( + final String[] argumentArray) + throws Exception + { + EnvManager.InitEnv (""); + + double[] horizonArray = {1./12., 0.25, 0.5, 1., 2., 3., 5., 10.}; + double[] kArray = {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1., 2., 3., 4., 5.}; + double[] lambdaArray = {0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1., 2., 3., 4., 5.}; + + System.out.println ( + "\t||--------------------------------------------------------------------------------------------------------||" + ); + + System.out.println ( + "\t|| Probability Density across Horizon ||" + ); + + System.out.println ( + "\t||--------------------------------------------------------------------------------------------------------||" + ); + + System.out.println ( + "\t|| L -> R:" + ); + + System.out.println ( + "\t|| - Lambda (Left-most Value)" + ); + + System.out.println ( + "\t|| - Probability Density across Time Horizons (Right-most columns)" + ); + + System.out.println ( + "\t||--------------------------------------------------------------------------------------------------------||" + ); + + for (int i = 0; i < lambdaArray.length; ++i) + { + String metricDisplay = "\t|| " + FormatUtil.FormatDouble ( + lambdaArray[i], 1, 2, 1. + ) + " =>"; + + R1ParetoDistribution paretoDistribution = new R1ParetoDistribution (lambdaArray[i], 1.); + + for (int j = 0; j < horizonArray.length; ++j) + { + metricDisplay += " " + FormatUtil.FormatDouble ( + paretoDistribution.density (horizonArray[j]), 1, 6, 1. + ) + " |"; + } + + System.out.println (metricDisplay + "|"); + } + + System.out.println ( + "\t||--------------------------------------------------------------------------------------------------------||" + ); + + System.out.println(); + + System.out.println(); + + EnvManager.TerminateEnv(); + } +} diff --git a/src/main/java/org/drip/sample/pareto/package-info.java b/src/main/java/org/drip/sample/pareto/package-info.java new file mode 100644 index 00000000000..0c04b82f2db --- /dev/null +++ b/src/main/java/org/drip/sample/pareto/package-info.java @@ -0,0 +1,8 @@ + +/** + * R1 Pareto Distribution Run Sweep + * + * @author Lakshmi Krishnamurthy + */ + +package org.drip.sample.pareto;