ShortForwardRateUpdate.java

  1. package org.drip.dynamics.hjm;

  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>ShortForwardRateUpdate</i> contains the Instantaneous Snapshot of the Evolving Discount Latent State
  80.  * Quantification Metrics.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <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>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/dynamics/hjm/README.md">HJM Based Latent State Evolution</a></li>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class ShortForwardRateUpdate extends org.drip.dynamics.evolution.LSQMPointUpdate {
  93.     private org.drip.state.identifier.ForwardLabel _lslForward = null;
  94.     private org.drip.state.identifier.FundingLabel _lslFunding = null;

  95.     /**
  96.      * Construct an Instance of ShortForwardRateUpdate
  97.      *
  98.      * @param lslFunding The Funding Latent State Label
  99.      * @param lslForward The Forward Latent State Label
  100.      * @param iInitialDate The Initial Date
  101.      * @param iFinalDate The Final Date
  102.      * @param iTargetPointDate The Target Point Date
  103.      * @param dblInstantaneousForwardRate The Instantaneous Forward Rate
  104.      * @param dblInstantaneousForwardRateIncrement The Instantaneous Forward Rate Increment
  105.      * @param dblLIBORForwardRate The LIBOR Forward Rate
  106.      * @param dblLIBORForwardRateIncrement The LIBOR Forward Rate Increment
  107.      * @param dblShiftedLIBORForwardRate The Shifted LIBOR Forward Rate
  108.      * @param dblShiftedLIBORForwardRateIncrement The Shifted LIBOR Forward Rate Increment
  109.      * @param dblShortRate The Short Rate
  110.      * @param dblShortRateIncrement The Short Rate Increment
  111.      * @param dblCompoundedShortRate The Compounded Short Rate
  112.      * @param dblCompoundedShortRateIncrement The Compounded Short Rate Increment
  113.      * @param dblPrice The Price
  114.      * @param dblPriceIncrement The Price Increment
  115.      *
  116.      * @return Instance of ShortForwardRateUpdate
  117.      */

  118.     public static final ShortForwardRateUpdate Create (
  119.         final org.drip.state.identifier.FundingLabel lslFunding,
  120.         final org.drip.state.identifier.ForwardLabel lslForward,
  121.         final int iInitialDate,
  122.         final int iFinalDate,
  123.         final int iTargetPointDate,
  124.         final double dblInstantaneousForwardRate,
  125.         final double dblInstantaneousForwardRateIncrement,
  126.         final double dblLIBORForwardRate,
  127.         final double dblLIBORForwardRateIncrement,
  128.         final double dblShiftedLIBORForwardRate,
  129.         final double dblShiftedLIBORForwardRateIncrement,
  130.         final double dblShortRate,
  131.         final double dblShortRateIncrement,
  132.         final double dblCompoundedShortRate,
  133.         final double dblCompoundedShortRateIncrement,
  134.         final double dblPrice,
  135.         final double dblPriceIncrement)
  136.     {
  137.         org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot = new
  138.             org.drip.dynamics.evolution.LSQMPointRecord();

  139.         if (!lrSnapshot.setQM (lslFunding,
  140.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, dblShortRate))
  141.             return null;

  142.         if (!lrSnapshot.setQM (lslFunding,
  143.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_COMPOUNDED_SHORT_RATE,
  144.                 dblCompoundedShortRate))
  145.             return null;

  146.         if (!lrSnapshot.setQM (lslFunding,
  147.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR, dblPrice))
  148.             return null;

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

  152.         if (!lrSnapshot.setQM (lslForward,
  153.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_SHIFTED_FORWARD_RATE,
  154.                 dblShiftedLIBORForwardRate))
  155.             return null;

  156.         if (!lrSnapshot.setQM (lslForward,
  157.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_FORWARD_RATE,
  158.                 dblInstantaneousForwardRate))
  159.             return null;

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

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

  165.         if (!lrIncrement.setQM (lslFunding,
  166.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_COMPOUNDED_SHORT_RATE,
  167.                 dblCompoundedShortRateIncrement))
  168.             return null;

  169.         if (!lrIncrement.setQM (lslFunding,
  170.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR, dblPriceIncrement))
  171.             return null;

  172.         if (!lrIncrement.setQM (lslForward,
  173.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE,
  174.                 dblLIBORForwardRateIncrement))
  175.             return null;

  176.         if (!lrIncrement.setQM (lslForward,
  177.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_SHIFTED_FORWARD_RATE,
  178.                 dblShiftedLIBORForwardRateIncrement))
  179.             return null;

  180.         if (!lrIncrement.setQM (lslForward,
  181.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_FORWARD_RATE,
  182.                 dblInstantaneousForwardRateIncrement))
  183.             return null;

  184.         try {
  185.             return new ShortForwardRateUpdate (lslFunding, lslForward, iInitialDate, iFinalDate,
  186.                 iTargetPointDate, lrSnapshot, lrIncrement);
  187.         } catch (java.lang.Exception e) {
  188.             e.printStackTrace();
  189.         }

  190.         return null;
  191.     }

  192.     private ShortForwardRateUpdate (
  193.         final org.drip.state.identifier.FundingLabel lslFunding,
  194.         final org.drip.state.identifier.ForwardLabel lslForward,
  195.         final int iInitialDate,
  196.         final int iFinalDate,
  197.         final int iViewDate,
  198.         final org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot,
  199.         final org.drip.dynamics.evolution.LSQMPointRecord lrIncrement)
  200.         throws java.lang.Exception
  201.     {
  202.         super (iInitialDate, iFinalDate, iViewDate, lrSnapshot, lrIncrement);

  203.         if (null == (_lslFunding = lslFunding) || null == (_lslForward = lslForward))
  204.             throw new java.lang.Exception ("ShortForwardRateUpdate ctr: Invalid Inputs");
  205.     }

  206.     /**
  207.      * Retrieve the Instantaneous Forward Rate
  208.      *
  209.      * @return The Instantaneous Forward Rate
  210.      *
  211.      * @throws java.lang.Exception Thrown if the Instantaneous Forward Rate is not available
  212.      */

  213.     public double instantaneousForwardRate()
  214.         throws java.lang.Exception
  215.     {
  216.         return snapshot().qm (_lslForward,
  217.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_FORWARD_RATE);
  218.     }

  219.     /**
  220.      * Retrieve the Instantaneous Forward Rate Increment
  221.      *
  222.      * @return The Instantaneous Forward Rate Increment
  223.      *
  224.      * @throws java.lang.Exception Thrown if the Instantaneous Forward Rate Increment is not available
  225.      */

  226.     public double instantaneousForwardRateIncrement()
  227.         throws java.lang.Exception
  228.     {
  229.         return increment().qm (_lslForward,
  230.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_FORWARD_RATE);
  231.     }

  232.     /**
  233.      * Retrieve the LIBOR Forward Rate
  234.      *
  235.      * @return The LIBOR Forward Rate
  236.      *
  237.      * @throws java.lang.Exception Thrown if the Forward Rate is not available
  238.      */

  239.     public double liborForwardRate()
  240.         throws java.lang.Exception
  241.     {
  242.         return snapshot().qm (_lslForward,
  243.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE);
  244.     }

  245.     /**
  246.      * Retrieve the LIBOR Forward Rate Increment
  247.      *
  248.      * @return The LIBOR Forward Rate Increment
  249.      *
  250.      * @throws java.lang.Exception Thrown if the Forward Rate Increment is not available
  251.      */

  252.     public double liborForwardRateIncrement()
  253.         throws java.lang.Exception
  254.     {
  255.         return increment().qm (_lslForward,
  256.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_FORWARD_RATE);
  257.     }

  258.     /**
  259.      * Retrieve the Shifted LIBOR Forward Rate
  260.      *
  261.      * @return The Shifted LIBOR Forward Rate
  262.      *
  263.      * @throws java.lang.Exception Thrown if the Shifted Forward Rate is not available
  264.      */

  265.     public double shiftedLIBORForwardRate()
  266.         throws java.lang.Exception
  267.     {
  268.         return snapshot().qm (_lslForward,
  269.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_SHIFTED_FORWARD_RATE);
  270.     }

  271.     /**
  272.      * Retrieve the Shifted LIBOR Forward Rate Increment
  273.      *
  274.      * @return The Shifted LIBOR Forward Rate Increment
  275.      *
  276.      * @throws java.lang.Exception Thrown if the Shifted Forward Rate Increment is not available
  277.      */

  278.     public double shiftedLIBORForwardRateIncrement()
  279.         throws java.lang.Exception
  280.     {
  281.         return increment().qm (_lslForward,
  282.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_SHIFTED_FORWARD_RATE);
  283.     }

  284.     /**
  285.      * Retrieve the Short Rate
  286.      *
  287.      * @return The Short Rate
  288.      *
  289.      * @throws java.lang.Exception Thrown if the Short Rate is not available
  290.      */

  291.     public double shortRate()
  292.         throws java.lang.Exception
  293.     {
  294.         return snapshot().qm (_lslFunding,
  295.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE);
  296.     }

  297.     /**
  298.      * Retrieve the Short Rate Increment
  299.      *
  300.      * @return The Short Rate Increment
  301.      *
  302.      * @throws java.lang.Exception Thrown if the Short Rate Increment is not available
  303.      */

  304.     public double shortRateIncrement()
  305.         throws java.lang.Exception
  306.     {
  307.         return increment().qm (_lslFunding,
  308.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE);
  309.     }

  310.     /**
  311.      * Retrieve the Compounded Short Rate
  312.      *
  313.      * @return The Compounded Short Rate
  314.      *
  315.      * @throws java.lang.Exception Thrown if the Compounded Short Rate is not available
  316.      */

  317.     public double compoundedShortRate()
  318.         throws java.lang.Exception
  319.     {
  320.         return snapshot().qm (_lslFunding,
  321.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_COMPOUNDED_SHORT_RATE);
  322.     }

  323.     /**
  324.      * Retrieve the Compounded Short Rate Increment
  325.      *
  326.      * @return The Compounded Short Rate Increment
  327.      *
  328.      * @throws java.lang.Exception Thrown if the Compounded Short Rate Increment is not available
  329.      */

  330.     public double compoundedShortRateIncrement()
  331.         throws java.lang.Exception
  332.     {
  333.         return increment().qm (_lslFunding,
  334.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_COMPOUNDED_SHORT_RATE);
  335.     }

  336.     /**
  337.      * Retrieve the Price
  338.      *
  339.      * @return The Price
  340.      *
  341.      * @throws java.lang.Exception Thrown if the Price is not available
  342.      */

  343.     public double price()
  344.         throws java.lang.Exception
  345.     {
  346.         return snapshot().qm (_lslFunding,
  347.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  348.     }

  349.     /**
  350.      * Retrieve the Price Increment
  351.      *
  352.      * @return The Price Increment
  353.      *
  354.      * @throws java.lang.Exception Thrown if the Price Increment is not available
  355.      */

  356.     public double priceIncrement()
  357.         throws java.lang.Exception
  358.     {
  359.         return increment().qm (_lslFunding,
  360.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  361.     }
  362. }