E2ERFMacLaurinGenerator.java

  1. package org.drip.sample.erf;

  2. import java.util.TreeMap;

  3. import org.drip.function.e2erf.MacLaurinSeries;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;

  6. /*
  7.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  8.  */

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

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

  105. public class E2ERFMacLaurinGenerator
  106. {

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

  112.         int termCount = 20;

  113.         MacLaurinSeries e2MacLaurinSeriesGenerator = MacLaurinSeries.ERF (termCount);

  114.         TreeMap<Integer, Double> termWeightMap = e2MacLaurinSeriesGenerator.termWeightMap();

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

  116.         System.out.println ("\t|    ERROR FUNCTION MACLAURIN SERIES COEFFICIENTS     ||");

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

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

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

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

  121.         System.out.println ("\t|            - MacLaurin Series Coefficient Inverse   ||");

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

  123.         for (int termIndex = 0; termIndex < termCount; ++termIndex)
  124.         {
  125.             double coefficient = termWeightMap.get (termIndex);

  126.             System.out.println (
  127.                 "\t|" + FormatUtil.FormatDouble (termIndex, 2, 0, 1.) + " => " +
  128.                 FormatUtil.FormatDouble (coefficient, 1, 19, 1.) + " | " +
  129.                 FormatUtil.FormatDouble (1. / coefficient, 19, 0, 1.) + " ||"
  130.             );
  131.         }

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

  133.         EnvManager.TerminateEnv();
  134.     }
  135. }