OrnsteinUhlenbeckPopulationCentralMeasures.java

  1. package org.drip.sample.ckls;

  2. import org.drip.dynamics.meanreverting.R1OrnsteinUhlenbeckStochasticEvolver;
  3. import org.drip.dynamics.process.R1StochasticEvolver;
  4. import org.drip.measure.statistics.PopulationCentralMeasures;
  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.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  15.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  16.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  17.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  18.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  19.  *      and computational support.
  20.  *  
  21.  *      https://lakshmidrip.github.io/DROP/
  22.  *  
  23.  *  DROP is composed of three modules:
  24.  *  
  25.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  26.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  27.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  28.  *
  29.  *  DROP Product Core implements libraries for the following:
  30.  *  - Fixed Income Analytics
  31.  *  - Loan Analytics
  32.  *  - Transaction Cost Analytics
  33.  *
  34.  *  DROP Portfolio Core implements libraries for the following:
  35.  *  - Asset Allocation Analytics
  36.  *  - Asset Liability Management Analytics
  37.  *  - Capital Estimation Analytics
  38.  *  - Exposure Analytics
  39.  *  - Margin Analytics
  40.  *  - XVA Analytics
  41.  *
  42.  *  DROP Computational Core implements libraries for the following:
  43.  *  - Algorithm Support
  44.  *  - Computation Support
  45.  *  - Function Analysis
  46.  *  - Model Validation
  47.  *  - Numerical Analysis
  48.  *  - Numerical Optimizer
  49.  *  - Spline Builder
  50.  *  - Statistical Learning
  51.  *
  52.  *  Documentation for DROP is Spread Over:
  53.  *
  54.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  55.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  56.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  57.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  58.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  59.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  60.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  61.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  62.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  63.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  64.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  65.  *
  66.  *  Licensed under the Apache License, Version 2.0 (the "License");
  67.  *      you may not use this file except in compliance with the License.
  68.  *  
  69.  *  You may obtain a copy of the License at
  70.  *      http://www.apache.org/licenses/LICENSE-2.0
  71.  *  
  72.  *  Unless required by applicable law or agreed to in writing, software
  73.  *      distributed under the License is distributed on an "AS IS" BASIS,
  74.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  75.  *  
  76.  *  See the License for the specific language governing permissions and
  77.  *      limitations under the License.
  78.  */

  79. /**
  80.  * <i>OrnsteinUhlenbeckPopulationCentralMeasures</i> illustrates the Aging of Population Central Measures,
  81.  *  both Temporal and Steady-State, of an Evolving R<sup>1</sup> Ornstein-Uhlenbeck Process. The References
  82.  * are:
  83.  *  
  84.  *  <br><br>
  85.  *  <ul>
  86.  *      <li>
  87.  *          Bogoliubov, N. N., and D. P. Sankevich (1994): N. N. Bogoliubov and Statistical Mechanics
  88.  *              <i>Russian Mathematical Surveys</i> <b>49 (5)</b> 19-49
  89.  *      </li>
  90.  *      <li>
  91.  *          Holubec, V., K. Kroy, and S. Steffenoni (2019): Physically Consistent Numerical Solver for
  92.  *              Time-dependent Fokker-Planck Equations <i>Physical Review E</i> <b>99 (4)</b> 032117
  93.  *      </li>
  94.  *      <li>
  95.  *          Kadanoff, L. P. (2000): <i>Statistical Physics: Statics, Dynamics, and Re-normalization</i>
  96.  *              <b>World Scientific</b>
  97.  *      </li>
  98.  *      <li>
  99.  *          Ottinger, H. C. (1996): <i>Stochastic Processes in Polymeric Fluids</i> <b>Springer-Verlag</b>
  100.  *              Berlin-Heidelberg
  101.  *      </li>
  102.  *      <li>
  103.  *          Wikipedia (2019): Fokker-Planck Equation
  104.  *              https://en.wikipedia.org/wiki/Fokker%E2%80%93Planck_equation
  105.  *      </li>
  106.  *  </ul>
  107.  *
  108.  *  <br><br>
  109.  *  <ul>
  110.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  111.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  112.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  113.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/ckls/README.md">Analysis of CKLS Process Variants</a></li>
  114.  *  </ul>
  115.  *
  116.  * @author Lakshmi Krishnamurthy
  117.  */

  118. public class OrnsteinUhlenbeckPopulationCentralMeasures
  119. {

  120.     private static final void TemporalCentralMeasures (
  121.         final double meanReversionSpeed,
  122.         final double volatility,
  123.         final double[] tArray)
  124.         throws Exception
  125.     {
  126.         R1StochasticEvolver r1StochasticEvolver = R1OrnsteinUhlenbeckStochasticEvolver.Wiener (
  127.             meanReversionSpeed,
  128.             volatility,
  129.             0.01
  130.         );

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

  133.         for (double t : tArray)
  134.         {
  135.             PopulationCentralMeasures populationCentralMeasures =
  136.                 r1StochasticEvolver.temporalPopulationCentralMeasures (
  137.                     meanReversionSpeed,
  138.                     t
  139.                 );

  140.             dump = dump + " {" + FormatUtil.FormatDouble (
  141.                 populationCentralMeasures.mean(), 1, 4, 1.
  142.             ) + " |" + FormatUtil.FormatDouble (
  143.                 populationCentralMeasures.variance(), 1, 4, 1.
  144.             ) + "}";
  145.         }

  146.         System.out.println (dump);
  147.     }

  148.     private static final void SteadyStateCentralMeasures (
  149.         final double meanReversionSpeed,
  150.         final double volatility)
  151.         throws Exception
  152.     {
  153.         PopulationCentralMeasures populationCentralMeasures = R1OrnsteinUhlenbeckStochasticEvolver.Wiener (
  154.             meanReversionSpeed,
  155.             volatility,
  156.             0.01
  157.         ).steadyStatePopulationCentralMeasures (
  158.             meanReversionSpeed
  159.         );

  160.         System.out.println (
  161.             "\t| [" + FormatUtil.FormatDouble (
  162.                 meanReversionSpeed, 1, 1, 1.
  163.             ) + "," + FormatUtil.FormatDouble (
  164.                 volatility, 1, 1, 1.
  165.             ) + "] =>" + " {" + FormatUtil.FormatDouble (
  166.                 populationCentralMeasures.mean(), 1, 4, 1.
  167.             ) + " |" + FormatUtil.FormatDouble (
  168.                 populationCentralMeasures.variance(), 1, 4, 1.
  169.             ) + "}"
  170.         );
  171.     }

  172.     public static final void main (
  173.         final String[] argumentArray)
  174.         throws Exception
  175.     {
  176.         EnvManager.InitEnv (
  177.             ""
  178.         );
  179.         double[] tArray =
  180.         {
  181.              1.0,
  182.              2.0,
  183.              3.0,
  184.              4.0,
  185.              5.0,
  186.              6.0,
  187.              7.0,
  188.         };
  189.         double[] volatilityArray =
  190.         {
  191.              0.5,
  192.              1.0,
  193.              1.5,
  194.              2.0,
  195.              2.5,
  196.         };
  197.         double[] meanReversionSpeedArray =
  198.         {
  199.              0.5,
  200.              1.0,
  201.              1.5,
  202.              2.0,
  203.              2.5,
  204.         };

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

  206.         System.out.println ("\t|                                          ORNSTEIN-UHLENBECK FOKKER-PLANCK PDF TEMPORAL CENTRAL MEASURES                                           ||");

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

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

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

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

  211.         System.out.println ("\t|                - Row of PDF {Mean | Variance} Tuple over t                                                                                        ||");

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

  213.         for (double meanReversionSpeed : meanReversionSpeedArray)
  214.         {
  215.             for (double volatility : volatilityArray)
  216.             {
  217.                 TemporalCentralMeasures (
  218.                     meanReversionSpeed,
  219.                     volatility,
  220.                     tArray
  221.                 );
  222.             }
  223.         }

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

  225.         System.out.println();

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

  227.         System.out.println ("\t|                                        ORNSTEIN-UHLENBECK FOKKER-PLANCK PDF STEADY STATE CENTRAL MEASURES                                         ||");

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

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

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

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

  232.         System.out.println ("\t|                - PDF {Mean | Variance} Tuple                                                                                                      ||");

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

  234.         for (double meanReversionSpeed : meanReversionSpeedArray)
  235.         {
  236.             for (double volatility : volatilityArray)
  237.             {
  238.                 SteadyStateCentralMeasures (
  239.                     meanReversionSpeed,
  240.                     volatility
  241.                 );
  242.             }
  243.         }

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

  245.         EnvManager.TerminateEnv();
  246.     }
  247. }