ERFWinitzki2008b.java

  1. package org.drip.sample.erf;

  2. import java.util.Map;

  3. import org.drip.function.e2erf.BuiltInEntry;
  4. import org.drip.function.e2erf.AbramowitzStegun;
  5. import org.drip.function.e2erf.ErrorFunctionAnalytical;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;

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

  107. public class ERFWinitzki2008b
  108. {

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

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

  115.         AbramowitzStegun erfWinitzki = ErrorFunctionAnalytical.Winitzki2008b();

  116.         double maximumError = erfWinitzki.maximumError();

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

  118.         System.out.println ("\t|                      erfWinitzki erf 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|                - Winitzki Estimate                                 ||");

  124.         System.out.println ("\t|                - Winitzki Error                                    ||");

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

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

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

  130.             double erfTable = builtInTableEntry.getValue().erf();

  131.             double erfEstimate = erfWinitzki.evaluate (x);

  132.             System.out.println (
  133.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  134.                 FormatUtil.FormatDouble (erfTable, 1, 9, 1.) + " | " +
  135.                 FormatUtil.FormatDouble (erfEstimate, 1, 9, 1.) + " | " +
  136.                 FormatUtil.FormatDouble (Math.abs (erfEstimate - erfTable), 1, 9, 1.) + " | " +
  137.                 FormatUtil.FormatDouble (maximumError, 1, 9, 1.) + " ||"
  138.             );
  139.         }

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

  141.         EnvManager.TerminateEnv();
  142.     }
  143. }