KohlrauschFunctionEstimate.java

  1. package org.drip.sample.scaledexponential;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;
  4. import org.drip.specialfunction.definition.ScaledExponentialEstimator;

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

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

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

  104. public class KohlrauschFunctionEstimate
  105. {

  106.     public static final void main (
  107.         final String[] argumentArray)
  108.         throws Exception
  109.     {
  110.         EnvManager.InitEnv ("");

  111.         double[] tArray =
  112.         {
  113.              0.1,
  114.              0.2,
  115.              0.3,
  116.              0.4,
  117.              0.5,
  118.              1.0,
  119.              2.0,
  120.              5.0,
  121.             10.0,
  122.         };
  123.         double[] betaArray =
  124.         {
  125.              0.1,
  126.              0.2,
  127.              0.3,
  128.              0.4,
  129.              0.5,
  130.              0.6,
  131.              0.7,
  132.              0.8,
  133.              0.9,
  134.              1.0,
  135.              1.2,
  136.              1.4,
  137.              1.6,
  138.              1.8,
  139.              2.0,
  140.              2.5,
  141.              3.0,
  142.              3.5,
  143.              4.0,
  144.              4.5,
  145.              5.0,
  146.         };

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

  148.         System.out.println ("\t|                                             SCALED EXPONENTIAL FUNCTION ESTIMATE                                             ||");

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

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

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

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

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

  154.         for (double beta : betaArray)
  155.         {
  156.             ScaledExponentialEstimator scaledExponentialEstimator = new ScaledExponentialEstimator (
  157.                 beta,
  158.                 1.
  159.             );

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

  161.             for (double t : tArray)
  162.             {
  163.                 display = display + " " + FormatUtil.FormatDouble (
  164.                     scaledExponentialEstimator.evaluate (t), 1, 8, 1., false
  165.                 ) + " |";
  166.             }

  167.             System.out.println (display + "|");
  168.         }

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

  170.         EnvManager.TerminateEnv();
  171.     }
  172. }