GFunctionHalfBeta.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>GFunctionHalfBeta</i> compares the Estimates of the "G" Function using Two different Formulas. The
  70.  * 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 GFunctionHalfBeta
  108. {

  109.     public static final void main (
  110.         final String[] argumentArray)
  111.         throws Exception
  112.     {
  113.         EnvManager.InitEnv ("");

  114.         int termCount = 100;
  115.         double[] tArray =
  116.         {
  117.              0.50,
  118.              1.00,
  119.              1.50,
  120.              2.00,
  121.              2.50,
  122.              3.00,
  123.              3.50,
  124.              4.00,
  125.              4.50,
  126.              5.00,
  127.              5.50,
  128.              6.00,
  129.              6.50,
  130.              7.00,
  131.              7.50,
  132.              8.00,
  133.              8.50,
  134.              9.00,
  135.              9.50,
  136.             10.00,
  137.         };

  138.         R1ToR1 gammaEstimator = new NemesAnalytic (null);

  139.         R1ToR1 gFunctionSeries = RelaxationTimeDistributionSeriesEstimator.Standard (
  140.             0.5,
  141.             gammaEstimator,
  142.             termCount
  143.         ).gFunction();

  144.         R1ToR1 gFunctionHalfBeta = RelaxationTimeDistributionEstimator.GFunctionHalfBeta();

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

  146.         System.out.println ("\t|    Beta = 0.5 G FUNCTION COMPARISON    ||");

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

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

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

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

  151.         System.out.println ("\t|            - Half Beta G Estimate      ||");

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

  153.         for (double t : tArray)
  154.         {
  155.             System.out.println (
  156.                 "\t| [" + FormatUtil.FormatDouble (t, 2, 2, 1., false) + "] => " +
  157.                 FormatUtil.FormatDouble (gFunctionSeries.evaluate (t), 1, 10, 1., false) + " | " +
  158.                 FormatUtil.FormatDouble (gFunctionHalfBeta.evaluate (t), 1, 10, 1., false) + " ||"
  159.             );
  160.         }

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

  162.         EnvManager.TerminateEnv();
  163.     }
  164. }