GFunctionEstimate.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.gamma.NemesAnalytic;
  6. import org.drip.specialfunction.scaledexponential.RelaxationTimeDistributionSeriesEstimator;

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

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

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

  106. public class GFunctionEstimate
  107. {

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

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

  123.             for (double t : tArray)
  124.             {
  125.                 display = display + " " + FormatUtil.FormatDouble (
  126.                     gFunction.evaluate (t), 1, 8, 1., false
  127.                 ) + " |";
  128.             }

  129.             System.out.println (display + "|");
  130.         }
  131.     }

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

  137.         double[] tArray =
  138.         {
  139.              0.25,
  140.              0.50,
  141.              0.75,
  142.              1.00,
  143.              1.25,
  144.              1.50,
  145.              1.75,
  146.              2.00,
  147.              2.25,
  148.         };
  149.         double[] betaArray =
  150.         {
  151.              0.1,
  152.              0.2,
  153.              0.3,
  154.              0.4,
  155.              0.5,
  156.              0.6,
  157.              0.7,
  158.              0.8,
  159.              0.9,
  160.         };
  161.         int[] termCountArray =
  162.         {
  163.             100,
  164.         };

  165.         R1ToR1 gammaEstimator = new NemesAnalytic (null);

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

  167.         System.out.println ("\t|                                                     G FUNCTION ESTIMATOR                                                     ||");

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

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

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

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

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

  173.         for (int termCount : termCountArray)
  174.         {
  175.             G (
  176.                 gammaEstimator,
  177.                 tArray,
  178.                 betaArray,
  179.                 termCount
  180.             );
  181.         }

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

  183.         EnvManager.TerminateEnv();
  184.     }
  185. }