ERFCInverseFactorialExpansion.java

  1. package org.drip.sample.erfx;

  2. import java.util.Map;

  3. import org.drip.function.e2erf.BuiltInEntry;
  4. import org.drip.function.e2erfc.ErrorFunctionComplement;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.service.env.EnvManager;

  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>ERFCInverseFactorialExpansion</i> illustrates the Error Function Complement Estimation based on the
  69.  * Inverse Factorial Expansion Error Function Complement Series. The References are:
  70.  *
  71.  * <br><br>
  72.  *  <ul>
  73.  *      <li>
  74.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  75.  *              on Mathematics</b>
  76.  *      </li>
  77.  *      <li>
  78.  *          Chang, S. H., P. C. Cosman, L. B. Milstein (2011): Chernoff-Type Bounds for Gaussian Error
  79.  *              Function <i>IEEE Transactions on Communications</i> <b>59 (11)</b> 2939-2944
  80.  *      </li>
  81.  *      <li>
  82.  *          Cody, W. J. (1991): Algorithm 715: SPECFUN – A Portable FORTRAN Package of Special Function
  83.  *              Routines and Test Drivers <i>ACM Transactions on Mathematical Software</i> <b>19 (1)</b>
  84.  *              22-32
  85.  *      </li>
  86.  *      <li>
  87.  *          Schopf, H. M., and P. H. Supancic (2014): On Burmann’s Theorem and its Application to Problems of
  88.  *              Linear and Non-linear Heat Transfer and Diffusion
  89.  *              https://www.mathematica-journal.com/2014/11/on-burmanns-theorem-and-its-application-to-problems-of-linear-and-nonlinear-heat-transfer-and-diffusion/#more-39602/
  90.  *      </li>
  91.  *      <li>
  92.  *          Wikipedia (2019): Error Function https://en.wikipedia.org/wiki/Error_function
  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/feed/README.md">Function</a></li>
  101.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/feed/erfx/README.md">E<sup>2</sup> erfc and erfi Estimation</a></li>
  102.  *  </ul>
  103.  *
  104.  * @author Lakshmi Krishnamurthy
  105.  */

  106. public class ERFCInverseFactorialExpansion
  107. {

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

  113.         Map<Double, BuiltInEntry> builtInTable = BuiltInEntry.Table();

  114.         int termCount = 70;

  115.         ErrorFunctionComplement erfInverseFactorial = ErrorFunctionComplement.InverseFactorialExpansion
  116.             (termCount);

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

  118.         System.out.println ("\t|      Inverse Factorial Expansion erfc Estimate      ||");

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

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

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

  122.         System.out.println ("\t|                - Built-in Estimate                  ||");

  123.         System.out.println ("\t|                - Inverse Factorial Estimate         ||");

  124.         System.out.println ("\t|                - Inverse Factorial Estimate Error   ||");

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

  126.         for (Map.Entry<Double, BuiltInEntry> builtInTableEntry : builtInTable.entrySet())
  127.         {
  128.             double x = builtInTableEntry.getKey();

  129.             double erfcTable = builtInTableEntry.getValue().erfc();

  130.             double erfcEstimate = erfInverseFactorial.evaluate (x);

  131.             System.out.println (
  132.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  133.                 FormatUtil.FormatDouble (erfcTable, 1, 9, 1.) + " | " +
  134.                 FormatUtil.FormatDouble (erfcEstimate, 1, 9, 1.) + " | " +
  135.                 FormatUtil.FormatDouble (Math.abs (erfcEstimate - erfcTable), 1, 9, 1.) + " ||"
  136.             );
  137.         }

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

  139.         EnvManager.TerminateEnv();
  140.     }
  141. }