Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
Bug Fixes/Re-organization:

	- Pareto R^1 PDF and CDF (45)
	- Pareto R^1 Distribution - Mean Exception (58)
	- Pareto R^1 Distribution - Variance Exception (59, 60)


Samples:

	- R^1 CDF and PDF #1 (1, 2, 3)
	- R^1 CDF and PDF #2 (4, 5, 6)
	- R^1 CDF and PDF #3 (7, 8, 9)
	- R^1 CDF and PDF #4 (10, 11, 12)
	- R^1 Pareto Quantile Variates #1 (13, 14, 15)
	- R^1 Pareto Quantile Variates #2 (16, 17, 18)
	- R^1 Pareto Quantile Variates #3 (19, 20, 21)
	- R^1 Pareto Quantile Variates #4 (22, 23, 24)
	- R^1 Pareto Quantile Variates #5 (25, 26, 27)
	- R^1 Pareto Quantile Variates #6 (28, 29, 30)
	- R^1 Pareto Quantile Variates #7 (31, 32, 33)
	- R^1 Pareto Quantile Variates #8 (33, 34, 36)
	- R^1 Pareto Quantile Variates #9 (37, 38, 39)
	- R^1 Pareto Quantile Variates #10 (40, 41, 42)
	- R^1 Pareto Quantile Variates #11 (43, 44)
	- R^1 Pareto Distribution Statistics #1 (46, 47, 48)
	- R^1 Pareto Distribution Statistics #2 (49, 50, 51)
	- R^1 Pareto Distribution Statistics #3 (52, 53, 54)
	- R^1 Pareto Distribution Statistics #4 (55, 56, 57)


IdeaDRIP:
  • Loading branch information
Lakshmik committed Aug 17, 2023
1 parent 0d60ad3 commit d81a46a
Show file tree
Hide file tree
Showing 6 changed files with 585 additions and 32 deletions.
34 changes: 34 additions & 0 deletions ReleaseNotes/12_29_2022.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Features:

Bug Fixes/Re-organization:

- Pareto R^1 PDF and CDF (45)
- Pareto R^1 Distribution - Mean Exception (58)
- Pareto R^1 Distribution - Variance Exception (59, 60)


Samples:

- R^1 CDF and PDF #1 (1, 2, 3)
- R^1 CDF and PDF #2 (4, 5, 6)
- R^1 CDF and PDF #3 (7, 8, 9)
- R^1 CDF and PDF #4 (10, 11, 12)
- R^1 Pareto Quantile Variates #1 (13, 14, 15)
- R^1 Pareto Quantile Variates #2 (16, 17, 18)
- R^1 Pareto Quantile Variates #3 (19, 20, 21)
- R^1 Pareto Quantile Variates #4 (22, 23, 24)
- R^1 Pareto Quantile Variates #5 (25, 26, 27)
- R^1 Pareto Quantile Variates #6 (28, 29, 30)
- R^1 Pareto Quantile Variates #7 (31, 32, 33)
- R^1 Pareto Quantile Variates #8 (33, 34, 36)
- R^1 Pareto Quantile Variates #9 (37, 38, 39)
- R^1 Pareto Quantile Variates #10 (40, 41, 42)
- R^1 Pareto Quantile Variates #11 (43, 44)
- R^1 Pareto Distribution Statistics #1 (46, 47, 48)
- R^1 Pareto Distribution Statistics #2 (49, 50, 51)
- R^1 Pareto Distribution Statistics #3 (52, 53, 54)
- R^1 Pareto Distribution Statistics #4 (55, 56, 57)


IdeaDRIP:
Binary file modified ScheduleSheet.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,61 @@ public double lambda()
);
}

@Override public double quantile (
final double p)
throws Exception
{
if (!NumberUtil.IsValid (
p
) || 0. > p || 1. < p
)
{
throw new Exception (
"R1ParetoDistribution::quantile => p is Invalid"
);
}

if (0. == p)
{
return support()[0];
}

if (1. == p)
{
return support()[1];
}

return _k + Math.pow (
1. - p,
-1. * _lambda
);
}

@Override public double mean()
throws Exception
{
return _lambda * _k / (1. >= _lambda ? 1. - _lambda : _lambda - 1.);
if (1. >= _lambda)
{
throw new Exception (
"R1ParetoDistribution::mean => Does not converge for lambda <= 1."
);
}

return _lambda * _k / _lambda - 1.;
}

@Override public double variance()
throws Exception
{
if (1. >= _lambda)
{
throw new Exception (
"R1ParetoDistribution::variance => Does not converge for lambda <= 2."
);
}

double mean = mean();

return _lambda * _k * _k / (2. >= _lambda ? 2. - _lambda : _lambda - 2.) - mean * mean;
return _lambda * _k * _k / (_lambda - 2.) - mean * mean;
}
}
254 changes: 254 additions & 0 deletions src/main/java/org/drip/sample/pareto/R1PDFAndCDF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@

package org.drip.sample.pareto;

import org.drip.measure.continuous.R1ParetoDistribution;
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.
*/

/**
* <i>R1PDFAndCDF</i> illustrates the Density and CDF Metrics Suite generated from R<sup>1</sup> Pareto
* Distribution. The References are:
*
* <br><br>
* <ul>
* <li>
* Devroye, L. (1986): <i>Non-Uniform Random Variate Generation</i> <b>Springer-Verlag</b> New York
* </li>
* <li>
* Exponential Distribution (2019): Exponential Distribution
* https://en.wikipedia.org/wiki/Exponential_distribution
* </li>
* <li>
* Norton, M., V. Khokhlov, and S. Uryasev (2019): Calculating CVaR and bPOE for Common Probability
* Distributions with Application to Portfolio Optimization and Density Estimation <i>Annals of
* Operations Research</i> <b>299 (1-2)</b> 1281-1315
* </li>
* <li>
* Ross, S. M. (2009): <i>Introduction to Probability and Statistics for Engineers and Scientists
* 4<sup>th</sup> Edition</i> <b>Associated Press</b> New York, NY
* </li>
* <li>
* Schmidt, D. F., and D. Makalic (2009): Universal Models for the Exponential Distribution <i>IEEE
* Transactions on Information Theory</i> <b>55 (7)</b> 3087-3090
* </li>
* </ul>
*
* <br><br>
* <ul>
* <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
* <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
* <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure/README.md">R<sup>d</sup> Continuous/Discrete Probability Measures</a></li>
* <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/measure/exponential/README.md">R<sup>1</sup> Exponential Distribution Implementation/Properties</a></li>
* </ul>
*
* @author Lakshmi Krishnamurthy
*/

public class R1PDFAndCDF
{

/**
* 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, k] (Left-most Values)"
);

System.out.println (
"\t|| - Probability Density across Time Horizons (Right-most columns)"
);

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

for (int i = 0; i < kArray.length; ++i)
{
for (int j = 0; j < lambdaArray.length; ++j)
{
String metricDisplay = "\t|| [" + FormatUtil.FormatDouble (
kArray[i], 1, 2, 1., false
) + ", " +FormatUtil.FormatDouble (
lambdaArray[j], 1, 2, 1., false
) + "] =>";

R1ParetoDistribution paretoDistribution = new R1ParetoDistribution (lambdaArray[j], kArray[i]);

for (int k = 0; k < horizonArray.length; ++k)
{
metricDisplay += " " + FormatUtil.FormatDouble (
paretoDistribution.density (horizonArray[k] + kArray[i]), 1, 6, 1.
) + " |";
}

System.out.println (metricDisplay + "|");
}
}

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

System.out.println();

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

System.out.println (
"\t|| Cumulative Probability across Horizon ||"
);

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

System.out.println (
"\t|| L -> R:"
);

System.out.println (
"\t|| - [Lambda, k] (Left-most Values)"
);

System.out.println (
"\t|| - Probability Density across Time Horizons (Right-most columns)"
);

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

for (int i = 0; i < kArray.length; ++i)
{
for (int j = 0; j < lambdaArray.length; ++j)
{
String metricDisplay = "\t|| [" + FormatUtil.FormatDouble (
kArray[i], 1, 2, 1., false
) + ", " +FormatUtil.FormatDouble (
lambdaArray[j], 1, 2, 1., false
) + "] =>";

R1ParetoDistribution paretoDistribution = new R1ParetoDistribution (lambdaArray[j], kArray[i]);

for (int k = 0; k < horizonArray.length; ++k)
{
metricDisplay += " " + FormatUtil.FormatDouble (
paretoDistribution.cumulative (horizonArray[k] + kArray[i]), 1, 6, 1.
) + " |";
}

System.out.println (metricDisplay + "|");
}
}

System.out.println (
"\t||---------------------------------------------------------------------------------------------------------------||"
);

EnvManager.TerminateEnv();
}
}
Loading

0 comments on commit d81a46a

Please sign in to comment.