ForwardCurve.java

  1. package org.drip.state.forward;

  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.  * Copyright (C) 2014 Lakshmi Krishnamurthy
  13.  * Copyright (C) 2013 Lakshmi Krishnamurthy
  14.  *
  15.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  16.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  17.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  18.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  19.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  20.  *      and computational support.
  21.  *  
  22.  *      https://lakshmidrip.github.io/DROP/
  23.  *  
  24.  *  DROP is composed of three modules:
  25.  *  
  26.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  27.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  28.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  29.  *
  30.  *  DROP Product Core implements libraries for the following:
  31.  *  - Fixed Income Analytics
  32.  *  - Loan Analytics
  33.  *  - Transaction Cost Analytics
  34.  *
  35.  *  DROP Portfolio Core implements libraries for the following:
  36.  *  - Asset Allocation Analytics
  37.  *  - Asset Liability Management Analytics
  38.  *  - Capital Estimation Analytics
  39.  *  - Exposure Analytics
  40.  *  - Margin Analytics
  41.  *  - XVA Analytics
  42.  *
  43.  *  DROP Computational Core implements libraries for the following:
  44.  *  - Algorithm Support
  45.  *  - Computation Support
  46.  *  - Function Analysis
  47.  *  - Model Validation
  48.  *  - Numerical Analysis
  49.  *  - Numerical Optimizer
  50.  *  - Spline Builder
  51.  *  - Statistical Learning
  52.  *
  53.  *  Documentation for DROP is Spread Over:
  54.  *
  55.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  56.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  57.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  58.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  59.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  60.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  61.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  62.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  63.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  64.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  65.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  66.  *
  67.  *  Licensed under the Apache License, Version 2.0 (the "License");
  68.  *      you may not use this file except in compliance with the License.
  69.  *  
  70.  *  You may obtain a copy of the License at
  71.  *      http://www.apache.org/licenses/LICENSE-2.0
  72.  *  
  73.  *  Unless required by applicable law or agreed to in writing, software
  74.  *      distributed under the License is distributed on an "AS IS" BASIS,
  75.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  76.  *  
  77.  *  See the License for the specific language governing permissions and
  78.  *      limitations under the License.
  79.  */

  80. /**
  81.  * <i>ForwardCurve</i> is the stub for the forward curve functionality. It extends the Curve object by
  82.  * exposing the following functions:
  83.  *
  84.  *  <br><br>
  85.  *  <ul>
  86.  *      <li>
  87.  *          The name/epoch of the forward rate instance
  88.  *      </li>
  89.  *      <li>
  90.  *          The index/currency/tenor associated with the forward rate instance
  91.  *      </li>
  92.  *      <li>
  93.  *          Forward Rate to a specific date/tenor
  94.  *      </li>
  95.  *      <li>
  96.  *          Generate scenario tweaked Latent State from the base forward curve corresponding to mode adjusted
  97.  *              (flat/parallel/custom) manifest measure/quantification metric
  98.  *      </li>
  99.  *      <li>
  100.  *          Retrieve array of latent state manifest measure, instrument quantification metric, and the array
  101.  *              of calibration components
  102.  *      </li>
  103.  *      <li>
  104.  *          Set/retrieve curve construction input instrument sets
  105.  *      </li>
  106.  *  </ul>
  107.  *
  108.  *  <br><br>
  109.  *  <ul>
  110.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  111.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  112.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/README.md">Latent State Inference and Creation Utilities</a></li>
  113.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/forward/README.md">Forward Latent State Curve Estimator</a></li>
  114.  *  </ul>
  115.  * <br><br>
  116.  *
  117.  * @author Lakshmi Krishnamurthy
  118.  */

  119. public abstract class ForwardCurve implements org.drip.state.forward.ForwardRateEstimator,
  120.     org.drip.analytics.definition.Curve {

  121.     private int _iEpochDate = java.lang.Integer.MIN_VALUE;
  122.     private org.drip.state.identifier.ForwardLabel _fri = null;

  123.     protected ForwardCurve (
  124.         final int iEpochDate,
  125.         final org.drip.state.identifier.ForwardLabel fri)
  126.         throws java.lang.Exception
  127.     {
  128.         if (null == (_fri = fri)) throw new java.lang.Exception ("ForwardCurve ctr: Invalid Inputs");

  129.         _iEpochDate = iEpochDate;
  130.     }

  131.     @Override public org.drip.state.identifier.LatentStateLabel label()
  132.     {
  133.         return _fri;
  134.     }

  135.     @Override public java.lang.String currency()
  136.     {
  137.         return _fri.currency();
  138.     }

  139.     @Override public org.drip.analytics.date.JulianDate epoch()
  140.     {
  141.         try {
  142.             return new org.drip.analytics.date.JulianDate (_iEpochDate);
  143.         } catch (java.lang.Exception e) {
  144.             e.printStackTrace();
  145.         }

  146.         return null;
  147.     }

  148.     @Override public java.lang.String tenor()
  149.     {
  150.         return _fri.tenor();
  151.     }

  152.     @Override public org.drip.state.identifier.ForwardLabel index()
  153.     {
  154.         return _fri;
  155.     }

  156.     @Override public double forward (
  157.         final org.drip.analytics.date.JulianDate dt)
  158.         throws java.lang.Exception
  159.     {
  160.         if (null == dt) throw new java.lang.Exception ("ForwardRate::forward got null for date");

  161.         return forward (dt.julian());
  162.     }

  163.     @Override public double forward (
  164.         final java.lang.String strTenor)
  165.         throws java.lang.Exception
  166.     {
  167.         if (null == strTenor || strTenor.isEmpty())
  168.             throw new java.lang.Exception ("ForwardRate::forward got bad tenor");

  169.         return forward (epoch().addTenor (strTenor));
  170.     }

  171.     @Override public boolean setCCIS (
  172.         final org.drip.analytics.input.CurveConstructionInputSet ccis)
  173.     {
  174.         return true;
  175.     }

  176.     @Override public org.drip.product.definition.CalibratableComponent[] calibComp()
  177.     {
  178.         return null;
  179.     }

  180.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> manifestMeasure (
  181.         final java.lang.String strInstrumentCode)
  182.     {
  183.         return null;
  184.     }

  185.     @Override public org.drip.state.representation.LatentState parallelShiftManifestMeasure (
  186.         final java.lang.String strManifestMeasure,
  187.         final double dblShift)
  188.     {
  189.         return null;
  190.     }

  191.     @Override public org.drip.state.representation.LatentState shiftManifestMeasure (
  192.         final int iSpanIndex,
  193.         final java.lang.String strManifestMeasure,
  194.         final double dblShift)
  195.     {
  196.         return null;
  197.     }

  198.     @Override public org.drip.state.representation.LatentState customTweakManifestMeasure (
  199.         final java.lang.String strManifestMeasure,
  200.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  201.     {
  202.         return null;
  203.     }

  204.     @Override public org.drip.state.representation.LatentState parallelShiftQuantificationMetric (
  205.         final double dblShift)
  206.     {
  207.         return null;
  208.     }

  209.     @Override public org.drip.state.representation.LatentState customTweakQuantificationMetric (
  210.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  211.     {
  212.         return null;
  213.     }

  214.     /**
  215.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the given date
  216.      *
  217.      * @param strManifestMeasure Manifest Measure
  218.      * @param dblDate Date
  219.      *
  220.      * @return The Manifest Measure Jacobian of the Forward Rate to the given date
  221.      */

  222.     public abstract org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  223.         final java.lang.String strManifestMeasure,
  224.         final int dblDate);

  225.     /**
  226.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the given date
  227.      *
  228.      * @param strManifestMeasure Manifest Measure
  229.      * @param dt Date
  230.      *
  231.      * @return The Manifest Measure Jacobian of the Forward Rate to the given date
  232.      */

  233.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  234.         final java.lang.String strManifestMeasure,
  235.         final org.drip.analytics.date.JulianDate dt)
  236.     {
  237.         if (null == dt) return null;

  238.         return jackDForwardDManifestMeasure (strManifestMeasure, dt.julian());
  239.     }

  240.     /**
  241.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  242.      *
  243.      * @param strManifestMeasure Manifest Measure
  244.      * @param strTenor Tenor
  245.      *
  246.      * @return The Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  247.      */

  248.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  249.         final java.lang.String strManifestMeasure,
  250.         final java.lang.String strTenor)
  251.     {
  252.         if (null == strTenor || strTenor.isEmpty()) return null;

  253.         try {
  254.             return jackDForwardDManifestMeasure (strManifestMeasure, epoch().addTenor (strTenor));
  255.         } catch (java.lang.Exception e) {
  256.             e.printStackTrace();
  257.         }

  258.         return null;
  259.     }
  260. }