GaussKronrodQuadratureGenerator.java

  1. package org.drip.numerical.integration;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  *
  9.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  10.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  11.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  12.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  13.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  14.  *      and computational support.
  15.  *  
  16.  *      https://lakshmidrip.github.io/DROP/
  17.  *  
  18.  *  DROP is composed of three modules:
  19.  *  
  20.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  21.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  22.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  23.  *
  24.  *  DROP Product Core implements libraries for the following:
  25.  *  - Fixed Income Analytics
  26.  *  - Loan Analytics
  27.  *  - Transaction Cost Analytics
  28.  *
  29.  *  DROP Portfolio Core implements libraries for the following:
  30.  *  - Asset Allocation Analytics
  31.  *  - Asset Liability Management Analytics
  32.  *  - Capital Estimation Analytics
  33.  *  - Exposure Analytics
  34.  *  - Margin Analytics
  35.  *  - XVA Analytics
  36.  *
  37.  *  DROP Computational Core implements libraries for the following:
  38.  *  - Algorithm Support
  39.  *  - Computation Support
  40.  *  - Function Analysis
  41.  *  - Model Validation
  42.  *  - Numerical Analysis
  43.  *  - Numerical Optimizer
  44.  *  - Spline Builder
  45.  *  - Statistical Learning
  46.  *
  47.  *  Documentation for DROP is Spread Over:
  48.  *
  49.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  50.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  51.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  52.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  53.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  54.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  55.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  56.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  57.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  58.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  59.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  60.  *
  61.  *  Licensed under the Apache License, Version 2.0 (the "License");
  62.  *      you may not use this file except in compliance with the License.
  63.  *  
  64.  *  You may obtain a copy of the License at
  65.  *      http://www.apache.org/licenses/LICENSE-2.0
  66.  *  
  67.  *  Unless required by applicable law or agreed to in writing, software
  68.  *      distributed under the License is distributed on an "AS IS" BASIS,
  69.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  70.  *  
  71.  *  See the License for the specific language governing permissions and
  72.  *      limitations under the License.
  73.  */

  74. /**
  75.  * <i>GaussKronrodQuadratureGenerator</i> generates the Array of Gaussian Quadrature Based Abscissa and their
  76.  * corresponding Weights, with the Kronrod Extensions applied. The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Holoborodko, P. (2011): Gauss-Kronrod Quadrature Nodes and Weights
  82.  *              https://www.advanpix.com/2011/11/07/gauss-kronrod-quadrature-nodes-weights/
  83.  *      </li>
  84.  *      <li>
  85.  *          Kahaner, D., C. Moler, and S. Nash (1989): <i>Numerical Methods and Software</i> <b>Prentice
  86.  *              Hall</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Laurie, D. (1997): Calculation of Gauss-Kronrod Quadrature Rules <i>Mathematics of
  90.  *              Computation</i> <b>66 (219)</b> 1133-1145
  91.  *      </li>
  92.  *      <li>
  93.  *          Piessens, R., E. de Doncker-Kapenga, C. W. Uberhuber, and D. K. Kahaner (1983): <i>QUADPACK – A
  94.  *              Subroutine Package for Automatic Integration</i> <b>Springer-Verlag</b>
  95.  *      </li>
  96.  *      <li>
  97.  *          Wikipedia (2019): Gauss-Kronrod Quadrature Formula
  98.  *              https://en.wikipedia.org/wiki/Gauss%E2%80%93Kronrod_quadrature_formula
  99.  *      </li>
  100.  *  </ul>
  101.  *
  102.  *  <br><br>
  103.  *  <ul>
  104.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  105.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  106.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/numerical/README.md">Numerical Quadrature, Differentiation, Eigenization, Linear Algebra, and Utilities</a></li>
  107.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/numerical/integration/README.md">R<sup>1</sup> R<sup>d</sup> Numerical Integration Schemes</a></li>
  108.  *  </ul>
  109.  *
  110.  * @author Lakshmi Krishnamurthy
  111.  */

  112. public class GaussKronrodQuadratureGenerator
  113. {

  114.     /**
  115.      * Generate the Nested/Embedded G7 Gaussian Quadrature over (0, +1)
  116.      *
  117.      * @param abscissaTransformer The Abscissa Transformer
  118.      *
  119.      * @return The Nested/Embedded G7 Gaussian Quadrature over (0, +1)
  120.      */

  121.     public static final org.drip.numerical.integration.QuadratureEstimator G7 (
  122.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  123.     {
  124.         try
  125.         {
  126.             return new org.drip.numerical.integration.QuadratureEstimator (
  127.                 abscissaTransformer,
  128.                 org.drip.numerical.common.Array2D.FromArray (
  129.                     new double[]
  130.                     {
  131.                         -0.949107912342759,
  132.                         -0.741531185599394,
  133.                         -0.405845151377397,
  134.                          0.000000000000000,
  135.                          0.405845151377397,
  136.                          0.741531185599394,
  137.                          0.949107912342759,
  138.                     },
  139.                     new double[]
  140.                     {
  141.                         0.129484966168870,
  142.                         0.279705391489277,
  143.                         0.381830050505119,
  144.                         0.417959183673469,
  145.                         0.381830050505119,
  146.                         0.279705391489277,
  147.                         0.129484966168870,
  148.                     }
  149.                 )
  150.             );
  151.         }
  152.         catch (java.lang.Exception e)
  153.         {
  154.             e.printStackTrace();
  155.         }

  156.         return null;
  157.     }

  158.     /**
  159.      * Generate the K15 Gaussian Quadrature over (0, +1)
  160.      *
  161.      * @param abscissaTransformer The Abscissa Transformer
  162.      *
  163.      * @return The K15 Gaussian Quadrature over (0, +1)
  164.      */

  165.     public static final org.drip.numerical.integration.QuadratureEstimator K15 (
  166.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  167.     {
  168.         try
  169.         {
  170.             return new org.drip.numerical.integration.QuadratureEstimator (
  171.                 abscissaTransformer,
  172.                 org.drip.numerical.common.Array2D.FromArray (
  173.                     new double[]
  174.                     {
  175.                         -0.991455371120813,
  176.                         -0.949107912342759,
  177.                         -0.864864423359769,
  178.                         -0.741531185599394,
  179.                         -0.586087235467691,
  180.                         -0.405845151377397,
  181.                         -0.207784955007898,
  182.                          0.000000000000000,
  183.                          0.207784955007898,
  184.                          0.405845151377397,
  185.                          0.586087235467691,
  186.                          0.741531185599394,
  187.                          0.864864423359769,
  188.                          0.949107912342759,
  189.                          0.991455371120813,
  190.                     },
  191.                     new double[]
  192.                     {
  193.                         0.022935322010529,
  194.                         0.063092092629979,
  195.                         0.104790010322250,
  196.                         0.140653259715525,
  197.                         0.169004726639267,
  198.                         0.190350578064785,
  199.                         0.204432940075298,
  200.                         0.209482141084728,
  201.                         0.204432940075298,
  202.                         0.190350578064785,
  203.                         0.169004726639267,
  204.                         0.140653259715525,
  205.                         0.104790010322250,
  206.                         0.063092092629979,
  207.                         0.022935322010529,
  208.                     }
  209.                 )
  210.             );
  211.         }
  212.         catch (java.lang.Exception e)
  213.         {
  214.             e.printStackTrace();
  215.         }

  216.         return null;
  217.     }

  218.     /**
  219.      * Generate the Nested/Embedded G7 Gaussian Quadrature over (a, b) onto (-1, +1)
  220.      *
  221.      * @param left Left Integrand Quadrature Limit
  222.      * @param right Right Integrand Quadrature Limit
  223.      *
  224.      * @return The Nested/Embedded G7 Gaussian Quadrature over (a, b) onto (-1, +1)
  225.      */

  226.     public static final org.drip.numerical.integration.QuadratureEstimator G7 (
  227.         final double left,
  228.         final double right)
  229.     {
  230.         return G7 (
  231.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  232.                 left,
  233.                 right
  234.             )
  235.         );
  236.     }

  237.     /**
  238.      * Generate the K15 Gaussian Quadrature over (a, b) onto (-1, +1)
  239.      *
  240.      * @param left Left Integrand Quadrature Limit
  241.      * @param right Right Integrand Quadrature Limit
  242.      *
  243.      * @return The K15 Gaussian Quadrature over (a, b) onto (-1, +1)
  244.      */

  245.     public static final org.drip.numerical.integration.QuadratureEstimator K15 (
  246.         final double left,
  247.         final double right)
  248.     {
  249.         return K15 (
  250.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  251.                 left,
  252.                 right
  253.             )
  254.         );
  255.     }

  256.     /**
  257.      * Generate the G7-K15 Nested Quadrature Estimator over (a, b) onto (-1, +1)
  258.      *
  259.      * @param left Left Integrand Quadrature Limit
  260.      * @param right Right Integrand Quadrature Limit
  261.      *
  262.      * @return The G7-K15 Nested Quadrature Estimator over (a, b) onto (-1, +1)
  263.      */

  264.     public static final org.drip.numerical.integration.NestedQuadratureEstimator G7K15 (
  265.         final double left,
  266.         final double right)
  267.     {
  268.         try
  269.         {
  270.             return new org.drip.numerical.integration.NestedQuadratureEstimator (
  271.                 org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  272.                     left,
  273.                     right
  274.                 ),
  275.                 org.drip.numerical.common.Array2D.FromArray (
  276.                     new double[]
  277.                     {
  278.                         -0.991455371120813,
  279.                         -0.949107912342759,
  280.                         -0.864864423359769,
  281.                         -0.741531185599394,
  282.                         -0.586087235467691,
  283.                         -0.405845151377397,
  284.                         -0.207784955007898,
  285.                          0.000000000000000,
  286.                          0.207784955007898,
  287.                          0.405845151377397,
  288.                          0.586087235467691,
  289.                          0.741531185599394,
  290.                          0.864864423359769,
  291.                          0.949107912342759,
  292.                          0.991455371120813,
  293.                     },
  294.                     new double[]
  295.                     {
  296.                         0.022935322010529,
  297.                         0.063092092629979,
  298.                         0.104790010322250,
  299.                         0.140653259715525,
  300.                         0.169004726639267,
  301.                         0.190350578064785,
  302.                         0.204432940075298,
  303.                         0.209482141084728,
  304.                         0.204432940075298,
  305.                         0.190350578064785,
  306.                         0.169004726639267,
  307.                         0.140653259715525,
  308.                         0.104790010322250,
  309.                         0.063092092629979,
  310.                         0.022935322010529,
  311.                     }
  312.                 ),
  313.                 G7 (
  314.                     left,
  315.                     right
  316.                 )
  317.             );
  318.         }
  319.         catch (java.lang.Exception e)
  320.         {
  321.             e.printStackTrace();
  322.         }

  323.         return null;
  324.     }
  325. }