ContinuouslyCompoundedForwardProcess.java

  1. package org.drip.dynamics.lmm;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

  5. /*!
  6.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  7.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  8.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  9.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  10.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  11.  * Copyright (C) 2015 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>ContinuouslyCompoundedForwardProcess</i> implements the Continuously Compounded Forward Rate Process
  80.  * defined in the LIBOR Market Model. The References are:
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li>
  85.  *          Goldys, B., M. Musiela, and D. Sondermann (1994): <i>Log-normality of Rates and Term Structure
  86.  *              Models</i> <b>The University of New South Wales</b>
  87.  *      </li>
  88.  *      <li>
  89.  *          Musiela, M. (1994): <i>Nominal Annual Rates and Log-normal Volatility Structure</i> <b>The
  90.  *              University of New South Wales</b>
  91.  *      </li>
  92.  *      <li>
  93.  *          Brace, A., D. Gatarek, and M. Musiela (1997): The Market Model of Interest Rate Dynamics
  94.  *              <i>Mathematical Finance</i> <b>7 (2)</b> 127-155
  95.  *      </li>
  96.  *  </ul>
  97.  *
  98.  *  <br><br>
  99.  *  <ul>
  100.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  101.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  102.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/dynamics/README.md">HJM, Hull White, LMM, and SABR Dynamic Evolution Models</a></li>
  103.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/dynamics/lmm/README.md">LMM Based Latent State Evolution</a></li>
  104.  *  </ul>
  105.  *
  106.  * @author Lakshmi Krishnamurthy
  107.  */

  108. public class ContinuouslyCompoundedForwardProcess {
  109.     private int _iSpotDate = java.lang.Integer.MIN_VALUE;
  110.     private org.drip.measure.stochastic.R1R1ToR1 _funcR1R1ToR1 = null;

  111.     /**
  112.      * ContinuouslyCompoundedForwardProcess Constructor
  113.      *
  114.      * @param iSpotDate The Spot Date
  115.      * @param funcR1R1ToR1 The Stochastic Forward Rate Function
  116.      *
  117.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  118.      */

  119.     public ContinuouslyCompoundedForwardProcess (
  120.         final int iSpotDate,
  121.         final org.drip.measure.stochastic.R1R1ToR1 funcR1R1ToR1)
  122.         throws java.lang.Exception
  123.     {
  124.         if (null == (_funcR1R1ToR1 = funcR1R1ToR1))
  125.             throw new java.lang.Exception ("ContinuouslyCompoundedForwardProcess ctr: Invalid Inputs");

  126.         _iSpotDate = iSpotDate;
  127.     }

  128.     /**
  129.      * Retrieve the Spot Date
  130.      *
  131.      * @return The Spot Date
  132.      */

  133.     public int spotDate()
  134.     {
  135.         return _iSpotDate;
  136.     }

  137.     /**
  138.      * Retrieve the Stochastic Forward Rate Function
  139.      *
  140.      * @return The Stochastic Forward Rate Function
  141.      */

  142.     public org.drip.measure.stochastic.R1R1ToR1 stochasticForwardRateFunction()
  143.     {
  144.         return _funcR1R1ToR1;
  145.     }

  146.     /**
  147.      * Retrieve a Realized Zero-Coupon Bond Price
  148.      *
  149.      * @param iMaturityDate The Maturity Date
  150.      *
  151.      * @return The Realized Zero-Coupon Bond Price
  152.      *
  153.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  154.      */

  155.     public double realizedZeroCouponPrice (
  156.         final int iMaturityDate)
  157.         throws java.lang.Exception
  158.     {
  159.         if (iMaturityDate <= _iSpotDate)
  160.             throw new java.lang.Exception
  161.                 ("ContinuouslyCompoundedForwardProcess::realizedZeroCouponPrice => Invalid Maturity Date");

  162.         return java.lang.Math.exp (-1. * _funcR1R1ToR1.integralRealization (0., iMaturityDate - _iSpotDate));
  163.     }

  164.     /**
  165.      * Compute the Realized/Expected Instantaneous Forward Rate Integral to the Target Date
  166.      *
  167.      * @param iTargetDate The Target Date
  168.      * @param bRealized TRUE - Compute the Realized (TRUE) / Expected (FALSE) Instantaneous Forward Rate
  169.      *  Integral
  170.      *
  171.      * @return The Realized/Expected Instantaneous Forward Rate Integral
  172.      *
  173.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  174.      */

  175.     public double instantaneousForwardRateIntegral (
  176.         final int iTargetDate,
  177.         final boolean bRealized)
  178.         throws java.lang.Exception
  179.     {
  180.         if (iTargetDate <= _iSpotDate)
  181.             throw new java.lang.Exception
  182.                 ("ContinuouslyCompoundedForwardProcess::instantaneousForwardRateIntegral => Invalid Target Date");

  183.         return bRealized ? java.lang.Math.exp (-1. * _funcR1R1ToR1.integralRealization (0., iTargetDate -
  184.             _iSpotDate)) : java.lang.Math.exp (-1. * _funcR1R1ToR1.integralExpectation (0., iTargetDate -
  185.                 _iSpotDate));
  186.     }

  187.     /**
  188.      * Retrieve a Realized/Expected Value of the Discount to the Target Date
  189.      *
  190.      * @param iTargetDate The Target Date
  191.      * @param bRealized TRUE - Compute the Realized (TRUE) / Expected (FALSE) Instantaneous Forward Rate
  192.      *  Integral
  193.      *
  194.      * @return The Realized/Expected Value of the Discount to the Target Date
  195.      *
  196.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  197.      */

  198.     public double discountFunctionValue (
  199.         final int iTargetDate,
  200.         final boolean bRealized)
  201.         throws java.lang.Exception
  202.     {
  203.         if (iTargetDate <= _iSpotDate)
  204.             throw new java.lang.Exception
  205.                 ("ContinuouslyCompoundedForwardProcess::discountFunctionValue => Invalid Target Date");

  206.         return bRealized ? java.lang.Math.exp (-1. * _funcR1R1ToR1.integralRealization (0., iTargetDate -
  207.             _iSpotDate)) : java.lang.Math.exp (-1. * _funcR1R1ToR1.integralExpectation (0., iTargetDate -
  208.                 _iSpotDate));
  209.     }

  210.     /**
  211.      * Retrieve a Realized/Expected Value of the LIBOR Rate at the Target Date
  212.      *
  213.      * @param iTargetDate The Target Date
  214.      * @param strTenor The LIBOR Tenor
  215.      * @param bRealized TRUE - Compute the Realized (TRUE) / Expected (FALSE) LIBOR Rate
  216.      *
  217.      * @return The Realized/Expected Value of the LIBOR Rate at the Target Date
  218.      *
  219.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  220.      */

  221.     public double liborRate (
  222.         final int iTargetDate,
  223.         final java.lang.String strTenor,
  224.         final boolean bRealized)
  225.         throws java.lang.Exception
  226.     {
  227.         if (iTargetDate <= _iSpotDate)
  228.             throw new java.lang.Exception
  229.                 ("ContinuouslyCompoundedForwardProcess::liborRate => Invalid Inputs");

  230.         return (discountFunctionValue (new org.drip.analytics.date.JulianDate (iTargetDate).addTenor
  231.             (strTenor).julian(), bRealized) / discountFunctionValue (iTargetDate, bRealized) - 1.) /
  232.                 org.drip.analytics.support.Helper.TenorToYearFraction (strTenor);
  233.     }
  234. }