ERFIntegrandG7.java

  1. package org.drip.sample.gausskronrod;

  2. import java.util.Map;

  3. import org.drip.function.definition.R1ToR1;
  4. import org.drip.function.e2erf.BuiltInEntry;
  5. import org.drip.function.e2erf.ErrorFunction;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.numerical.integration.GaussKronrodQuadratureGenerator;
  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>ERFIntegrandG7</i> computes the R<sup>1</sup> Numerical Estimate of the erf Integrand using the G7
  71.  * Gaussian Quadrature Scheme. The References are:
  72.  *
  73.  * <br><br>
  74.  *  <ul>
  75.  *      <li>
  76.  *          Holoborodko, P. (2011): Gauss-Kronrod Quadrature Nodes and Weights
  77.  *              https://www.advanpix.com/2011/11/07/gauss-kronrod-quadrature-nodes-weights/
  78.  *      </li>
  79.  *      <li>
  80.  *          Kahaner, D., C. Moler, and S. Nash (1989): <i>Numerical Methods and Software</i> <b>Prentice
  81.  *              Hall</b>
  82.  *      </li>
  83.  *      <li>
  84.  *          Laurie, D. (1997): Calculation of Gauss-Kronrod Quadrature Rules <i>Mathematics of
  85.  *              Computation</i> <b>66 (219)</b> 1133-1145
  86.  *      </li>
  87.  *      <li>
  88.  *          Piessens, R., E. de Doncker-Kapenga, C. W. Uberhuber, and D. K. Kahaner (1983): <i>QUADPACK – A
  89.  *              Subroutine Package for Automatic Integration</i> <b>Springer-Verlag</b>
  90.  *      </li>
  91.  *      <li>
  92.  *          Wikipedia (2019): Gauss-Kronrod Quadrature Formula
  93.  *              https://en.wikipedia.org/wiki/Gauss%E2%80%93Kronrod_quadrature_formula
  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/sample/README.md">Numerical Analysis</a></li>
  102.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/gausskronrod/README.md">R<sup>1</sup> Gauss-Kronrod Quadrature Schemes</a></li>
  103.  *  </ul>
  104.  *
  105.  * @author Lakshmi Krishnamurthy
  106.  */

  107. public class ERFIntegrandG7
  108. {

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

  114.         R1ToR1 erfIntegrand = new ErrorFunction (
  115.             null,
  116.             null
  117.         ).integrand();

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

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

  120.         System.out.println ("\t|       erf Integrand G7 Estimate      ||");

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

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

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

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

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

  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 = GaussKronrodQuadratureGenerator.G7 (
  132.                 0.,
  133.                 x
  134.             ).integrate (erfIntegrand);

  135.             System.out.println (
  136.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  137.                 FormatUtil.FormatDouble (erfTable, 1, 9, 1.) + " | " +
  138.                 FormatUtil.FormatDouble (erfEstimate, 1, 9, 1.) + " ||"
  139.             );
  140.         }

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

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