RelaxationTimeDistributionEstimate.java

  1. package org.drip.sample.scaledexponential;

  2. import org.drip.function.definition.R1ToR1;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.specialfunction.definition.RelaxationTimeDistributionEstimator;
  6. import org.drip.specialfunction.gamma.NemesAnalytic;
  7. import org.drip.specialfunction.scaledexponential.RelaxationTimeDistributionSeriesEstimator;

  8. /*
  9.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  10.  */

  11. /*!
  12.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DROP, an open-source library targeting risk, transaction costs, exposure, margin
  15.  *      calculations, and portfolio construction within and across fixed income, credit, commodity, equity,
  16.  *      FX, and structured products.
  17.  *  
  18.  *      https://lakshmidrip.github.io/DROP/
  19.  *  
  20.  *  DROP is composed of three main modules:
  21.  *  
  22.  *  - DROP Analytics Core - https://lakshmidrip.github.io/DROP-Analytics-Core/
  23.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  24.  *  - DROP Numerical Core - https://lakshmidrip.github.io/DROP-Numerical-Core/
  25.  *
  26.  *  DROP Analytics Core implements libraries for the following:
  27.  *  - Fixed Income Analytics
  28.  *  - Asset Backed Analytics
  29.  *  - XVA Analytics
  30.  *  - Exposure and Margin Analytics
  31.  *
  32.  *  DROP Portfolio Core implements libraries for the following:
  33.  *  - Asset Allocation Analytics
  34.  *  - Transaction Cost Analytics
  35.  *
  36.  *  DROP Numerical Core implements libraries for the following:
  37.  *  - Statistical Learning Library
  38.  *  - Numerical Optimizer Library
  39.  *  - Machine Learning Library
  40.  *  - Spline Builder Library
  41.  *
  42.  *  Documentation for DROP is Spread Over:
  43.  *
  44.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  45.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  46.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  47.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  48.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  49.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  50.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  51.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  52.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  53.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  54.  *
  55.  *  Licensed under the Apache License, Version 2.0 (the "License");
  56.  *      you may not use this file except in compliance with the License.
  57.  *  
  58.  *  You may obtain a copy of the License at
  59.  *      http://www.apache.org/licenses/LICENSE-2.0
  60.  *  
  61.  *  Unless required by applicable law or agreed to in writing, software
  62.  *      distributed under the License is distributed on an "AS IS" BASIS,
  63.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  64.  *  
  65.  *  See the License for the specific language governing permissions and
  66.  *      limitations under the License.
  67.  */

  68. /**
  69.  * <i>RelaxationTimeDistributionEstimate</i> illustrates the Series-based Estimate for the Relaxation Time
  70.  * Distribution Function. The References are:
  71.  *
  72.  * <br><br>
  73.  *  <ul>
  74.  *      <li>
  75.  *          Gradshteyn, I. S., I. M. Ryzhik, Y. V. Geronimus, M. Y. Tseytlin, and A. Jeffrey (2015):
  76.  *              <i>Tables of Integrals, Series, and Products</i> <b>Academic Press</b>
  77.  *      </li>
  78.  *      <li>
  79.  *          Hilfer, J. (2002): H-function Representations for Stretched Exponential Relaxation and non-Debye
  80.  *              Susceptibilities in Glassy Systems <i>Physical Review E</i> <b>65 (6)</b> 061510
  81.  *      </li>
  82.  *      <li>
  83.  *          Wikipedia (2019): Stretched Exponential Function
  84.  *              https://en.wikipedia.org/wiki/Stretched_exponential_function
  85.  *      </li>
  86.  *      <li>
  87.  *          Wuttke, J. (2012): Laplace-Fourier Transform of the Stretched Exponential Function: Analytic
  88.  *              Error-Bounds, Double Exponential Transform, and Open Source Implementation <i>libkw</i>
  89.  *              <i>Algorithm</i> <b>5 (4)</b> 604-628
  90.  *      </li>
  91.  *      <li>
  92.  *          Zorn, R. (2002): Logarithmic Moments of Relaxation Time Distributions <i>Journal of Chemical
  93.  *              Physics</i> <b>116 (8)</b> 3204-3209
  94.  *      </li>
  95.  *  </ul>
  96.  *
  97.  *  <br><br>
  98.  *  <ul>
  99.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalCore.md">Numerical Core Module</a></li>
  100.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalOptimizerLibrary.md">Numerical Optimizer</a></li>
  101.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/README.md">Special Function Project</a></li>
  102.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/specialfunction/ode/README.md">Special Function Ordinary Differential Equations</a></li>
  103.  *  </ul>
  104.  *
  105.  * @author Lakshmi Krishnamurthy
  106.  */

  107. public class RelaxationTimeDistributionEstimate
  108. {

  109.     private static final void RelaxationTimeDensity (
  110.         final R1ToR1 gammaEstimator,
  111.         final double[] tArray,
  112.         final double[] betaArray,
  113.         final int termCount)
  114.         throws Exception
  115.     {
  116.         for (double beta : betaArray)
  117.         {
  118.             RelaxationTimeDistributionEstimator relaxationTimeDistributionEstimator =
  119.                 RelaxationTimeDistributionSeriesEstimator.Standard (
  120.                     beta,
  121.                     gammaEstimator,
  122.                     termCount
  123.                 );

  124.             String display = "\t| [" + FormatUtil.FormatDouble (beta, 1, 1, 1., false) + "] => ";

  125.             for (double t : tArray)
  126.             {
  127.                 display = display + " " + FormatUtil.FormatDouble (
  128.                     relaxationTimeDistributionEstimator.relaxationTimeDensity (t), 1, 8, 1., false
  129.                 ) + " |";
  130.             }

  131.             System.out.println (display + "|");
  132.         }
  133.     }

  134.     public static final void main (
  135.         final String[] argumentArray)
  136.         throws Exception
  137.     {
  138.         EnvManager.InitEnv ("");

  139.         double[] tArray =
  140.         {
  141.              0.1,
  142.              0.2,
  143.              0.3,
  144.              0.4,
  145.              0.5,
  146.              1.0,
  147.              2.0,
  148.              5.0,
  149.             10.0,
  150.         };
  151.         double[] betaArray =
  152.         {
  153.              0.1,
  154.              0.2,
  155.              0.3,
  156.              0.4,
  157.              0.5,
  158.              0.6,
  159.              0.7,
  160.              0.8,
  161.              0.9,
  162.              1.0,
  163.         };
  164.         int[] termCountArray =
  165.         {
  166.             100,
  167.         };

  168.         R1ToR1 gammaEstimator = new NemesAnalytic (null);

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

  170.         System.out.println ("\t|                                                 KOHLRAUSCH MOMENT ESTIMATOR                                                  ||");

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

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

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

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

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

  176.         for (int termCount : termCountArray)
  177.         {
  178.             RelaxationTimeDensity (
  179.                 gammaEstimator,
  180.                 tArray,
  181.                 betaArray,
  182.                 termCount
  183.             );
  184.         }

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

  186.         EnvManager.TerminateEnv();
  187.     }
  188. }