E0ERF.java

  1. package org.drip.sample.erf;

  2. import org.drip.function.enerf.E0ErrorFunction;
  3. import org.drip.function.enerf.GeneralizedErrorFunction;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;

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

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

  66. /**
  67.  * <i>E0ERF</i> illustrates the Estimation of E<sub>0</sub> erf. The References are:
  68.  *
  69.  * <br><br>
  70.  *  <ul>
  71.  *      <li>
  72.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  73.  *              on Mathematics</b>
  74.  *      </li>
  75.  *      <li>
  76.  *          Chang, S. H., P. C. Cosman, L. B. Milstein (2011): Chernoff-Type Bounds for Gaussian Error
  77.  *              Function <i>IEEE Transactions on Communications</i> <b>59 (11)</b> 2939-2944
  78.  *      </li>
  79.  *      <li>
  80.  *          Cody, W. J. (1991): Algorithm 715: SPECFUN – A Portable FORTRAN Package of Special Function
  81.  *              Routines and Test Drivers <i>ACM Transactions on Mathematical Software</i> <b>19 (1)</b>
  82.  *              22-32
  83.  *      </li>
  84.  *      <li>
  85.  *          Schopf, H. M., and P. H. Supancic (2014): On Burmann’s Theorem and its Application to Problems of
  86.  *              Linear and Non-linear Heat Transfer and Diffusion
  87.  *              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/
  88.  *      </li>
  89.  *      <li>
  90.  *          Wikipedia (2019): Error Function https://en.wikipedia.org/wiki/Error_function
  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/feed/README.md">Function</a></li>
  99.  *      <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>
  100.  *  </ul>
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class E0ERF
  105. {

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

  111.         double[] xArray =
  112.         {
  113.             -3.25,
  114.             -3.00,
  115.             -2.75,
  116.             -2.50,
  117.             -2.25,
  118.             -2.00,
  119.             -1.75,
  120.             -1.50,
  121.             -1.25,
  122.             -1.00,
  123.             -0.75,
  124.             -0.50,
  125.             -0.25,
  126.              0.00,
  127.              0.25,
  128.              0.50,
  129.              0.75,
  130.              1.00,
  131.              1.25,
  132.              1.50,
  133.              1.75,
  134.              2.00,
  135.              2.25,
  136.              2.50,
  137.              2.75,
  138.              3.00,
  139.              3.25
  140.         };
  141.         int degree = 0;
  142.         int termCount = 50;

  143.         GeneralizedErrorFunction generalizedErrorFunction = GeneralizedErrorFunction.MacLaurin (
  144.             degree,
  145.             termCount
  146.         );

  147.         E0ErrorFunction e0erfn = new E0ErrorFunction (null);

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

  149.         System.out.println ("\t|      E0 MacLaurin erf Estimate       ||");

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

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

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

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

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

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

  156.         for (double x : xArray)
  157.         {
  158.             System.out.println (
  159.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  160.                 FormatUtil.FormatDouble (generalizedErrorFunction.evaluate (x), 1, 9, 1.) + " | " +
  161.                 FormatUtil.FormatDouble (e0erfn.evaluate (x), 1, 9, 1.) + " ||"
  162.             );
  163.         }

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

  165.         EnvManager.TerminateEnv();
  166.     }
  167. }