BGMTenorNodeSequence.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>BGMTenorNodeSequence</i> contains the Point Nodes of the Latent State Quantifiers and their Increments
  80.  * present in the specified BGMForwardTenorSnap Instance. 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 BGMTenorNodeSequence {
  109.     private int[] _aiDate = null;
  110.     private double[] _adblLIBOR = null;
  111.     private double[] _adblLIBORIncrement = null;
  112.     private double[] _adblDiscountFactor = null;
  113.     private double[] _adblSpotRateIncrement = null;
  114.     private double[] _adblDiscountFactorIncrement = null;
  115.     private double[] _adblContinuousForwardRateIncrement = null;
  116.     private double[] _adblInstantaneousNominalForwardRate = null;
  117.     private double[] _adblInstantaneousEffectiveForwardRate = null;

  118.     /**
  119.      * BGMTenorNodeSequence Constructor
  120.      *
  121.      * @param aBFTS Array of the BGM Forward Tenor Snap Instances
  122.      *
  123.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  124.      */

  125.     public BGMTenorNodeSequence (
  126.         final org.drip.dynamics.lmm.BGMForwardTenorSnap[] aBFTS)
  127.         throws java.lang.Exception
  128.     {
  129.         if (null == aBFTS) throw new java.lang.Exception ("BGMTenorNodeSequence ctr: Invalid Inputs!");

  130.         int iNumSnap = aBFTS.length;
  131.         _aiDate = new int[iNumSnap];
  132.         _adblLIBOR = new double[iNumSnap];
  133.         _adblLIBORIncrement = new double[iNumSnap];
  134.         _adblDiscountFactor = new double[iNumSnap];
  135.         _adblSpotRateIncrement = new double[iNumSnap];
  136.         _adblDiscountFactorIncrement = new double[iNumSnap];
  137.         _adblContinuousForwardRateIncrement = new double[iNumSnap];
  138.         _adblInstantaneousNominalForwardRate = new double[iNumSnap];
  139.         _adblInstantaneousEffectiveForwardRate = new double[iNumSnap];

  140.         if (0 == iNumSnap) throw new java.lang.Exception ("BGMTenorNodeSequence ctr: Invalid Inputs!");

  141.         for (int i = 0; i < iNumSnap; ++i) {
  142.             _aiDate[i] = aBFTS[i].date();

  143.             _adblLIBOR[i] = aBFTS[i].libor();

  144.             _adblLIBORIncrement[i] = aBFTS[i].liborIncrement();

  145.             _adblDiscountFactor[i] = aBFTS[i].discountFactor();

  146.             _adblSpotRateIncrement[i] = aBFTS[i].spotRateIncrement();

  147.             _adblDiscountFactorIncrement[i] = aBFTS[i].discountFactorIncrement();

  148.             _adblInstantaneousNominalForwardRate[i] = aBFTS[i].instantaneousNominalForwardRate();

  149.             _adblInstantaneousEffectiveForwardRate[i] = aBFTS[i].instantaneousEffectiveForwardRate();

  150.             _adblContinuousForwardRateIncrement[i] = aBFTS[i].continuouslyCompoundedForwardIncrement();
  151.         }
  152.     }

  153.     /**
  154.      * Retrieve the Array of Tenor Dates
  155.      *
  156.      * @return The Array of Tenor Dates
  157.      */

  158.     public int[] dates()
  159.     {
  160.         return _aiDate;
  161.     }

  162.     /**
  163.      * Retrieve the Array of Tenor LIBOR Rates
  164.      *
  165.      * @return The Array of Tenor LIBOR Rates
  166.      */

  167.     public double[] liborRates()
  168.     {
  169.         return _adblLIBOR;
  170.     }

  171.     /**
  172.      * Retrieve the Array of Tenor LIBOR Rate Increments
  173.      *
  174.      * @return The Array of Tenor LIBOR Rate Increments
  175.      */

  176.     public double[] liborRateIncrements()
  177.     {
  178.         return _adblLIBORIncrement;
  179.     }

  180.     /**
  181.      * Retrieve the Array of Tenor Discount Factors
  182.      *
  183.      * @return The Array of Tenor Discount Factors
  184.      */

  185.     public double[] discountFactors()
  186.     {
  187.         return _adblDiscountFactor;
  188.     }

  189.     /**
  190.      * Retrieve the Array of Tenor Discount Factor Increments
  191.      *
  192.      * @return The Array of Tenor Discount Factor Increments
  193.      */

  194.     public double[] discountFactorIncrements()
  195.     {
  196.         return _adblDiscountFactorIncrement;
  197.     }

  198.     /**
  199.      * Retrieve the Array of Tenor Instantaneous Effective Annual Forward Rate
  200.      *
  201.      * @return The Array of Tenor Instantaneous Effective Annual Forward Rate
  202.      */

  203.     public double[] instantaneousEffectiveForwardRates()
  204.     {
  205.         return _adblInstantaneousEffectiveForwardRate;
  206.     }

  207.     /**
  208.      * Retrieve the Array of Tenor Instantaneous Nominal Annual Forward Rate
  209.      *
  210.      * @return The Array of Tenor Instantaneous Nominal Annual Forward Rate
  211.      */

  212.     public double[] instantaneousNominalForwardRates()
  213.     {
  214.         return _adblInstantaneousNominalForwardRate;
  215.     }

  216.     /**
  217.      * Retrieve the Array of Tenor Instantaneous Continuously Compounded Forward Rate Increments
  218.      *
  219.      * @return The Array of Tenor Instantaneous Continuously Compounded Forward Rate Increments
  220.      */

  221.     public double[] continuousForwardRateIncrements()
  222.     {
  223.         return _adblContinuousForwardRateIncrement;
  224.     }

  225.     /**
  226.      * Retrieve the Array of Tenor Spot Rate Increments
  227.      *
  228.      * @return The Array of Tenor Spot Rate Increments
  229.      */

  230.     public double[] spotRateIncrements()
  231.     {
  232.         return _adblSpotRateIncrement;
  233.     }

  234.     @Override public java.lang.String toString()
  235.     {
  236.         int iNumTenor = _aiDate.length;
  237.         java.lang.String strDateDump = "\t |";
  238.         java.lang.String strPartition = "\t |";
  239.         java.lang.String strLIBORDump = "\t |";
  240.         java.lang.String strLIBORIncrementDump = "\t |";
  241.         java.lang.String strDiscountFactorDump = "\t |";
  242.         java.lang.String strSpotRateIncrementDump = "\t |";
  243.         java.lang.String strDiscountFactorIncrementDump = "\t |";
  244.         java.lang.String strContinuousForwardIncrementDump = "\t |";
  245.         java.lang.String strInstantaneousNominalForwardDump = "\t |";
  246.         java.lang.String strInstantaneousEffectiveForwardDump = "\t |";

  247.         for (int i = 0; i < iNumTenor; ++i) {
  248.             strPartition += "-------------";

  249.             strDateDump += " " + new org.drip.analytics.date.JulianDate (_aiDate[i]) + " |";

  250.             strLIBORDump += "  " + org.drip.numerical.common.FormatUtil.FormatDouble (_adblLIBOR[i], 1, 3, 100.)
  251.                 + "%   |";

  252.             strLIBORIncrementDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  253.                 (_adblLIBORIncrement[i], 2, 0, 10000.) + "     |";

  254.             strDiscountFactorDump += "  " + org.drip.numerical.common.FormatUtil.FormatDouble
  255.                 (_adblDiscountFactor[i], 2, 3, 100.) + "   |";

  256.             strDiscountFactorIncrementDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  257.                 (_adblDiscountFactorIncrement[i], 2, 0, 10000.) + "     |";

  258.             strContinuousForwardIncrementDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  259.                 (_adblContinuousForwardRateIncrement[i], 2, 0, 10000.) + "     |";

  260.             strSpotRateIncrementDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  261.                 (_adblSpotRateIncrement[i], 2, 0, 10000.) + "     |";

  262.             strInstantaneousEffectiveForwardDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  263.                 (_adblInstantaneousEffectiveForwardRate[i], 2, 0, 10000.) + "     |";

  264.             strInstantaneousNominalForwardDump += "    " + org.drip.numerical.common.FormatUtil.FormatDouble
  265.                 (_adblInstantaneousNominalForwardRate[i], 2, 0, 10000.) + "     |";
  266.         }

  267.         return "\n" + strPartition + "|\n" + strDateDump + "|\n" + strPartition + "|\n" + strLIBORDump +
  268.             "|\n" + strLIBORIncrementDump + "|\n" + strDiscountFactorDump + "|\n" +
  269.                 strDiscountFactorIncrementDump + "|\n" + strContinuousForwardIncrementDump + "|\n" +
  270.                     strSpotRateIncrementDump + "|\n" + strInstantaneousEffectiveForwardDump + "|\n" +
  271.                         strInstantaneousNominalForwardDump + "|\n" + strPartition + "|\n";
  272.     }
  273. }