BrownianTemporalPDF.java

  1. package org.drip.sample.kolmogorov;

  2. import org.drip.dynamics.ito.TimeR1Vertex;
  3. import org.drip.dynamics.kolmogorov.R1FokkerPlanckBrownian;
  4. import org.drip.dynamics.process.R1ProbabilityDensityFunction;
  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>BrownianTemporalPDF</i> illustrates the Temporal Distribution of an Evolving R<sup>1</sup> Brownian
  70.  *  Motion. 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 BrownianTemporalPDF
  107. {

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

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

  151.         R1ProbabilityDensityFunction r1ProbabilityDensityFunction =
  152.             new R1FokkerPlanckBrownian().deltaStartTemporalPDF (
  153.                 0.
  154.             );

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

  156.         System.out.println ("\t|                                     FOKKER PLANCK BROWNIAN MOTION DISTRIBUTION REALIZATIONS OVER TIME                                     ||");

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

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

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

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

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

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

  165.             for (double x : xArray)
  166.             {
  167.                 dump = dump + " " + FormatUtil.FormatDouble (
  168.                     r1ProbabilityDensityFunction.density (
  169.                         new TimeR1Vertex (
  170.                             t,
  171.                             x
  172.                         )
  173.                     ), 1, 6, 1.
  174.                 ) + " |";
  175.             }

  176.             System.out.println (dump + "|");
  177.         }

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

  179.         EnvManager.TerminateEnv();
  180.     }
  181. }