CIRSteadyStatePDF.java

  1. package org.drip.sample.kolmogorov;

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

  68. /**
  69.  * <i>CIRTemporalPDF</i> demonstrates the Computation of the PDF from an Evolving R<sup>1</sup>
  70.  *  Cox-Ingersoll-Ross Process. The References are:
  71.  *  
  72.  *  <br><br>
  73.  *  <ul>
  74.  *      <li>
  75.  *          Bogoliubov, N. N., and D. P. Sankevich (1994): N. N. Bogoliubov and Statistical Mechanics
  76.  *              <i>Russian Mathematical Surveys</i> <b>49 (5)</b> 19-49
  77.  *      </li>
  78.  *      <li>
  79.  *          Holubec, V., K. Kroy, and S. Steffenoni (2019): Physically Consistent Numerical Solver for
  80.  *              Time-dependent Fokker-Planck Equations <i>Physical Review E</i> <b>99 (4)</b> 032117
  81.  *      </li>
  82.  *      <li>
  83.  *          Kadanoff, L. P. (2000): <i>Statistical Physics: Statics, Dynamics, and Re-normalization</i>
  84.  *              <b>World Scientific</b>
  85.  *      </li>
  86.  *      <li>
  87.  *          Ottinger, H. C. (1996): <i>Stochastic Processes in Polymeric Fluids</i> <b>Springer-Verlag</b>
  88.  *              Berlin-Heidelberg
  89.  *      </li>
  90.  *      <li>
  91.  *          Wikipedia (2019): Fokker-Planck Equation
  92.  *              https://en.wikipedia.org/wiki/Fokker%E2%80%93Planck_equation
  93.  *      </li>
  94.  *  </ul>
  95.  *
  96.  *  <br><br>
  97.  *  <ul>
  98.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  99.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  100.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/dynamics/README.md">Dynamics</a></li>
  101.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/dynamics/lmm/README.md">LIBOR Market Model</a></li>
  102.  *  </ul>
  103.  *
  104.  * @author Lakshmi Krishnamurthy
  105.  */

  106. public class CIRSteadyStatePDF
  107. {

  108.     private static final void SteadyStateDistribution (
  109.         final double meanReversionSpeed,
  110.         final double meanReversionLevel,
  111.         final double volatility,
  112.         final double[] xArray)
  113.         throws Exception
  114.     {
  115.         R1ToR1 steadyStatePDF = R1CIRStochasticEvolver.Wiener (
  116.             meanReversionSpeed,
  117.             meanReversionLevel,
  118.             volatility,
  119.             0.01
  120.         ).fokkerPlanckGenerator().steadyStatePDF();

  121.         java.lang.String dump = "\t| [" +
  122.             FormatUtil.FormatDouble (meanReversionSpeed, 1, 1, 1.) + ", " +
  123.             FormatUtil.FormatDouble (meanReversionLevel, 1, 1, 1.) + ", " +
  124.             FormatUtil.FormatDouble (volatility, 1, 1, 1.) + "] =>";

  125.         for (double x : xArray)
  126.         {
  127.             dump = dump + " " + FormatUtil.FormatDouble (
  128.                 steadyStatePDF.evaluate (
  129.                     x
  130.                 ), 1, 6, 1.
  131.             ) + " |";
  132.         }

  133.         System.out.println (dump + "|");
  134.     }

  135.     public static final void main (
  136.         final String[] argumentArray)
  137.         throws Exception
  138.     {
  139.         EnvManager.InitEnv (
  140.             ""
  141.         );

  142.         double[] xArray =
  143.         {
  144.              0.01,
  145.              0.25,
  146.              0.50,
  147.              0.75,
  148.              1.00,
  149.              1.25,
  150.              1.50,
  151.              1.75,
  152.              2.00,
  153.              2.25,
  154.              2.50,
  155.         };
  156.         double[] meanReversionLevelArray =
  157.         {
  158.              2.0,
  159.              3.0,
  160.              4.0,
  161.         };
  162.         double[] meanReversionSpeedArray =
  163.         {
  164.              0.5,
  165.              1.0,
  166.              1.5,
  167.              2.0,
  168.              2.5,
  169.         };
  170.         double[] volatilityArray =
  171.         {
  172.             0.5,
  173.             1.0,
  174.             1.5,
  175.             2.0,
  176.             2.5,
  177.             3.0,
  178.         };

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

  180.         System.out.println ("\t|                                                 CIR FOKKER-PLANCK PDF STEADY STATE DISTRIBUTION                                                   ||");

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

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

  183.         System.out.println ("\t|                - Mean Reversion Speed                                                                                                             ||");

  184.         System.out.println ("\t|                - Mean Reversion Level                                                                                                             ||");

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

  186.         System.out.println ("\t|                - Row of PDF Values over x                                                                                                         ||");

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

  188.         for (double meanReversionSpeed : meanReversionSpeedArray)
  189.         {
  190.             for (double meanReversionLevel : meanReversionLevelArray)
  191.             {
  192.                 for (double volatility : volatilityArray)
  193.                 {
  194.                     SteadyStateDistribution (
  195.                         meanReversionSpeed,
  196.                         meanReversionLevel,
  197.                         volatility,
  198.                         xArray
  199.                     );
  200.                 }
  201.             }
  202.         }

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

  204.         EnvManager.TerminateEnv();
  205.     }
  206. }