ERFIntegrandG7K15.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.numerical.integration.QuadratureEstimate;
  9. import org.drip.service.env.EnvManager;

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

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

  70. /**
  71.  * <i>ERFIntegrandG7K15</i> computes the R<sup>1</sup> Nested Numerical Estimate and Error of the erf
  72.  * Integrand using the G7-K15 Gaussian Integration Quadrature Scheme. The References are:
  73.  *
  74.  * <br><br>
  75.  *  <ul>
  76.  *      <li>
  77.  *          Holoborodko, P. (2011): Gauss-Kronrod Quadrature Nodes and Weights
  78.  *              https://www.advanpix.com/2011/11/07/gauss-kronrod-quadrature-nodes-weights/
  79.  *      </li>
  80.  *      <li>
  81.  *          Kahaner, D., C. Moler, and S. Nash (1989): <i>Numerical Methods and Software</i> <b>Prentice
  82.  *              Hall</b>
  83.  *      </li>
  84.  *      <li>
  85.  *          Laurie, D. (1997): Calculation of Gauss-Kronrod Quadrature Rules <i>Mathematics of
  86.  *              Computation</i> <b>66 (219)</b> 1133-1145
  87.  *      </li>
  88.  *      <li>
  89.  *          Piessens, R., E. de Doncker-Kapenga, C. W. Uberhuber, and D. K. Kahaner (1983): <i>QUADPACK – A
  90.  *              Subroutine Package for Automatic Integration</i> <b>Springer-Verlag</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Wikipedia (2019): Gauss-Kronrod Quadrature Formula
  94.  *              https://en.wikipedia.org/wiki/Gauss%E2%80%93Kronrod_quadrature_formula
  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/sample/README.md">Numerical Analysis</a></li>
  103.  *      <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>
  104.  *  </ul>
  105.  *
  106.  * @author Lakshmi Krishnamurthy
  107.  */

  108. public class ERFIntegrandG7K15
  109. {

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

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

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

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

  121.         System.out.println ("\t|            erf Integrand G7-K15 Estimate            ||");

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

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

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

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

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

  127.         System.out.println ("\t|                - Estimation Error                   ||");

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

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

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

  133.             QuadratureEstimate quadratureEstimate = GaussKronrodQuadratureGenerator.G7K15 (
  134.                 0.,
  135.                 x
  136.             ).estimate (erfIntegrand);

  137.             System.out.println (
  138.                 "\t| " + FormatUtil.FormatDouble (x, 1, 2, 1.) + " => " +
  139.                 FormatUtil.FormatDouble (erfTable, 1, 9, 1.) + " | " +
  140.                 FormatUtil.FormatDouble (quadratureEstimate.baseline(), 1, 9, 1.) + " | " +
  141.                 FormatUtil.FormatDouble (quadratureEstimate.error(), 1, 9, 1.) + " ||"
  142.             );
  143.         }

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

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