VasicekPopulationCentralMeasures.java

  1. package org.drip.sample.ckls;

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

  117. public class VasicekPopulationCentralMeasures
  118. {

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

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

  136.         for (double t : tArray)
  137.         {
  138.             PopulationCentralMeasures populationCentralMeasures =
  139.                 r1StochasticEvolver.temporalPopulationCentralMeasures (
  140.                     meanReversionSpeed,
  141.                     t
  142.                 );

  143.             dump = dump + " {" + FormatUtil.FormatDouble (
  144.                 populationCentralMeasures.mean(), 1, 4, 1.
  145.             ) + " |" + FormatUtil.FormatDouble (
  146.                 populationCentralMeasures.variance(), 1, 4, 1.
  147.             ) + "}";
  148.         }

  149.         System.out.println (dump);
  150.     }

  151.     private static final void SteadyStateCentralMeasures (
  152.         final double meanReversionSpeed,
  153.         final double meanReversionLevel,
  154.         final double volatility)
  155.         throws Exception
  156.     {
  157.         PopulationCentralMeasures populationCentralMeasures = R1VasicekStochasticEvolver.Wiener (
  158.             meanReversionSpeed,
  159.             meanReversionLevel,
  160.             volatility,
  161.             0.01
  162.         ).steadyStatePopulationCentralMeasures (
  163.             meanReversionSpeed
  164.         );

  165.         System.out.println (
  166.             "\t| [" + FormatUtil.FormatDouble (
  167.                 meanReversionSpeed, 1, 1, 1.
  168.             ) + "," + FormatUtil.FormatDouble (
  169.                 meanReversionLevel, 1, 1, 1.
  170.             ) + "," + FormatUtil.FormatDouble (
  171.                 volatility, 1, 1, 1.
  172.             ) + "] =>" + " {" + FormatUtil.FormatDouble (
  173.                 populationCentralMeasures.mean(), 1, 4, 1.
  174.             ) + " |" + FormatUtil.FormatDouble (
  175.                 populationCentralMeasures.variance(), 1, 4, 1.
  176.             ) + "}"
  177.         );
  178.     }

  179.     public static final void main (
  180.         final String[] argumentArray)
  181.         throws Exception
  182.     {
  183.         EnvManager.InitEnv (
  184.             ""
  185.         );
  186.         double[] tArray =
  187.         {
  188.              1.0,
  189.              2.0,
  190.              3.0,
  191.              4.0,
  192.              5.0,
  193.              6.0,
  194.              7.0,
  195.         };
  196.         double[] volatilityArray =
  197.         {
  198.              0.5,
  199.              1.0,
  200.              1.5,
  201.              2.0,
  202.              2.5,
  203.         };
  204.         double[] meanReversionLevelArray =
  205.         {
  206.              0.5,
  207.              1.0,
  208.              1.5,
  209.         };
  210.         double[] meanReversionSpeedArray =
  211.         {
  212.              0.5,
  213.              1.0,
  214.              1.5,
  215.              2.0,
  216.              2.5,
  217.         };

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

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

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

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

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

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

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

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

  226.         for (double meanReversionSpeed : meanReversionSpeedArray)
  227.         {
  228.             for (double meanReversionLevel : meanReversionLevelArray)
  229.             {
  230.                 for (double volatility : volatilityArray)
  231.                 {
  232.                     TemporalCentralMeasures (
  233.                         meanReversionSpeed,
  234.                         meanReversionLevel,
  235.                         volatility,
  236.                         tArray
  237.                     );
  238.                 }
  239.             }
  240.         }

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

  242.         System.out.println();

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

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

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

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

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

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

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

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

  251.         for (double meanReversionSpeed : meanReversionSpeedArray)
  252.         {
  253.             for (double meanReversionLevel : meanReversionLevelArray)
  254.             {
  255.                 for (double volatility : volatilityArray)
  256.                 {
  257.                     SteadyStateCentralMeasures (
  258.                         meanReversionSpeed,
  259.                         meanReversionLevel,
  260.                         volatility
  261.                     );
  262.                 }
  263.             }
  264.         }

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

  266.         EnvManager.TerminateEnv();
  267.     }
  268. }