OrnsteinUhlenbeckSteadyStatePDF.java

  1. package org.drip.sample.kolmogorov;

  2. import org.drip.dynamics.kolmogorov.R1FokkerPlanckOrnsteinUhlenbeck;
  3. import org.drip.dynamics.meanreverting.CKLSParameters;
  4. import org.drip.function.definition.R1ToR1;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.service.env.EnvManager;

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

  10. /*!
  11.  * Copyright (C) 2020 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>OrnsteinUhlenbeckSteadyStatePDF</i> illustrates the Steady-State Distribution of an Evolving
  70.  *  R<sup>1</sup> Ornstein-Uhlenbeck 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 OrnsteinUhlenbeckSteadyStatePDF
  107. {

  108.     private static final void SteadyStateDistribution (
  109.         final double meanReversionSpeed,
  110.         final double volatility,
  111.         final double[] xArray)
  112.         throws Exception
  113.     {
  114.         R1ToR1 steadyStatePDF = new R1FokkerPlanckOrnsteinUhlenbeck (
  115.             CKLSParameters.OrnsteinUhlenbeck (
  116.                 meanReversionSpeed,
  117.                 volatility
  118.             )
  119.         ).steadyStatePDF();

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

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

  130.         System.out.println (dump + "|");
  131.     }

  132.     public static final void main (
  133.         final String[] argumentArray)
  134.         throws Exception
  135.     {
  136.         EnvManager.InitEnv (
  137.             ""
  138.         );
  139.         double[] xArray =
  140.         {
  141.             -2.5,
  142.             -2.0,
  143.             -1.5,
  144.             -1.0,
  145.             -0.5,
  146.              0.0,
  147.              0.5,
  148.              1.0,
  149.              1.5,
  150.              2.0,
  151.              2.5,
  152.         };
  153.         double[] volatilityArray =
  154.         {
  155.              0.5,
  156.              1.0,
  157.              1.5,
  158.              2.0,
  159.              2.5,
  160.         };
  161.         double[] meanReversionSpeedArray =
  162.         {
  163.              0.5,
  164.              1.0,
  165.              1.5,
  166.              2.0,
  167.              2.5,
  168.         };

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

  170.         System.out.println ("\t|                                          ORNSTEIN-UHLENBECK FOKKER-PLANCK PDF STEADY STATE DISTRIBUTION                                           ||");

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

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

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

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

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

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

  177.         for (double meanReversionSpeed : meanReversionSpeedArray)
  178.         {
  179.             for (double volatility : volatilityArray)
  180.             {
  181.                 SteadyStateDistribution (
  182.                     meanReversionSpeed,
  183.                     volatility,
  184.                     xArray
  185.                 );
  186.             }
  187.         }

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

  189.         EnvManager.TerminateEnv();
  190.     }
  191. }