ContinuousForwardRateUpdate.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>ContinuousForwardRateUpdate</i> contains the Instantaneous Snapshot of the Evolving Discount Latent
  80.  * State Quantification Metrics Updated using the Continuously Compounded Forward Rate Dynamics.
  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 ContinuousForwardRateUpdate extends org.drip.dynamics.evolution.LSQMPointUpdate {
  109.     private org.drip.state.identifier.ForwardLabel _lslForward = null;
  110.     private org.drip.state.identifier.FundingLabel _lslFunding = null;
  111.     private double _dblDContinuousForwardDXInitial = java.lang.Double.NaN;
  112.     private double _dblDContinuousForwardDXTerminal = java.lang.Double.NaN;

  113.     /**
  114.      * Construct an Instance of ContinuousForwardRateUpdate
  115.      *
  116.      * @param lslFunding The Funding Latent State Label
  117.      * @param lslForward The Forward Latent State Label
  118.      * @param iInitialDate The Initial Date
  119.      * @param iFinalDate The Final Date
  120.      * @param iTargetPointDate The Target Point Date
  121.      * @param dblContinuousForwardRate The Continuously Compounded Forward Rate
  122.      * @param dblContinuousForwardRateIncrement The Continuously Compounded Forward Rate Increment
  123.      * @param dblSpotRate The Spot Rate
  124.      * @param dblSpotRateIncrement The Spot Rate Increment
  125.      * @param dblDiscountFactor The Discount Factor
  126.      * @param dblDiscountFactorIncrement The Discount Factor Increment
  127.      * @param dblDContinuousForwardDXInitial Initial D {Continuously Compounded Forward Rate} / DX
  128.      * @param dblDContinuousForwardDXTerminal Terminal D {Continuously Compounded Forward Rate} / DX
  129.      *
  130.      * @return Instance of ContinuousForwardRateUpdate
  131.      */

  132.     public static final ContinuousForwardRateUpdate Create (
  133.         final org.drip.state.identifier.FundingLabel lslFunding,
  134.         final org.drip.state.identifier.ForwardLabel lslForward,
  135.         final int iInitialDate,
  136.         final int iFinalDate,
  137.         final int iTargetPointDate,
  138.         final double dblContinuousForwardRate,
  139.         final double dblContinuousForwardRateIncrement,
  140.         final double dblSpotRate,
  141.         final double dblSpotRateIncrement,
  142.         final double dblDiscountFactor,
  143.         final double dblDiscountFactorIncrement,
  144.         final double dblDContinuousForwardDXInitial,
  145.         final double dblDContinuousForwardDXTerminal)
  146.     {
  147.         org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot = new org.drip.dynamics.evolution.LSQMPointRecord();

  148.         if (!lrSnapshot.setQM (lslForward,
  149.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE,
  150.                 dblContinuousForwardRate))
  151.             return null;

  152.         if (!lrSnapshot.setQM (lslFunding,
  153.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, dblSpotRate))
  154.             return null;

  155.         if (!lrSnapshot.setQM (lslFunding,
  156.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR, dblDiscountFactor))
  157.             return null;

  158.         org.drip.dynamics.evolution.LSQMPointRecord lrIncrement = new org.drip.dynamics.evolution.LSQMPointRecord();

  159.         if (!lrIncrement.setQM (lslForward,
  160.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE,
  161.                 dblContinuousForwardRateIncrement))
  162.             return null;

  163.         if (!lrIncrement.setQM (lslFunding,
  164.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, dblSpotRateIncrement))
  165.             return null;

  166.         if (!lrIncrement.setQM (lslFunding,
  167.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  168.                 dblDiscountFactorIncrement))
  169.             return null;

  170.         try {
  171.             return new ContinuousForwardRateUpdate (lslFunding, lslForward, iInitialDate, iFinalDate,
  172.                 iTargetPointDate, lrSnapshot, lrIncrement, dblDContinuousForwardDXInitial,
  173.                     dblDContinuousForwardDXTerminal);
  174.         } catch (java.lang.Exception e) {
  175.             e.printStackTrace();
  176.         }

  177.         return null;
  178.     }

  179.     private ContinuousForwardRateUpdate (
  180.         final org.drip.state.identifier.FundingLabel lslFunding,
  181.         final org.drip.state.identifier.ForwardLabel lslForward,
  182.         final int iInitialDate,
  183.         final int iFinalDate,
  184.         final int iViewDate,
  185.         final org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot,
  186.         final org.drip.dynamics.evolution.LSQMPointRecord lrIncrement,
  187.         final double dblDContinuousForwardDXInitial,
  188.         final double dblDContinuousForwardDXTerminal)
  189.         throws java.lang.Exception
  190.     {
  191.         super (iInitialDate, iFinalDate, iViewDate, lrSnapshot, lrIncrement);

  192.         if (null == (_lslFunding = lslFunding) || null == (_lslForward = lslForward) ||
  193.             !org.drip.numerical.common.NumberUtil.IsValid (_dblDContinuousForwardDXTerminal =
  194.                 dblDContinuousForwardDXTerminal) || !org.drip.numerical.common.NumberUtil.IsValid
  195.                     (_dblDContinuousForwardDXInitial = dblDContinuousForwardDXInitial))
  196.             throw new java.lang.Exception ("ContinuousForwardRateUpdate ctr: Invalid Inputs");
  197.     }

  198.     /**
  199.      * Retrieve the Continuously Compounded Forward Rate
  200.      *
  201.      * @return The Continuously Compounded Forward Rate
  202.      *
  203.      * @throws java.lang.Exception Thrown if the Continuously Compounded Forward Rate is not available
  204.      */

  205.     public double continuousForwardRate()
  206.         throws java.lang.Exception
  207.     {
  208.         return snapshot().qm (_lslForward,
  209.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE);
  210.     }

  211.     /**
  212.      * Retrieve the Continuously Compounded Forward Rate Increment
  213.      *
  214.      * @return The Continuously Compounded Forward Rate Increment
  215.      *
  216.      * @throws java.lang.Exception Thrown if the Continuously Compounded Forward Rate Increment is not available
  217.      */

  218.     public double continuousForwardRateIncrement()
  219.         throws java.lang.Exception
  220.     {
  221.         return increment().qm (_lslForward,
  222.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE);
  223.     }

  224.     /**
  225.      * Retrieve the Spot Rate
  226.      *
  227.      * @return The Spot Rate
  228.      *
  229.      * @throws java.lang.Exception Thrown if the Spot Rate is not available
  230.      */

  231.     public double spotRate()
  232.         throws java.lang.Exception
  233.     {
  234.         return snapshot().qm (_lslFunding,
  235.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE);
  236.     }

  237.     /**
  238.      * Retrieve the Spot Rate Increment
  239.      *
  240.      * @return The Spot Rate Increment
  241.      *
  242.      * @throws java.lang.Exception Thrown if the Spot Rate Increment is not available
  243.      */

  244.     public double spotRateIncrement()
  245.         throws java.lang.Exception
  246.     {
  247.         return increment().qm (_lslFunding,
  248.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE);
  249.     }

  250.     /**
  251.      * Retrieve the Discount Factor
  252.      *
  253.      * @return The Discount Factor
  254.      *
  255.      * @throws java.lang.Exception Thrown if the Discount Factor is not available
  256.      */

  257.     public double discountFactor()
  258.         throws java.lang.Exception
  259.     {
  260.         return snapshot().qm (_lslFunding,
  261.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  262.     }

  263.     /**
  264.      * Retrieve the Discount Factor Increment
  265.      *
  266.      * @return The Discount Factor Increment
  267.      *
  268.      * @throws java.lang.Exception Thrown if the Discount Factor Increment is not available
  269.      */

  270.     public double discountFactorIncrement()
  271.         throws java.lang.Exception
  272.     {
  273.         return increment().qm (_lslFunding,
  274.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  275.     }

  276.     /**
  277.      * Retrieve the Initial D {Continuously Compounded Forward Rate} / DX
  278.      *
  279.      * @return The Initial D {Continuously Compounded Forward Rate} / DX
  280.      */

  281.     public double dContinuousForwardDXInitial()
  282.     {
  283.         return _dblDContinuousForwardDXInitial;
  284.     }

  285.     /**
  286.      * Retrieve the Terminal D {Continuously Compounded Forward Rate} / DX
  287.      *
  288.      * @return The Terminal D {Continuously Compounded Forward Rate} / DX
  289.      */

  290.     public double dContinuousForwardDXTerminal()
  291.     {
  292.         return _dblDContinuousForwardDXTerminal;
  293.     }
  294. }