ExponentialAffineZeroPricer.java

  1. package org.drip.sample.ckls;

  2. import org.drip.dynamics.meanreverting.R1CIRStochasticEvolver;
  3. import org.drip.dynamics.physical.ExponentialAffineZeroCoefficients;
  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>ExponentialAffineZeroPricer</i> illustrates the Pricing of a Zero Coupon Bond using the R<sup>1</sup>
  80.  *  Cox-Ingersoll-Ross Process. The References are:
  81.  *  
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Bogoliubov, N. N., and D. P. Sankevich (1994): N. N. Bogoliubov and Statistical Mechanics
  86.  *              <i>Russian Mathematical Surveys</i> <b>49 (5)</b> 19-49
  87.  *      </li>
  88.  *      <li>
  89.  *          Holubec, V., K. Kroy, and S. Steffenoni (2019): Physically Consistent Numerical Solver for
  90.  *              Time-dependent Fokker-Planck Equations <i>Physical Review E</i> <b>99 (4)</b> 032117
  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.  *          Ottinger, H. C. (1996): <i>Stochastic Processes in Polymeric Fluids</i> <b>Springer-Verlag</b>
  98.  *              Berlin-Heidelberg
  99.  *      </li>
  100.  *      <li>
  101.  *          Wikipedia (2019): Fokker-Planck Equation
  102.  *              https://en.wikipedia.org/wiki/Fokker%E2%80%93Planck_equation
  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 ExponentialAffineZeroPricer
  117. {

  118.     private static final void Price (
  119.         final R1CIRStochasticEvolver r1CIRStochasticEvolver,
  120.         final double[] ttmArray,
  121.         final double[] rateArray)
  122.         throws Exception
  123.     {
  124.         System.out.println (
  125.             "\t|--------------------------------------------------------------------------------------------------||"
  126.         );

  127.         System.out.println (
  128.             "\t|      Mean Reversion Speed => " + r1CIRStochasticEvolver.cklsParameters().meanReversionSpeed()
  129.         );

  130.         System.out.println (
  131.             "\t|      Mean Reversion Level => " + r1CIRStochasticEvolver.cklsParameters().meanReversionLevel()
  132.         );

  133.         System.out.println (
  134.             "\t|      Volatility           => " + r1CIRStochasticEvolver.cklsParameters().volatilityCoefficient()
  135.         );

  136.         System.out.println (
  137.             "\t|--------------------------------------------------------------------------------------------------||"
  138.         );

  139.         for (double ttm : ttmArray)
  140.         {
  141.             ExponentialAffineZeroCoefficients exponentialAffineZeroCoefficients =
  142.                 ExponentialAffineZeroCoefficients.FromCIR (
  143.                     r1CIRStochasticEvolver,
  144.                     ttm
  145.                 );

  146.             String dump = "\t|" + FormatUtil.FormatDouble (ttm, 1, 1, 1.) + " => {" +
  147.                 FormatUtil.FormatDouble (exponentialAffineZeroCoefficients.a(), 2, 2, 1.) + " | " +
  148.                 FormatUtil.FormatDouble (exponentialAffineZeroCoefficients.b(), 2, 2, 1.) + "}  ";

  149.             for (double rate : rateArray)
  150.             {
  151.                 dump = dump + " " + FormatUtil.FormatDouble (
  152.                     exponentialAffineZeroCoefficients.price (
  153.                         rate
  154.                     ), 2, 3, 100., false
  155.                 ) + " |";
  156.             }

  157.             System.out.println (dump + "|");
  158.         }

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

  162.         System.out.println();
  163.     }

  164.     public static final void main (
  165.         final String[] argumentArray)
  166.         throws Exception
  167.     {
  168.         EnvManager.InitEnv (
  169.             ""
  170.         );

  171.         double[] ttmArray =
  172.         {
  173.             5.0,
  174.             4.5,
  175.             4.0,
  176.             3.5,
  177.             3.0,
  178.             2.5,
  179.             2.0,
  180.             1.5,
  181.             1.0,
  182.             0.5,
  183.         };
  184.         double[] rateArray =
  185.         {
  186.             0.08,
  187.             0.07,
  188.             0.06,
  189.             0.05,
  190.             0.04,
  191.             0.03,
  192.             0.02,
  193.             0.01,
  194.         };
  195.         double[] meanReversionSpeedArray =
  196.         {
  197.             0.030,
  198.             0.025,
  199.             0.020,
  200.             0.015,
  201.             0.010,
  202.         };
  203.         double[] meanReversionLevelArray =
  204.         {
  205.             0.045,
  206.             0.035,
  207.             0.035,
  208.             0.015,
  209.             0.005,
  210.         };
  211.         double[] volatilityArray =
  212.         {
  213.             0.020,
  214.             0.015,
  215.             0.010,
  216.             0.005,
  217.         };

  218.         for (double meanReversionLevel : meanReversionLevelArray)
  219.         {
  220.             for (double meanReversionSpeed : meanReversionSpeedArray)
  221.             {
  222.                 for (double volatility : volatilityArray)
  223.                 {
  224.                     Price (
  225.                         R1CIRStochasticEvolver.Wiener (
  226.                             meanReversionSpeed,
  227.                             meanReversionLevel,
  228.                             volatility,
  229.                             0.01
  230.                         ),
  231.                         ttmArray,
  232.                         rateArray
  233.                     );
  234.                 }
  235.             }
  236.         }

  237.         EnvManager.TerminateEnv();
  238.     }
  239. }