LangevinEvolution.java

  1. package org.drip.sample.ckls;

  2. import org.drip.dynamics.ito.R1WienerDriver;
  3. import org.drip.dynamics.physical.LangevinEvolver;
  4. import org.drip.numerical.common.FormatUtil;
  5. import org.drip.service.env.EnvManager;

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

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

  78. /**
  79.  * <i>LangevinEvolver</i> implements the Noisy Elastic Relaxation Process in a Friction-Thermal Background.
  80.  *  The References are:
  81.  *  
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Doob, J. L. (1942): The Brownian Movement and Stochastic Equations <i>Annals of Mathematics</i>
  86.  *              <b>43 (2)</b> 351-369
  87.  *      </li>
  88.  *      <li>
  89.  *          Gardiner, C. W. (2009): <i>Stochastic Methods: A Handbook for the Natural and Social Sciences
  90.  *              4<sup>th</sup> Edition</i> <b>Springer-Verlag</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Kadanoff, L. P. (2000): <i>Statistical Physics: Statics, Dynamics, and Re-normalization</i>
  94.  *              <b>World Scientific</b>
  95.  *      </li>
  96.  *      <li>
  97.  *          Karatzas, I., and S. E. Shreve (1991): <i>Brownian Motion and Stochastic Calculus 2<sup>nd</sup>
  98.  *              Edition</i> <b>Springer-Verlag</b>
  99.  *      </li>
  100.  *      <li>
  101.  *          Risken, H., and F. Till (1996): <i>The Fokker-Planck Equation – Methods of Solution and
  102.  *              Applications</i> <b>Springer</b>
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  110.  *      <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>
  111.  *      <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>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class LangevinEvolution
  117. {

  118.     public static final void main (
  119.         final String[] argumentArray)
  120.         throws Exception
  121.     {
  122.         EnvManager.InitEnv (
  123.             ""
  124.         );

  125.         double timeWidth = 1.;
  126.         double temperature = 300.;
  127.         double restLength = 1.e-10;
  128.         double initialLength = 3.e-10;
  129.         double dampingCoefficient = 0.5;
  130.         double elasticityCoefficient = 1.0;
  131.         double[] timeArray =
  132.         {
  133.             0.0,
  134.             0.5,
  135.             1.0,
  136.             1.5,
  137.             2.0,
  138.             2.5,
  139.             3.0,
  140.             3.5,
  141.             4.0,
  142.             4.5,
  143.             5.0,
  144.             5.5,
  145.             6.0,
  146.             6.5,
  147.             7.0,
  148.             7.5,
  149.             8.0,
  150.             8.5,
  151.             9.0,
  152.             9.5
  153.         };

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

  157.         System.out.println (
  158.             "\t|                 LANGEVIN SYSTEM EVOLUTION                 ||"
  159.         );

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

  163.         System.out.println (
  164.             "\t| Temperature             => " + temperature
  165.         );

  166.         System.out.println (
  167.             "\t| Rest Length             => " + restLength
  168.         );

  169.         System.out.println (
  170.             "\t| Damping Coefficient     => " + dampingCoefficient
  171.         );

  172.         System.out.println (
  173.             "\t| Elasticity Coefficient  => " + elasticityCoefficient
  174.         );

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

  178.         R1WienerDriver wienerDriver = new R1WienerDriver (
  179.             timeWidth
  180.         );

  181.         LangevinEvolver langevinEvolver = new LangevinEvolver (
  182.             elasticityCoefficient,
  183.             dampingCoefficient,
  184.             restLength,
  185.             temperature,
  186.             wienerDriver
  187.         );

  188.         System.out.println (
  189.             "\t| Correlation Time        => " + langevinEvolver.correlationTime()
  190.         );

  191.         System.out.println (
  192.             "\t| Diffusion Coefficient   => " + langevinEvolver.stokesEinsteinEffectiveDiffusionCoefficient()
  193.         );

  194.         System.out.println (
  195.             "\t| Equi-Partition Energy   => " + langevinEvolver.equiPartitionEnergy()
  196.         );

  197.         System.out.println (
  198.             "\t| Volatility              => " + langevinEvolver.cklsParameters().volatilityCoefficient()
  199.         );

  200.         System.out.println (
  201.             "\t| Mean-Reversion Level    => " + langevinEvolver.cklsParameters().meanReversionLevel()
  202.         );

  203.         System.out.println (
  204.             "\t| Mean-Reversion Speed    => " + langevinEvolver.cklsParameters().meanReversionSpeed()
  205.         );

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

  209.         System.out.println();

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

  213.         for (double time : timeArray)
  214.         {
  215.             System.out.println (
  216.                 "\t| " + FormatUtil.FormatDouble (time, 1, 1, 1.) + " => " +
  217.                 FormatUtil.FormatDouble (
  218.                     langevinEvolver.fluctuationCorrelation (
  219.                         time
  220.                     ), 1, 5, 1.
  221.                 ) + " | " + FormatUtil.FormatDouble (
  222.                     langevinEvolver.fluctuationCovariance (
  223.                         time
  224.                     ), 1, 25, 1.
  225.                 ) + " | " + FormatUtil.FormatDouble (
  226.                     langevinEvolver.mean (
  227.                         initialLength,
  228.                         time
  229.                     ), 1, 15, 1.
  230.                 )
  231.             );
  232.         }

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

  236.         System.out.println();

  237.         double[][] aitSahaliaMLEAsymptote = langevinEvolver.aitSahaliaMLEAsymptote (
  238.             1.
  239.         );

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

  243.         System.out.println (
  244.             "\t| AIT SAHALIA MLE ASYMPTOTE ERROR ||"
  245.         );

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

  249.         org.drip.numerical.common.NumberUtil.Print2DArray (
  250.             "\t|\t",
  251.             aitSahaliaMLEAsymptote,
  252.             false
  253.         );

  254.         System.out.println (
  255.             "\t|---------------------------------||"
  256.         );

  257.         EnvManager.TerminateEnv();
  258.     }
  259. }