FXCurve.java

  1. package org.drip.state.fx;

  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>FXCurve</i> is the Stub for the FX Curve for the specified Currency Pair.
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  84.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  85.  *      <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>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/fx/README.md">FX Latent State Curve Estimator</a></li>
  87.  *  </ul>
  88.  * <br><br>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public abstract class FXCurve implements org.drip.analytics.definition.Curve {
  93.     private org.drip.product.params.CurrencyPair _cp = null;

  94.     protected int _iEpochDate = java.lang.Integer.MIN_VALUE;

  95.     protected FXCurve (
  96.         final int iEpochDate,
  97.         final org.drip.product.params.CurrencyPair cp)
  98.         throws java.lang.Exception
  99.     {
  100.         if (null == (_cp = cp)) throw new java.lang.Exception ("FXCurve ctr: Invalid Inputs");

  101.         _iEpochDate = iEpochDate;
  102.     }

  103.     /**
  104.      * Calculate the FX Forward to the given Date
  105.      *
  106.      * @param iDate Date
  107.      *
  108.      * @return The FX Forward
  109.      *
  110.      * @throws java.lang.Exception Thrown if the FX Forward cannot be calculated
  111.      */

  112.     public abstract double fx (
  113.         final int iDate)
  114.         throws java.lang.Exception;

  115.     /**
  116.      * Calculate the set of Zero basis given the input discount curves
  117.      *
  118.      * @param aiDateNode Array of Date Nodes
  119.      * @param valParams Valuation Parameters
  120.      * @param dcNum Discount Curve Numerator
  121.      * @param dcDenom Discount Curve Denominator
  122.      * @param bBasisOnDenom True if the basis is calculated on the denominator discount curve
  123.      *
  124.      * @return Array of the computed basis
  125.      */

  126.     public abstract double[] zeroBasis (
  127.         final int[] aiDateNode,
  128.         final org.drip.param.valuation.ValuationParams valParams,
  129.         final org.drip.state.discount.MergedDiscountForwardCurve dcNum,
  130.         final org.drip.state.discount.MergedDiscountForwardCurve dcDenom,
  131.         final boolean bBasisOnDenom);

  132.     /**
  133.      * Bootstrap the basis to the discount curve inputs
  134.      *
  135.      * @param aiDateNode Array of Date Nodes
  136.      * @param valParams Valuation Parameters
  137.      * @param dcNum Discount Curve Numerator
  138.      * @param dcDenom Discount Curve Denominator
  139.      * @param bBasisOnDenom True if the basis is calculated on the denominator discount curve
  140.      *
  141.      * @return Array of the computed basis
  142.      */

  143.     public abstract double[] bootstrapBasis (
  144.         final int[] aiDateNode,
  145.         final org.drip.param.valuation.ValuationParams valParams,
  146.         final org.drip.state.discount.MergedDiscountForwardCurve dcNum,
  147.         final org.drip.state.discount.MergedDiscountForwardCurve dcDenom,
  148.         final boolean bBasisOnDenom);

  149.     /**
  150.      * Bootstrap the discount curve from the discount curve inputs
  151.      *
  152.      * @param aiDateNode Array of Date Nodes
  153.      * @param valParams Valuation Parameters
  154.      * @param dcNum Discount Curve Numerator
  155.      * @param dcDenom Discount Curve Denominator
  156.      * @param bBasisOnDenom True if the basis is calculated on the denominator discount curve
  157.      *
  158.      * @return Array of the computed basis
  159.      */

  160.     public abstract org.drip.state.discount.MergedDiscountForwardCurve bootstrapBasisDC (
  161.         final int[] aiDateNode,
  162.         final org.drip.param.valuation.ValuationParams valParams,
  163.         final org.drip.state.discount.MergedDiscountForwardCurve dcNum,
  164.         final org.drip.state.discount.MergedDiscountForwardCurve dcDenom,
  165.         final boolean bBasisOnDenom);

  166.     /**
  167.      * Calculate the rates implied by the discount curve inputs
  168.      *
  169.      * @param aiDateNode Array of Date Nodes
  170.      * @param valParams Valuation Parameters
  171.      * @param dcNum Discount Curve Numerator
  172.      * @param dcDenom Discount Curve Denominator
  173.      * @param bBasisOnDenom True if the basis is calculated on the denominator discount curve
  174.      *
  175.      * @return Array of the computed implied rates
  176.      */

  177.     public abstract double[] impliedNodeRates (
  178.         final int[] aiDateNode,
  179.         final org.drip.param.valuation.ValuationParams valParams,
  180.         final org.drip.state.discount.MergedDiscountForwardCurve dcNum,
  181.         final org.drip.state.discount.MergedDiscountForwardCurve dcDenom,
  182.         final boolean bBasisOnDenom);

  183.     /**
  184.      * Calculate the rate implied by the discount curve inputs to a specified date
  185.      *
  186.      * @param aiDateNode Array of Date Nodes
  187.      * @param valParams ValuationParams
  188.      * @param dcNum Discount Curve Numerator
  189.      * @param dcDenom Discount Curve Denominator
  190.      * @param iDate Date to which the implied rate is sought
  191.      * @param bBasisOnDenom True if the implied rate is calculated on the denominator discount curve
  192.      *
  193.      * @return Implied rate
  194.      *
  195.      * @throws java.lang.Exception Thrown if the implied rate cannot be calculated
  196.      */

  197.     public abstract double rate (
  198.         final int[] aiDateNode,
  199.         final org.drip.param.valuation.ValuationParams valParams,
  200.         final org.drip.state.discount.MergedDiscountForwardCurve dcNum,
  201.         final org.drip.state.discount.MergedDiscountForwardCurve dcDenom,
  202.         final int iDate,
  203.         final boolean bBasisOnDenom)
  204.         throws java.lang.Exception;

  205.     @Override public org.drip.state.identifier.LatentStateLabel label()
  206.     {
  207.         return org.drip.state.identifier.FXLabel.Standard (_cp);
  208.     }

  209.     @Override public java.lang.String currency()
  210.     {
  211.         return _cp.quoteCcy();
  212.     }

  213.     @Override public org.drip.analytics.date.JulianDate epoch()
  214.     {
  215.         return new org.drip.analytics.date.JulianDate (_iEpochDate);
  216.     }

  217.     /**
  218.      * Return the CurrencyPair
  219.      *
  220.      * @return CurrencyPair
  221.      */

  222.     public org.drip.product.params.CurrencyPair currencyPair()
  223.     {
  224.         return _cp;
  225.     }

  226.     /**
  227.      * Calculate the FX Forward to the given date
  228.      *
  229.      * @param dt Date
  230.      *
  231.      * @return The FX Forward
  232.      *
  233.      * @throws java.lang.Exception Thrown if the FX Forward cannot be calculated
  234.      */

  235.     public double fx (
  236.         final org.drip.analytics.date.JulianDate dt)
  237.         throws java.lang.Exception
  238.     {
  239.         if (null == dt) throw new java.lang.Exception ("FXCurve::fx got null for date");

  240.         return fx (dt.julian());
  241.     }

  242.     /**
  243.      * Calculate the FX Forward to the given date
  244.      *
  245.      * @param strTenor The Tenor
  246.      *
  247.      * @return The FX Forward
  248.      *
  249.      * @throws java.lang.Exception Thrown if the FX Forward cannot be calculated
  250.      */

  251.     public double fx (
  252.         final java.lang.String strTenor)
  253.         throws java.lang.Exception
  254.     {
  255.         if (null == strTenor || strTenor.isEmpty())
  256.             throw new java.lang.Exception ("FXCurve::fx got bad tenor");

  257.         return fx (epoch().addTenor (strTenor));
  258.     }

  259.     @Override public boolean setCCIS (
  260.         final org.drip.analytics.input.CurveConstructionInputSet ccis)
  261.     {
  262.         return true;
  263.     }

  264.     @Override public org.drip.product.definition.CalibratableComponent[] calibComp()
  265.     {
  266.         return null;
  267.     }

  268.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> manifestMeasure (
  269.         final java.lang.String strInstr)
  270.     {
  271.         return null;
  272.     }

  273.     @Override public org.drip.state.representation.LatentState parallelShiftManifestMeasure (
  274.         final java.lang.String strManifestMeasure,
  275.         final double dblShift)
  276.     {
  277.         return null;
  278.     }

  279.     @Override public org.drip.state.representation.LatentState shiftManifestMeasure (
  280.         final int iSpanIndex,
  281.         final java.lang.String strManifestMeasure,
  282.         final double dblShift)
  283.     {
  284.         return null;
  285.     }

  286.     @Override public org.drip.state.representation.LatentState customTweakManifestMeasure (
  287.         final java.lang.String strManifestMeasure,
  288.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  289.     {
  290.         return null;
  291.     }

  292.     @Override public org.drip.state.representation.LatentState parallelShiftQuantificationMetric (
  293.         final double dblShift)
  294.     {
  295.         return null;
  296.     }

  297.     @Override public org.drip.state.representation.LatentState customTweakQuantificationMetric (
  298.         final org.drip.param.definition.ManifestMeasureTweak rvtp)
  299.     {
  300.         return null;
  301.     }

  302.     /**
  303.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the given date
  304.      *
  305.      * @param strManifestMeasure Manifest Measure
  306.      * @param iDate Date
  307.      *
  308.      * @return The Manifest Measure Jacobian of the Forward Rate to the given date
  309.      */

  310.     public abstract org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  311.         final java.lang.String strManifestMeasure,
  312.         final int iDate);

  313.     /**
  314.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the given date
  315.      *
  316.      * @param strManifestMeasure Manifest Measure
  317.      * @param dt Date
  318.      *
  319.      * @return The Manifest Measure Jacobian of the Forward Rate to the given date
  320.      */

  321.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  322.         final java.lang.String strManifestMeasure,
  323.         final org.drip.analytics.date.JulianDate dt)
  324.     {
  325.         if (null == dt) return null;

  326.         return jackDForwardDManifestMeasure (strManifestMeasure, dt.julian());
  327.     }

  328.     /**
  329.      * Retrieve the Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  330.      *
  331.      * @param strManifestMeasure Manifest Measure
  332.      * @param strTenor Tenor
  333.      *
  334.      * @return The Manifest Measure Jacobian of the Forward Rate to the date implied by the given Tenor
  335.      */

  336.     public org.drip.numerical.differentiation.WengertJacobian jackDForwardDManifestMeasure (
  337.         final java.lang.String strManifestMeasure,
  338.         final java.lang.String strTenor)
  339.     {
  340.         if (null == strTenor || strTenor.isEmpty()) return null;

  341.         try {
  342.             return jackDForwardDManifestMeasure (strManifestMeasure, epoch().addTenor (strTenor));
  343.         } catch (java.lang.Exception e) {
  344.             e.printStackTrace();
  345.         }

  346.         return null;
  347.     }
  348. }