FuturesHelper.java

  1. package org.drip.analytics.support;

  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>FuturesHelper</i> contains the Collection of the Futures Valuation related Utility Functions.
  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/analytics/README.md">Date, Cash Flow, and Cash Flow Period Measure Generation Utilities</a></li>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/support/README.md">Assorted Support and Helper Utilities</a></li>
  87.  *  </ul>
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class FuturesHelper {

  92.     /**
  93.      * Compute the Forward Bond Price Using the Implied Bond Yield
  94.      *
  95.      * @param bond The Bond Instance
  96.      * @param valParamsSpot The Spot Valuation Parameters
  97.      * @param valParamsForward The Forward Valuation Parameters
  98.      * @param csqc The Market Parameters
  99.      * @param vcp Valuation Customization Parameters
  100.      * @param dblCleanPrice The Clean Bond Price
  101.      *
  102.      * @return The Forward Bond Price Using the Implied Bond Yield
  103.      *
  104.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  105.      */

  106.     public static final double ForwardBondYieldPrice (
  107.         final org.drip.product.definition.Bond bond,
  108.         final org.drip.param.valuation.ValuationParams valParamsSpot,
  109.         final org.drip.param.valuation.ValuationParams valParamsForward,
  110.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  111.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  112.         final double dblCleanPrice)
  113.         throws java.lang.Exception
  114.     {
  115.         if (null == bond)
  116.             throw new java.lang.Exception ("FuturesHelper::ForwardBondYieldPrice => Invalid Inputs");

  117.         return bond.priceFromYield (valParamsForward, csqc, vcp, bond.yieldFromPrice (valParamsSpot, csqc,
  118.             vcp, dblCleanPrice));
  119.     }

  120.     /**
  121.      * Compute the Forward Bond Price Using the Implied Bond Z Spread
  122.      *
  123.      * @param bond The Bond Instance
  124.      * @param valParamsSpot The Spot Valuation Parameters
  125.      * @param valParamsForward The Forward Valuation Parameters
  126.      * @param csqc The Market Parameters
  127.      * @param vcp Valuation Customization Parameters
  128.      * @param dblCleanPrice The Clean Bond Price
  129.      *
  130.      * @return The Forward Bond Price Using the Implied Bond Z Spread
  131.      *
  132.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  133.      */

  134.     public static final double ForwardBondZSpreadPrice (
  135.         final org.drip.product.definition.Bond bond,
  136.         final org.drip.param.valuation.ValuationParams valParamsSpot,
  137.         final org.drip.param.valuation.ValuationParams valParamsForward,
  138.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  139.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  140.         final double dblCleanPrice)
  141.         throws java.lang.Exception
  142.     {
  143.         if (null == bond)
  144.             throw new java.lang.Exception ("FuturesHelper::ForwardBondZSpreadPrice => Invalid Inputs");

  145.         return bond.priceFromZSpread (valParamsForward, csqc, vcp, bond.zSpreadFromPrice (valParamsSpot,
  146.             csqc, vcp, dblCleanPrice));
  147.     }

  148.     /**
  149.      * Compute the Forward Bond Price Using the Implied Bond OAS
  150.      *
  151.      * @param bond The Bond Instance
  152.      * @param valParamsSpot The Spot Valuation Parameters
  153.      * @param valParamsForward The Forward Valuation Parameters
  154.      * @param csqc The Market Parameters
  155.      * @param vcp Valuation Customization Parameters
  156.      * @param dblCleanPrice The Clean Bond Price
  157.      *
  158.      * @return The Forward Bond Price Using the Implied Bond OAS
  159.      *
  160.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  161.      */

  162.     public static final double ForwardBondOASPrice (
  163.         final org.drip.product.definition.Bond bond,
  164.         final org.drip.param.valuation.ValuationParams valParamsSpot,
  165.         final org.drip.param.valuation.ValuationParams valParamsForward,
  166.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  167.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  168.         final double dblCleanPrice)
  169.         throws java.lang.Exception
  170.     {
  171.         if (null == bond)
  172.             throw new java.lang.Exception ("FuturesHelper::ForwardBondOASPrice => Invalid Inputs");

  173.         return bond.priceFromOAS (valParamsForward, csqc, vcp, bond.oasFromPrice (valParamsSpot, csqc, vcp,
  174.             dblCleanPrice));
  175.     }

  176.     /**
  177.      * Compute the Forward Bond Price Using the Implied Bond Credit Basis
  178.      *
  179.      * @param bond The Bond Instance
  180.      * @param valParamsSpot The Spot Valuation Parameters
  181.      * @param valParamsForward The Forward Valuation Parameters
  182.      * @param csqc The Market Parameters
  183.      * @param vcp Valuation Customization Parameters
  184.      * @param dblCleanPrice The Clean Bond Price
  185.      *
  186.      * @return The Forward Bond Price Using the Implied Bond Credit Basis
  187.      *
  188.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  189.      */

  190.     public static final double ForwardBondCreditPrice (
  191.         final org.drip.product.definition.Bond bond,
  192.         final org.drip.param.valuation.ValuationParams valParamsSpot,
  193.         final org.drip.param.valuation.ValuationParams valParamsForward,
  194.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  195.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  196.         final double dblCleanPrice)
  197.         throws java.lang.Exception
  198.     {
  199.         if (null == bond)
  200.             throw new java.lang.Exception ("FuturesHelper::ForwardBondCreditPrice => Invalid Inputs");

  201.         return bond.priceFromCreditBasis (valParamsForward, csqc, vcp, bond.creditBasisFromPrice
  202.             (valParamsSpot, csqc, vcp, dblCleanPrice));
  203.     }

  204.     /**
  205.      * Compute the Forward Bond Price Using the Implied Bond Yield
  206.      *
  207.      * @param bond The Bond Instance
  208.      * @param dtSpot The Spot Date
  209.      * @param dtForward The Forward Date
  210.      * @param csqc The Market Parameters
  211.      * @param dblCleanPrice The Clean Bond Price
  212.      *
  213.      * @return The Forward Bond Price Using the Implied Bond Yield
  214.      *
  215.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  216.      */

  217.     public static final double ForwardBondYieldPrice (
  218.         final org.drip.product.definition.Bond bond,
  219.         final org.drip.analytics.date.JulianDate dtSpot,
  220.         final org.drip.analytics.date.JulianDate dtForward,
  221.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  222.         final double dblCleanPrice)
  223.         throws java.lang.Exception
  224.     {
  225.         if (null == bond || null == dtSpot || null == dtForward)
  226.             throw new java.lang.Exception ("FuturesHelper::ForwardBondYieldPrice => Invalid Inputs");

  227.         return bond.priceFromYield (org.drip.param.valuation.ValuationParams.Spot (dtForward.julian()), csqc,
  228.             null, bond.yieldFromPrice (org.drip.param.valuation.ValuationParams.Spot (dtSpot.julian()), csqc,
  229.                 null, dblCleanPrice));
  230.     }

  231.     /**
  232.      * Compute the Forward Bond Price Using the Implied Bond Z Spread
  233.      *
  234.      * @param bond The Bond Instance
  235.      * @param dtSpot The Spot Date
  236.      * @param dtForward The Forward Date
  237.      * @param csqc The Market Parameters
  238.      * @param dblCleanPrice The Clean Bond Price
  239.      *
  240.      * @return The Forward Bond Price Using the Implied Bond Z Spread
  241.      *
  242.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  243.      */

  244.     public static final double ForwardBondZSpreadPrice (
  245.         final org.drip.product.definition.Bond bond,
  246.         final org.drip.analytics.date.JulianDate dtSpot,
  247.         final org.drip.analytics.date.JulianDate dtForward,
  248.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  249.         final double dblCleanPrice)
  250.         throws java.lang.Exception
  251.     {
  252.         if (null == bond || null == dtSpot || null == dtForward)
  253.             throw new java.lang.Exception ("FuturesHelper::ForwardBondZSpreadPrice => Invalid Inputs");

  254.         return bond.priceFromZSpread (org.drip.param.valuation.ValuationParams.Spot (dtForward.julian()),
  255.             csqc, null, bond.zSpreadFromPrice (org.drip.param.valuation.ValuationParams.Spot
  256.                 (dtSpot.julian()), csqc, null, dblCleanPrice));
  257.     }

  258.     /**
  259.      * Compute the Forward Bond Price Using the Implied Bond OAS
  260.      *
  261.      * @param bond The Bond Instance
  262.      * @param dtSpot The Spot Date
  263.      * @param dtForward The Forward Date
  264.      * @param csqc The Market Parameters
  265.      * @param dblCleanPrice The Clean Bond Price
  266.      *
  267.      * @return The Forward Bond Price Using the Implied Bond OAS
  268.      *
  269.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  270.      */

  271.     public static final double ForwardBondOASPrice (
  272.         final org.drip.product.definition.Bond bond,
  273.         final org.drip.analytics.date.JulianDate dtSpot,
  274.         final org.drip.analytics.date.JulianDate dtForward,
  275.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  276.         final double dblCleanPrice)
  277.         throws java.lang.Exception
  278.     {
  279.         if (null == bond || null == dtSpot || null == dtForward)
  280.             throw new java.lang.Exception ("FuturesHelper::ForwardBondOASPrice => Invalid Inputs");

  281.         return bond.priceFromOAS (org.drip.param.valuation.ValuationParams.Spot (dtForward.julian()), csqc,
  282.             null, bond.oasFromPrice (org.drip.param.valuation.ValuationParams.Spot (dtSpot.julian()), csqc,
  283.                 null, dblCleanPrice));
  284.     }

  285.     /**
  286.      * Compute the Forward Bond Price Using the Implied Bond Credit Basis
  287.      *
  288.      * @param bond The Bond Instance
  289.      * @param dtSpot The Spot Date
  290.      * @param dtForward The Forward Date
  291.      * @param csqc The Market Parameters
  292.      * @param dblCleanPrice The Clean Bond Price
  293.      *
  294.      * @return The Forward Bond Price Using the Implied Bond Credit Basis
  295.      *
  296.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  297.      */

  298.     public static final double ForwardBondCreditPrice (
  299.         final org.drip.product.definition.Bond bond,
  300.         final org.drip.analytics.date.JulianDate dtSpot,
  301.         final org.drip.analytics.date.JulianDate dtForward,
  302.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  303.         final double dblCleanPrice)
  304.         throws java.lang.Exception
  305.     {
  306.         if (null == bond || null == dtSpot || null == dtForward)
  307.             throw new java.lang.Exception ("FuturesHelper::ForwardBondCreditPrice => Invalid Inputs");

  308.         return bond.priceFromCreditBasis (org.drip.param.valuation.ValuationParams.Spot (dtForward.julian()),
  309.             csqc, null, bond.creditBasisFromPrice (org.drip.param.valuation.ValuationParams.Spot
  310.                 (dtSpot.julian()), csqc, null, dblCleanPrice));
  311.     }
  312. }