BGMPointUpdate.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>BGMPointUpdate</i> contains the Instantaneous Snapshot of the Evolving Discount Point Latent State
  80.  * Quantification Metrics Updated using the BGM LIBOR Update Dynamics.
  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/lmm/README.md">LMM Based Latent State Evolution</a></li>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class BGMPointUpdate 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.     private double _dblLognormalLIBORVolatility = java.lang.Double.NaN;
  96.     private double _dblContinuouslyCompoundedForwardVolatility = java.lang.Double.NaN;

  97.     /**
  98.      * Construct an Instance of BGMPointUpdate
  99.      *
  100.      * @param lslFunding The Funding Latent State Label
  101.      * @param lslForward The Forward Latent State Label
  102.      * @param iInitialDate The Initial Date
  103.      * @param iFinalDate The Final Date
  104.      * @param iTargetPointDate The Target Point Date
  105.      * @param dblLIBOR The LIBOR Rate
  106.      * @param dblLIBORIncrement The LIBOR Rate Increment
  107.      * @param dblContinuousForwardRate The Continuously Compounded Forward Rate
  108.      * @param dblContinuousForwardRateIncrement The Continuously Compounded Forward Rate Increment
  109.      * @param dblSpotRate The Spot Rate
  110.      * @param dblSpotRateIncrement The Spot Rate Increment
  111.      * @param dblDiscountFactor The Discount Factor
  112.      * @param dblDiscountFactorIncrement The Discount Factor Increment
  113.      * @param dblInstantaneousEffectiveForwardRate Instantaneous Effective Annual Forward Rate
  114.      * @param dblInstantaneousNominalForwardRate Instantaneous Nominal Annual Forward Rate
  115.      * @param dblLognormalLIBORVolatility The Log-normal LIBOR Rate Volatility
  116.      * @param dblContinuouslyCompoundedForwardVolatility The Continuously Compounded Forward Rate Volatility
  117.      *
  118.      * @return Instance of BGMPointUpdate
  119.      */

  120.     public static final BGMPointUpdate Create (
  121.         final org.drip.state.identifier.FundingLabel lslFunding,
  122.         final org.drip.state.identifier.ForwardLabel lslForward,
  123.         final int iInitialDate,
  124.         final int iFinalDate,
  125.         final int iTargetPointDate,
  126.         final double dblLIBOR,
  127.         final double dblLIBORIncrement,
  128.         final double dblContinuousForwardRate,
  129.         final double dblContinuousForwardRateIncrement,
  130.         final double dblSpotRate,
  131.         final double dblSpotRateIncrement,
  132.         final double dblDiscountFactor,
  133.         final double dblDiscountFactorIncrement,
  134.         final double dblInstantaneousEffectiveForwardRate,
  135.         final double dblInstantaneousNominalForwardRate,
  136.         final double dblLognormalLIBORVolatility,
  137.         final double dblContinuouslyCompoundedForwardVolatility)
  138.     {
  139.         org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot = new
  140.             org.drip.dynamics.evolution.LSQMPointRecord();

  141.         if (!lrSnapshot.setQM (lslForward,
  142.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE, dblLIBOR))
  143.             return null;

  144.         if (!lrSnapshot.setQM (lslForward,
  145.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE,
  146.                 dblContinuousForwardRate))
  147.             return null;

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

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

  156.         if (!lrSnapshot.setQM (lslFunding,
  157.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, dblSpotRate))
  158.             return null;

  159.         if (!lrSnapshot.setQM (lslFunding,
  160.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR, dblDiscountFactor))
  161.             return null;

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

  164.         if (!lrIncrement.setQM (lslForward,
  165.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE, dblLIBORIncrement))
  166.             return null;

  167.         if (!lrIncrement.setQM (lslForward,
  168.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE,
  169.                 dblContinuousForwardRateIncrement))
  170.             return null;

  171.         if (!lrIncrement.setQM (lslFunding,
  172.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, dblSpotRateIncrement))
  173.             return null;

  174.         if (!lrIncrement.setQM (lslFunding,
  175.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  176.                 dblDiscountFactorIncrement))
  177.             return null;

  178.         try {
  179.             return new BGMPointUpdate (lslFunding, lslForward, iInitialDate, iFinalDate, iTargetPointDate,
  180.                 lrSnapshot, lrIncrement, dblLognormalLIBORVolatility,
  181.                     dblContinuouslyCompoundedForwardVolatility);
  182.         } catch (java.lang.Exception e) {
  183.             e.printStackTrace();
  184.         }

  185.         return null;
  186.     }

  187.     private BGMPointUpdate (
  188.         final org.drip.state.identifier.FundingLabel lslFunding,
  189.         final org.drip.state.identifier.ForwardLabel lslForward,
  190.         final int iInitialDate,
  191.         final int iFinalDate,
  192.         final int iViewDate,
  193.         final org.drip.dynamics.evolution.LSQMPointRecord lrSnapshot,
  194.         final org.drip.dynamics.evolution.LSQMPointRecord lrIncrement,
  195.         final double dblLognormalLIBORVolatility,
  196.         final double dblContinuouslyCompoundedForwardVolatility)
  197.         throws java.lang.Exception
  198.     {
  199.         super (iInitialDate, iFinalDate, iViewDate, lrSnapshot, lrIncrement);

  200.         if (null == (_lslFunding = lslFunding) || null == (_lslForward = lslForward) ||
  201.             !org.drip.numerical.common.NumberUtil.IsValid (_dblLognormalLIBORVolatility =
  202.                 dblLognormalLIBORVolatility) || !org.drip.numerical.common.NumberUtil.IsValid
  203.                     (_dblContinuouslyCompoundedForwardVolatility =
  204.                         dblContinuouslyCompoundedForwardVolatility))
  205.             throw new java.lang.Exception ("BGMPointUpdate ctr: Invalid Inputs");
  206.     }

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

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

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

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

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

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

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

  254.     public double continuousForwardRateIncrement()
  255.         throws java.lang.Exception
  256.     {
  257.         return increment().qm (_lslForward,
  258.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE);
  259.     }

  260.     /**
  261.      * Retrieve the Instantaneous Effective Annual Forward Rate
  262.      *
  263.      * @return The Instantaneous Effective Annual Forward Rate
  264.      *
  265.      * @throws java.lang.Exception Thrown if the Instantaneous Effective Annual Forward Rate is not available
  266.      */

  267.     public double instantaneousEffectiveForwardRate()
  268.         throws java.lang.Exception
  269.     {
  270.         return snapshot().qm (_lslForward,
  271.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_EFFECTIVE_FORWARD_RATE);
  272.     }

  273.     /**
  274.      * Retrieve the Instantaneous Nominal Annual Forward Rate
  275.      *
  276.      * @return The Instantaneous Nominal Annual Forward Rate
  277.      *
  278.      * @throws java.lang.Exception Thrown if the Instantaneous Nominal Annual Forward Rate is not available
  279.      */

  280.     public double instantaneousNominalForwardRate()
  281.         throws java.lang.Exception
  282.     {
  283.         return snapshot().qm (_lslForward,
  284.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_NOMINAL_FORWARD_RATE);
  285.     }

  286.     /**
  287.      * Retrieve the Spot Rate
  288.      *
  289.      * @return The Spot Rate
  290.      *
  291.      * @throws java.lang.Exception Thrown if the Spot Rate is not available
  292.      */

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

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

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

  312.     /**
  313.      * Retrieve the Discount Factor
  314.      *
  315.      * @return The Discount Factor
  316.      *
  317.      * @throws java.lang.Exception Thrown if the Discount Factor is not available
  318.      */

  319.     public double discountFactor()
  320.         throws java.lang.Exception
  321.     {
  322.         return snapshot().qm (_lslFunding,
  323.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  324.     }

  325.     /**
  326.      * Retrieve the Discount Factor Increment
  327.      *
  328.      * @return The Discount Factor Increment
  329.      *
  330.      * @throws java.lang.Exception Thrown if the Discount Factor Increment is not available
  331.      */

  332.     public double discountFactorIncrement()
  333.         throws java.lang.Exception
  334.     {
  335.         return increment().qm (_lslFunding,
  336.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  337.     }

  338.     /**
  339.      * Retrieve the Log-normal LIBOR Volatility
  340.      *
  341.      * @return The Log-normal LIBOR Volatility
  342.      */

  343.     public double lognormalLIBORVolatility()
  344.     {
  345.         return _dblLognormalLIBORVolatility;
  346.     }

  347.     /**
  348.      * Retrieve the Continuously Compounded Forward Rate Volatility
  349.      *
  350.      * @return The Continuously Compounded Forward Rate Volatility
  351.      */

  352.     public double continuouslyCompoundedForwardVolatility()
  353.     {
  354.         return _dblContinuouslyCompoundedForwardVolatility;
  355.     }
  356. }