BasisCurve.java

  1. package org.drip.state.basis;

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

  79. /**
  80.  * <i>BasisCurve</i> is the Stub for the Basis between a Pair of Forward Curves.
  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/state/README.md">Latent State Inference and Creation Utilities</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/basis/README.md">Basis State Curve Construction/Estimation</a></li>
  88.  *  </ul>
  89.  * <br><br>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public abstract class BasisCurve implements org.drip.state.basis.BasisEstimator,
  94.     org.drip.analytics.definition.Curve {

  95.     /**
  96.      * Basis Latent State
  97.      */

  98.     public static final java.lang.String LATENT_STATE_BASIS = "LATENT_STATE_BASIS";

  99.     /**
  100.      * Basis Latent State Quantification Metric - Discount Factor
  101.      */

  102.     public static final java.lang.String QUANTIFICATION_METRIC_FORWARD_RATE =
  103.         "QUANTIFICATION_METRIC_FORWARD_RATE";

  104.     private boolean _bBasisOnReference = false;
  105.     private int _iEpochDate = java.lang.Integer.MIN_VALUE;
  106.     private org.drip.state.identifier.ForwardLabel _friDerived = null;
  107.     private org.drip.state.identifier.ForwardLabel _friReference = null;

  108.     protected BasisCurve (
  109.         final int iEpochDate,
  110.         final org.drip.state.identifier.ForwardLabel friReference,
  111.         final org.drip.state.identifier.ForwardLabel friDerived,
  112.         final boolean bBasisOnReference)
  113.         throws java.lang.Exception
  114.     {
  115.         if (null == (_friDerived = friDerived) || null == (_friReference = friReference))
  116.             throw new java.lang.Exception ("BasisCurve ctr: Invalid Inputs");

  117.         _iEpochDate = iEpochDate;
  118.         _bBasisOnReference = bBasisOnReference;
  119.     }

  120.     @Override public org.drip.state.identifier.LatentStateLabel label()
  121.     {
  122.         return org.drip.state.identifier.CustomLabel.Standard (_bBasisOnReference ?
  123.             _friReference.fullyQualifiedName() + "::" + _friDerived.fullyQualifiedName() :
  124.                 _friDerived.fullyQualifiedName() + "::" + _friReference.fullyQualifiedName());
  125.     }

  126.     @Override public java.lang.String currency()
  127.     {
  128.         return _bBasisOnReference ? _friReference.currency() : _friDerived.currency();
  129.     }

  130.     @Override public org.drip.analytics.date.JulianDate epoch()
  131.     {
  132.         try {
  133.             return new org.drip.analytics.date.JulianDate (_iEpochDate);
  134.         } catch (java.lang.Exception e) {
  135.             e.printStackTrace();
  136.         }

  137.         return null;
  138.     }

  139.     @Override public org.drip.state.identifier.ForwardLabel referenceIndex()
  140.     {
  141.         return _friReference;
  142.     }

  143.     @Override public org.drip.state.identifier.ForwardLabel derivedIndex()
  144.     {
  145.         return _friDerived;
  146.     }

  147.     @Override public double basis (
  148.         final org.drip.analytics.date.JulianDate dt)
  149.         throws java.lang.Exception
  150.     {
  151.         if (null == dt) throw new java.lang.Exception ("BasisCurve::basis got null for date");

  152.         return basis (dt.julian());
  153.     }

  154.     @Override public double basis (
  155.         final java.lang.String strTenor)
  156.         throws java.lang.Exception
  157.     {
  158.         if (null == strTenor || strTenor.isEmpty())
  159.             throw new java.lang.Exception ("BasisCurve::basis got bad tenor");

  160.         return basis (epoch().addTenor (strTenor));
  161.     }

  162.     @Override public boolean setCCIS (
  163.         final org.drip.analytics.input.CurveConstructionInputSet ccis)
  164.     {
  165.         return true;
  166.     }

  167.     @Override public org.drip.product.definition.CalibratableComponent[] calibComp()
  168.     {
  169.         return null;
  170.     }

  171.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> manifestMeasure (
  172.         final java.lang.String strInstr)
  173.     {
  174.         return null;
  175.     }

  176.     @Override public org.drip.state.representation.LatentState parallelShiftManifestMeasure (
  177.         final java.lang.String strManifestMeasure,
  178.         final double dblShift)
  179.     {
  180.         return null;
  181.     }

  182.     @Override public org.drip.state.representation.LatentState shiftManifestMeasure (
  183.         final int iSpanIndex,
  184.         final java.lang.String strManifestMeasure,
  185.         final double dblShift)
  186.     {
  187.         return null;
  188.     }

  189.     @Override public org.drip.state.representation.LatentState customTweakManifestMeasure (
  190.         final java.lang.String strManifestMeasure,
  191.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  192.     {
  193.         return null;
  194.     }

  195.     @Override public org.drip.state.representation.LatentState parallelShiftQuantificationMetric (
  196.         final double dblShift)
  197.     {
  198.         return null;
  199.     }

  200.     @Override public org.drip.state.representation.LatentState customTweakQuantificationMetric (
  201.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  202.     {
  203.         return null;
  204.     }

  205.     /**
  206.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the given date
  207.      *
  208.      * @param strManifestMeasure Manifest Measure
  209.      * @param dblDate Date
  210.      *
  211.      * @return The Manifest Measure Jacobian of the Forward Rate to the given date
  212.      */

  213.     public abstract org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  214.         final java.lang.String strManifestMeasure,
  215.         final int dblDate);

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

  224.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  225.         final java.lang.String strManifestMeasure,
  226.         final org.drip.analytics.date.JulianDate dt)
  227.     {
  228.         if (null == dt) return null;

  229.         return jackDForwardDManifestMeasure (strManifestMeasure, dt.julian());
  230.     }

  231.     /**
  232.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  233.      *
  234.      * @param strManifestMeasure Manifest Measure
  235.      * @param strTenor Tenor
  236.      *
  237.      * @return The Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  238.      */

  239.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  240.         final java.lang.String strManifestMeasure,
  241.         final java.lang.String strTenor)
  242.     {
  243.         if (null == strTenor || strTenor.isEmpty()) return null;

  244.         try {
  245.             return jackDForwardDManifestMeasure (strManifestMeasure, epoch().addTenor (strTenor));
  246.         } catch (java.lang.Exception e) {
  247.             e.printStackTrace();
  248.         }

  249.         return null;
  250.     }
  251. }