GaussLobattoQuadratureGenerator.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>GaussLobattoQuadratureGenerator</i> generates the Array of Orthogonal Lobatto Polynomial Gaussian
  76.  * Quadrature Based Abscissa and their corresponding Weights. The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Abramowitz, M., and I. A. Stegun (2007): <i>Handbook of Mathematics Functions</i> <b>Dover Book
  82.  *              on Mathematics</b>
  83.  *      </li>
  84.  *      <li>
  85.  *          Gil, A., J. Segura, and N. M. Temme (2007): <i>Numerical Methods for Special Functions</i>
  86.  *              <b>Society for Industrial and Applied Mathematics</b> Philadelphia
  87.  *      </li>
  88.  *      <li>
  89.  *          Press, W. H., S. A. Teukolsky, W. T. Vetterling, and B. P. Flannery (2007): <i>Numerical Recipes:
  90.  *              The Art of Scientific Computing 3rd Edition</i> <b>Cambridge University Press</b> New York
  91.  *      </li>
  92.  *      <li>
  93.  *          Stoer, J., and R. Bulirsch (2002): <i>Introduction to Numerical Analysis 3rd Edition</i>
  94.  *              <b>Springer</b>
  95.  *      </li>
  96.  *      <li>
  97.  *          Wikipedia (2019): Gaussian Quadrature https://en.wikipedia.org/wiki/Gaussian_quadrature
  98.  *      </li>
  99.  *  </ul>
  100.  *
  101.  *  <br><br>
  102.  *  <ul>
  103.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  104.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
  105.  *      <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>
  106.  *      <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>
  107.  *  </ul>
  108.  *
  109.  * @author Lakshmi Krishnamurthy
  110.  */

  111. public class GaussLobattoQuadratureGenerator
  112. {

  113.     /**
  114.      * Generate the Three Point Gauss Lobatto Quadrature over [-1, +1]
  115.      *
  116.      * @param abscissaTransformer The Abscissa Transformer
  117.      *
  118.      * @return The Three Point Gauss Lobatto Quadrature over [-1, +1]
  119.      */

  120.     public static final org.drip.numerical.integration.QuadratureEstimator ThreePoint (
  121.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  122.     {
  123.         try
  124.         {
  125.             return new org.drip.numerical.integration.QuadratureEstimator (
  126.                 abscissaTransformer,
  127.                 org.drip.numerical.common.Array2D.FromArray (
  128.                     new double[]
  129.                     {
  130.                         -1.000000000000000,
  131.                          0.000000000000000,
  132.                          1.000000000000000,
  133.                     },
  134.                     new double[]
  135.                     {
  136.                         1. / 3.,
  137.                         4. / 3.,
  138.                         1. / 3.,
  139.                     }
  140.                 )
  141.             );
  142.         }
  143.         catch (java.lang.Exception e)
  144.         {
  145.             e.printStackTrace();
  146.         }

  147.         return null;
  148.     }

  149.     /**
  150.      * Generate the Four Point Gauss Lobatto Quadrature over [-1, +1]
  151.      *
  152.      * @param abscissaTransformer The Abscissa Transformer
  153.      *
  154.      * @return The Four Point Gauss Lobatto Quadrature over [-1, +1]
  155.      */

  156.     public static final org.drip.numerical.integration.QuadratureEstimator FourPoint (
  157.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  158.     {
  159.         double sqrt_1Over5_ = java.lang.Math.sqrt (0.2);

  160.         try
  161.         {
  162.             return new org.drip.numerical.integration.QuadratureEstimator (
  163.                 abscissaTransformer,
  164.                 org.drip.numerical.common.Array2D.FromArray (
  165.                     new double[]
  166.                     {
  167.                         -1.000000000000000,
  168.                         -sqrt_1Over5_,
  169.                          sqrt_1Over5_,
  170.                          1.000000000000000,
  171.                     },
  172.                     new double[]
  173.                     {
  174.                         1. / 6.,
  175.                         5. / 6.,
  176.                         5. / 6.,
  177.                         1. / 6.,
  178.                     }
  179.                 )
  180.             );
  181.         }
  182.         catch (java.lang.Exception e)
  183.         {
  184.             e.printStackTrace();
  185.         }

  186.         return null;
  187.     }

  188.     /**
  189.      * Generate the Five Point Gauss Lobatto Quadrature over [-1, +1]
  190.      *
  191.      * @param abscissaTransformer The Abscissa Transformer
  192.      *
  193.      * @return The Five Point Gauss Lobatto Quadrature over [-1, +1]
  194.      */

  195.     public static final org.drip.numerical.integration.QuadratureEstimator FivePoint (
  196.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  197.     {
  198.         double sqrt_3Over7_ = java.lang.Math.sqrt (3. / 7.);

  199.         try
  200.         {
  201.             return new org.drip.numerical.integration.QuadratureEstimator (
  202.                 abscissaTransformer,
  203.                 org.drip.numerical.common.Array2D.FromArray (
  204.                     new double[]
  205.                     {
  206.                         -1.000000000000000,
  207.                         -sqrt_3Over7_,
  208.                          0.000000000000000,
  209.                          sqrt_3Over7_,
  210.                          1.000000000000000,
  211.                     },
  212.                     new double[]
  213.                     {
  214.                          1. / 10.,
  215.                         49. / 90.,
  216.                         32. / 45.,
  217.                         49. / 90.,
  218.                          1. / 10.,
  219.                     }
  220.                 )
  221.             );
  222.         }
  223.         catch (java.lang.Exception e)
  224.         {
  225.             e.printStackTrace();
  226.         }

  227.         return null;
  228.     }

  229.     /**
  230.      * Generate the Six Point Gauss Lobatto Quadrature over [-1, +1]
  231.      *
  232.      * @param abscissaTransformer The Abscissa Transformer
  233.      *
  234.      * @return The Six Point Gauss Lobatto Quadrature over [-1, +1]
  235.      */

  236.     public static final org.drip.numerical.integration.QuadratureEstimator SixPoint (
  237.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  238.     {
  239.         double sqrt7 = java.lang.Math.sqrt (7.);

  240.         double twoSqrt_7_Over21 = 2. / 21. * sqrt7;
  241.         double nearWeight = (14. + sqrt7) / 30.;
  242.         double farWeight = (14. - sqrt7) / 30.;

  243.         double farNode = java.lang.Math.sqrt ((1. / 3.) + twoSqrt_7_Over21);

  244.         double nearNode = java.lang.Math.sqrt ((1. / 3.) - twoSqrt_7_Over21);

  245.         try
  246.         {
  247.             return new org.drip.numerical.integration.QuadratureEstimator (
  248.                 abscissaTransformer,
  249.                 org.drip.numerical.common.Array2D.FromArray (
  250.                     new double[]
  251.                     {
  252.                         -1.000000000000000,
  253.                         -farNode,
  254.                         -nearNode,
  255.                          nearNode,
  256.                          farNode,
  257.                          1.000000000000000,
  258.                     },
  259.                     new double[]
  260.                     {
  261.                         1. / 15.,
  262.                         farWeight,
  263.                         nearWeight,
  264.                         nearWeight,
  265.                         farWeight,
  266.                         1. / 15.,
  267.                     }
  268.                 )
  269.             );
  270.         }
  271.         catch (java.lang.Exception e)
  272.         {
  273.             e.printStackTrace();
  274.         }

  275.         return null;
  276.     }

  277.     /**
  278.      * Generate the Seven Point Gauss Lobatto Quadrature over [-1, +1]
  279.      *
  280.      * @param abscissaTransformer The Abscissa Transformer
  281.      *
  282.      * @return The Seven Point Gauss Lobatto Quadrature over [-1, +1]
  283.      */

  284.     public static final org.drip.numerical.integration.QuadratureEstimator SevenPoint (
  285.         final org.drip.numerical.integration.AbscissaTransform abscissaTransformer)
  286.     {
  287.         double twoOver11Sqrt_5Over3_ = 2. / 11. * java.lang.Math.sqrt (5. / 3.);

  288.         double farNode = java.lang.Math.sqrt ((5. / 11.) + twoOver11Sqrt_5Over3_);

  289.         double nearNode = java.lang.Math.sqrt ((5. / 11.) - twoOver11Sqrt_5Over3_);

  290.         double sevenSqrt15 = 7. * java.lang.Math.sqrt (15.);

  291.         double nearWeight = (124. + sevenSqrt15) / 350.;
  292.         double farWeight = (124. - sevenSqrt15) / 350.;

  293.         try
  294.         {
  295.             return new org.drip.numerical.integration.QuadratureEstimator (
  296.                 abscissaTransformer,
  297.                 org.drip.numerical.common.Array2D.FromArray (
  298.                     new double[]
  299.                     {
  300.                         -1.000000000000000,
  301.                         -farNode,
  302.                         -nearNode,
  303.                          0.000000000000000,
  304.                          nearNode,
  305.                          farNode,
  306.                          1.000000000000000,
  307.                     },
  308.                     new double[]
  309.                     {
  310.                         1. / 21.,
  311.                         farWeight,
  312.                         nearWeight,
  313.                         256. / 525.,
  314.                         nearWeight,
  315.                         farWeight,
  316.                         1. / 21.,
  317.                     }
  318.                 )
  319.             );
  320.         }
  321.         catch (java.lang.Exception e)
  322.         {
  323.             e.printStackTrace();
  324.         }

  325.         return null;
  326.     }

  327.     /**
  328.      * Generate the Three Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  329.      *
  330.      * @param left Left Integrand Quadrature Limit
  331.      * @param right Right Integrand Quadrature Limit
  332.      *
  333.      * @return The Three Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  334.      */

  335.     public static final org.drip.numerical.integration.QuadratureEstimator ThreePoint (
  336.         final double left,
  337.         final double right)
  338.     {
  339.         return ThreePoint (
  340.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  341.                 left,
  342.                 right
  343.             )
  344.         );
  345.     }

  346.     /**
  347.      * Generate the Four Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  348.      *
  349.      * @param left Left Integrand Quadrature Limit
  350.      * @param right Right Integrand Quadrature Limit
  351.      *
  352.      * @return The Four Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  353.      */

  354.     public static final org.drip.numerical.integration.QuadratureEstimator FourPoint (
  355.         final double left,
  356.         final double right)
  357.     {
  358.         return FourPoint (
  359.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  360.                 left,
  361.                 right
  362.             )
  363.         );
  364.     }

  365.     /**
  366.      * Generate the Five Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  367.      *
  368.      * @param left Left Integrand Quadrature Limit
  369.      * @param right Right Integrand Quadrature Limit
  370.      *
  371.      * @return The Five Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  372.      */

  373.     public static final org.drip.numerical.integration.QuadratureEstimator FivePoint (
  374.         final double left,
  375.         final double right)
  376.     {
  377.         return FivePoint (
  378.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  379.                 left,
  380.                 right
  381.             )
  382.         );
  383.     }

  384.     /**
  385.      * Generate the Six Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  386.      *
  387.      * @param left Left Integrand Quadrature Limit
  388.      * @param right Right Integrand Quadrature Limit
  389.      *
  390.      * @return The Six Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  391.      */

  392.     public static final org.drip.numerical.integration.QuadratureEstimator SixPoint (
  393.         final double left,
  394.         final double right)
  395.     {
  396.         return SixPoint (
  397.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  398.                 left,
  399.                 right
  400.             )
  401.         );
  402.     }

  403.     /**
  404.      * Generate the Seven Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  405.      *
  406.      * @param left Left Integrand Quadrature Limit
  407.      * @param right Right Integrand Quadrature Limit
  408.      *
  409.      * @return The Seven Point Gauss Legendre Quadrature over [a, b] onto [-1, +1]
  410.      */

  411.     public static final org.drip.numerical.integration.QuadratureEstimator SevenPoint (
  412.         final double left,
  413.         final double right)
  414.     {
  415.         return SevenPoint (
  416.             org.drip.numerical.integration.AbscissaTransform.DisplaceAndScaleMinusOne_PlusOne (
  417.                 left,
  418.                 right
  419.             )
  420.         );
  421.     }
  422. }