OrnsteinUhlenbeckTemporalPDF.java

  1. package org.drip.sample.kolmogorov;

  2. import org.drip.dynamics.ito.TimeR1Vertex;
  3. import org.drip.dynamics.kolmogorov.R1FokkerPlanckOrnsteinUhlenbeck;
  4. import org.drip.dynamics.meanreverting.CKLSParameters;
  5. import org.drip.dynamics.process.R1ProbabilityDensityFunction;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;

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

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

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

  107. public class OrnsteinUhlenbeckTemporalPDF
  108. {

  109.     public static final void main (
  110.         final String[] argumentArray)
  111.         throws Exception
  112.     {
  113.         EnvManager.InitEnv (
  114.             ""
  115.         );

  116.         double[] timeArray =
  117.         {
  118.             0.5,
  119.             1.0,
  120.             1.5,
  121.             2.0,
  122.             2.5,
  123.             3.0,
  124.             3.5,
  125.             4.0,
  126.             4.5,
  127.             5.0,
  128.             5.5,
  129.             6.0,
  130.             6.5,
  131.             7.0,
  132.             7.5,
  133.             8.0,
  134.             8.5,
  135.             9.0,
  136.             9.5
  137.         };
  138.         double[] xArray =
  139.         {
  140.             -2.5,
  141.             -2.0,
  142.             -1.5,
  143.             -1.0,
  144.             -0.5,
  145.              0.0,
  146.              0.5,
  147.              1.0,
  148.              1.5,
  149.              2.0,
  150.              2.5,
  151.         };

  152.         double volatility = 2.;
  153.         double meanReversionSpeed = 0.5;

  154.         R1ProbabilityDensityFunction r1ProbabilityDensityFunction =
  155.             new R1FokkerPlanckOrnsteinUhlenbeck (
  156.                 CKLSParameters.OrnsteinUhlenbeck (
  157.                     meanReversionSpeed,
  158.                     volatility
  159.                 )
  160.             ).deltaStartTemporalPDF (
  161.                 0.
  162.             );

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

  164.         System.out.println ("\t|                                FOKKER PLANCK ORNSTEIN UHLENBECK MOTION DISTRIBUTION REALIZATIONS OVER TIME                                ||");

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

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

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

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

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

  170.         for (double t : timeArray)
  171.         {
  172.             java.lang.String dump = "\t| " + FormatUtil.FormatDouble (t, 1, 1, 1.) + " =>";

  173.             for (double x : xArray)
  174.             {
  175.                 dump = dump + " " + FormatUtil.FormatDouble (
  176.                     r1ProbabilityDensityFunction.density (
  177.                         new TimeR1Vertex (
  178.                             t,
  179.                             x
  180.                         )
  181.                     ), 1, 6, 1.
  182.                 ) + " |";
  183.             }

  184.             System.out.println (dump + "|");
  185.         }

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

  187.         EnvManager.TerminateEnv();
  188.     }
  189. }