ERFCChianiDardariSimon2012a.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.function.e2erfc.ErrorFunctionComplementAnalytical;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.numerical.estimation.R1Estimate;
  8. import org.drip.service.env.EnvManager;

  9. /*
  10.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  11.  */

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

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

  108. public class ERFCChianiDardariSimon2012a
  109. {

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

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

  116.         ErrorFunctionComplement erfChianiDardariSimon2012a =
  117.             ErrorFunctionComplementAnalytical.ChianiDardariSimon2012a();

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

  119.         System.out.println ("\t|                Chiani-Dardari-Simon (2012a) Bounded erfc Estimate                ||");

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

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

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

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

  124.         System.out.println ("\t|                - Chiani-Dardari-Simon Estimate                                   ||");

  125.         System.out.println ("\t|                - Chiani-Dardari-Simon Lower Bound                                ||");

  126.         System.out.println ("\t|                - Chiani-Dardari-Simon Upper Bound                                ||");

  127.         System.out.println ("\t|                - Chiani-Dardari-Simon Error                                      ||");

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

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

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

  133.             R1Estimate erfcEstimate = erfChianiDardariSimon2012a.boundedEstimate (x);

  134.             double baseline = erfcEstimate.baseline();

  135.             System.out.println (
  136.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  137.                 FormatUtil.FormatDouble (erfcTable, 1, 9, 1.) + " | " +
  138.                 FormatUtil.FormatDouble (baseline, 1, 9, 1.) + " | [" +
  139.                 FormatUtil.FormatDouble (erfcEstimate.lowerBound(), 1, 9, 1.) + " -" +
  140.                 FormatUtil.FormatDouble (erfcEstimate.upperBound(), 1, 9, 1.) + " ]" +
  141.                 FormatUtil.FormatDouble (Math.abs (baseline - erfcTable), 1, 9, 1.) + " ||"
  142.             );
  143.         }

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

  145.         EnvManager.TerminateEnv();
  146.     }
  147. }