BGMCurveUpdate.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>BGMCurveUpdate</i> contains the Instantaneous Snapshot of the Evolving Discount Curve 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 BGMCurveUpdate extends org.drip.dynamics.evolution.LSQMCurveUpdate {
  93.     private org.drip.state.identifier.ForwardLabel _lslForward = null;
  94.     private org.drip.state.identifier.FundingLabel _lslFunding = null;
  95.     private org.drip.dynamics.lmm.LognormalLIBORVolatility _llv = null;

  96.     /**
  97.      * Construct an Instance of BGMCurveUpdate
  98.      *
  99.      * @param lslFunding The Funding Latent State Label
  100.      * @param lslForward The Forward Latent State Label
  101.      * @param iInitialDate The Initial Date
  102.      * @param iFinalDate The Final Date
  103.      * @param fc The LIBOR Forward Curve Snapshot
  104.      * @param spanLIBORIncrement The LIBOR Forward Curve Span Increment
  105.      * @param dc The Discount Factor Discount Curve
  106.      * @param spanDiscountFactorIncrement The Discount Factor Discount Curve Span Increment
  107.      * @param spanContinuousForwardRateIncrement The Continuous Forward Rate Discount Curve Span Increment
  108.      * @param spanSpotRateIncrement The Spot Rate Discount Curve Span Increment
  109.      * @param spanInstantaneousEffectiveForward The Instantaneous Effective Forward Rate Span
  110.      * @param spanInstantaneousNominalForward The Instantaneous Nominal Forward Rate Span
  111.      * @param llv The Log-normal LIBOR Rate Volatility
  112.      *
  113.      * @return Instance of BGMCurveUpdate
  114.      */

  115.     public static final BGMCurveUpdate Create (
  116.         final org.drip.state.identifier.FundingLabel lslFunding,
  117.         final org.drip.state.identifier.ForwardLabel lslForward,
  118.         final int iInitialDate,
  119.         final int iFinalDate,
  120.         final org.drip.state.forward.ForwardCurve fc,
  121.         final org.drip.spline.grid.Span spanLIBORIncrement,
  122.         final org.drip.state.discount.MergedDiscountForwardCurve dc,
  123.         final org.drip.spline.grid.Span spanDiscountFactorIncrement,
  124.         final org.drip.spline.grid.Span spanContinuousForwardRateIncrement,
  125.         final org.drip.spline.grid.Span spanSpotRateIncrement,
  126.         final org.drip.spline.grid.Span spanInstantaneousEffectiveForward,
  127.         final org.drip.spline.grid.Span spanInstantaneousNominalForward,
  128.         final org.drip.dynamics.lmm.LognormalLIBORVolatility llv)
  129.     {
  130.         org.drip.dynamics.evolution.LSQMCurveSnapshot snapshot = new
  131.             org.drip.dynamics.evolution.LSQMCurveSnapshot();

  132.         if (!snapshot.setQMCurve (org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE, fc))
  133.             return null;

  134.         if (!snapshot.setQMCurve
  135.             (org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR, dc))
  136.             return null;

  137.         org.drip.dynamics.evolution.LSQMCurveIncrement increment = new
  138.             org.drip.dynamics.evolution.LSQMCurveIncrement();

  139.         if (null != spanLIBORIncrement && !increment.setQMSpan (lslForward,
  140.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE, spanLIBORIncrement))
  141.             return null;

  142.         if (null != spanContinuousForwardRateIncrement && !increment.setQMSpan (lslForward,
  143.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE,
  144.                 spanContinuousForwardRateIncrement))
  145.             return null;

  146.         if (null != spanDiscountFactorIncrement && !increment.setQMSpan (lslFunding,
  147.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR,
  148.                 spanDiscountFactorIncrement))
  149.             return null;

  150.         if (null != spanSpotRateIncrement && !increment.setQMSpan (lslFunding,
  151.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE, spanSpotRateIncrement))
  152.             return null;

  153.         if (null != spanInstantaneousEffectiveForward && !increment.setQMSpan (lslForward,
  154.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_EFFECTIVE_FORWARD_RATE,
  155.                 spanInstantaneousEffectiveForward))
  156.             return null;

  157.         if (null != spanInstantaneousNominalForward && !increment.setQMSpan (lslForward,
  158.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_NOMINAL_FORWARD_RATE,
  159.                 spanInstantaneousNominalForward))
  160.             return null;

  161.         try {
  162.             return new BGMCurveUpdate (lslFunding, lslForward, iInitialDate, iFinalDate, snapshot, increment,
  163.                 llv);
  164.         } catch (java.lang.Exception e) {
  165.             e.printStackTrace();
  166.         }

  167.         return null;
  168.     }

  169.     private BGMCurveUpdate (
  170.         final org.drip.state.identifier.FundingLabel lslFunding,
  171.         final org.drip.state.identifier.ForwardLabel lslForward,
  172.         final int iInitialDate,
  173.         final int iFinalDate,
  174.         final org.drip.dynamics.evolution.LSQMCurveSnapshot snapshot,
  175.         final org.drip.dynamics.evolution.LSQMCurveIncrement increment,
  176.         final org.drip.dynamics.lmm.LognormalLIBORVolatility llv)
  177.         throws java.lang.Exception
  178.     {
  179.         super (iInitialDate, iFinalDate, snapshot, increment);

  180.         if (null == (_lslFunding = lslFunding) || null == (_lslForward = lslForward) || null == (_llv = llv))
  181.             throw new java.lang.Exception ("BGMCurveUpdate ctr: Invalid Inputs");
  182.     }

  183.     /**
  184.      * Retrieve the LIBOR Forward Curve
  185.      *
  186.      * @return The LIBOR Forward Curve
  187.      */

  188.     public org.drip.state.forward.ForwardCurve forwardCurve()
  189.     {
  190.         return (org.drip.state.forward.ForwardCurve) snapshot().qm (_lslForward,
  191.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE);
  192.     }

  193.     /**
  194.      * Retrieve the LIBOR Forward Curve Increment Span
  195.      *
  196.      * @return The LIBOR Forward Curve Increment Span
  197.      */

  198.     public org.drip.spline.grid.Span forwardCurveIncrement()
  199.     {
  200.         return increment().span (_lslForward,
  201.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_LIBOR_RATE);
  202.     }

  203.     /**
  204.      * Retrieve the Instantaneous Continuously Compounded Forward Curve Increment Span
  205.      *
  206.      * @return The Instantaneous Continuously Compounded Forward Curve Increment Span
  207.      */

  208.     public org.drip.spline.grid.Span continuousForwardRateIncrement()
  209.     {
  210.         return increment().span (_lslForward,
  211.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_CONTINUOUSLY_COMPOUNDED_FORWARD_RATE);
  212.     }

  213.     /**
  214.      * Retrieve the Instantaneous Effective Annual Forward Rate Span
  215.      *
  216.      * @return The Instantaneous Effective Annual Forward Rate Span
  217.      */

  218.     public org.drip.spline.grid.Span instantaneousEffectiveForwardRate()
  219.     {
  220.         return increment().span (_lslForward,
  221.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_EFFECTIVE_FORWARD_RATE);
  222.     }

  223.     /**
  224.      * Retrieve the Instantaneous Nominal Annual Forward Rate Span
  225.      *
  226.      * @return The Instantaneous Nominal Annual Forward Rate Span
  227.      */

  228.     public org.drip.spline.grid.Span instantaneousNominalForwardRate()
  229.     {
  230.         return increment().span (_lslForward,
  231.             org.drip.analytics.definition.LatentStateStatic.FORWARD_QM_INSTANTANEOUS_NOMINAL_FORWARD_RATE);
  232.     }

  233.     /**
  234.      * Retrieve the Discount Factor Curve
  235.      *
  236.      * @return The Discount Factor Curve
  237.      */

  238.     public org.drip.state.discount.MergedDiscountForwardCurve discountCurve()
  239.     {
  240.         return (org.drip.state.discount.MergedDiscountForwardCurve) snapshot().qm (_lslFunding,
  241.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  242.     }

  243.     /**
  244.      * Retrieve the Discount Factor Discount Curve Increment
  245.      *
  246.      * @return The Discount Factor Discount Curve Increment
  247.      */

  248.     public org.drip.spline.grid.Span discountCurveIncrement()
  249.     {
  250.         return increment().span (_lslFunding,
  251.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_DISCOUNT_FACTOR);
  252.     }

  253.     /**
  254.      * Retrieve the Spot Rate Discount Curve Increment
  255.      *
  256.      * @return The Spot Rate Discount Curve Increment
  257.      */

  258.     public org.drip.spline.grid.Span spotRateIncrement()
  259.     {
  260.         return increment().span (_lslFunding,
  261.             org.drip.analytics.definition.LatentStateStatic.DISCOUNT_QM_ZERO_RATE);
  262.     }

  263.     /**
  264.      * Retrieve the Log-normal LIBOR Volatility Instance
  265.      *
  266.      * @return The Log-normal LIBOR Volatility Instance
  267.      */

  268.     public org.drip.dynamics.lmm.LognormalLIBORVolatility lognormalLIBORVolatility()
  269.     {
  270.         return _llv;
  271.     }
  272. }