TreasuryFutures.java

  1. package org.drip.product.govvie;

  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>TreasuryFutures</i> implements the Treasury Futures Product Contract Details.
  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/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  86.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/govvie/README.md">Treasury Bills, Notes, Bonds, Futures</a></li>
  87.  *  </ul>
  88.  * <br><br>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class TreasuryFutures extends org.drip.product.definition.Component {

  93.     /*
  94.      * Bond Futures Valuation Settings
  95.      */

  96.     public static final int FORWARD_PRICE_OAS = 0;
  97.     public static final int FORWARD_PRICE_YIELD = 1;
  98.     public static final int FORWARD_PRICE_ZSPREAD = 2;
  99.     public static final int FORWARD_PRICE_CREDIT_BASIS = 3;

  100.     private double[] _adblConversionFactor = null;
  101.     private org.drip.product.definition.Bond[] _aBond = null;
  102.     private org.drip.analytics.date.JulianDate _dtExpiry = null;
  103.     private org.drip.param.valuation.CashSettleParams _csp = null;

  104.     /*
  105.      * Bond Futures Contract Details
  106.      */

  107.     private int[] _aiDeliveryMonth = null;
  108.     private java.lang.String _strType = "";
  109.     private double _dblTickValue = java.lang.Double.NaN;
  110.     private double _dblNotionalValue = java.lang.Double.NaN;
  111.     private double _dblReferenceCoupon = java.lang.Double.NaN;
  112.     private int _iLastTradingDayLag = java.lang.Integer.MIN_VALUE;
  113.     private double _dblMinimumPriceMovement = java.lang.Double.NaN;
  114.     private java.lang.String _strDeliverableGradeMaximumMaturity = "";
  115.     private java.lang.String _strDeliverableGradeMinimumMaturity = "";

  116.     /**
  117.      * BondFutures Constructor
  118.      *
  119.      * @param aBond Array of the Bonds on the Basket
  120.      * @param adblConversionFactor The Bond Conversion Factor
  121.      * @param csp Cash Settlement Parameters
  122.      *
  123.      * @throws java.lang.Exception thrown if the Inputs are Invalid
  124.      */

  125.     public TreasuryFutures (
  126.         final org.drip.product.definition.Bond[] aBond,
  127.         final double[] adblConversionFactor,
  128.         final org.drip.param.valuation.CashSettleParams csp)
  129.         throws java.lang.Exception
  130.     {
  131.         if (null == (_aBond = aBond) || null == (_adblConversionFactor = adblConversionFactor))
  132.             throw new java.lang.Exception ("BondFutures ctr: Invalid Inputs");

  133.         _csp = csp;
  134.         int iNumBond = _aBond.length;

  135.         if (0 == iNumBond || iNumBond != _adblConversionFactor.length)
  136.             throw new java.lang.Exception ("BondFutures ctr: Invalid Inputs");

  137.         for (int i = 0; i < iNumBond; ++i) {
  138.             if (null == _aBond[i] || !org.drip.numerical.common.NumberUtil.IsValid (_adblConversionFactor[i]))
  139.                 throw new java.lang.Exception ("BondFutures ctr: Invalid Inputs");
  140.         }
  141.     }

  142.     /**
  143.      * Set the Futures Type
  144.      *
  145.      * @param strType The Futures Type
  146.      *
  147.      * @return TRUE - Futures Type Successfully Set
  148.      */

  149.     public boolean setType (
  150.         final java.lang.String strType)
  151.     {
  152.         return null == (_strType = strType) || _strType.isEmpty() ? false : true;
  153.     }

  154.     /**
  155.      * Retrieve the Futures Type
  156.      *
  157.      * @return The Futures Type
  158.      */

  159.     public java.lang.String type()
  160.     {
  161.         return _strType;
  162.     }

  163.     /**
  164.      * Retrieve the Notional Value
  165.      *
  166.      * @param dblNotionalValue The Notional Value
  167.      *
  168.      * @return TRUE - The Notional Value successfully retrieved
  169.      */

  170.     public boolean setNotionalValue (
  171.         final double dblNotionalValue)
  172.     {
  173.         return org.drip.numerical.common.NumberUtil.IsValid (_dblNotionalValue = dblNotionalValue);
  174.     }

  175.     /**
  176.      * Retrieve the Notional Value
  177.      *
  178.      * @return The Notional Value
  179.      */

  180.     public double notionalValue()
  181.     {
  182.         return _dblNotionalValue;
  183.     }

  184.     /**
  185.      * Set the Reference Coupon Rate
  186.      *
  187.      * @param dblReferenceCoupon The Reference Coupon Rate
  188.      *
  189.      * @return TRUE - The Reference Coupon Rate successfully set
  190.      */

  191.     public boolean setReferenceCoupon (
  192.         final double dblReferenceCoupon)
  193.     {
  194.         return org.drip.numerical.common.NumberUtil.IsValid (_dblReferenceCoupon = dblReferenceCoupon);
  195.     }

  196.     /**
  197.      * Retrieve the Reference Coupon Rate
  198.      *
  199.      * @return The Reference Coupon Rate
  200.      */

  201.     public double referenceCoupon()
  202.     {
  203.         return _dblReferenceCoupon;
  204.     }

  205.     /**
  206.      * Retrieve the Deliverable Grade Minimum Maturity
  207.      *
  208.      * @param strDeliverableGradeMinimumMaturity Minimum Maturity of the Deliverable Grade
  209.      *
  210.      * @return TRUE - Minimum Maturity Successfully set
  211.      */

  212.     public boolean setMinimumMaturity (
  213.         final java.lang.String strDeliverableGradeMinimumMaturity)
  214.     {
  215.         return null == (_strDeliverableGradeMinimumMaturity = strDeliverableGradeMinimumMaturity) ||
  216.             _strDeliverableGradeMinimumMaturity.isEmpty() ? false : true;
  217.     }

  218.     /**
  219.      * Retrieve the Minimum Maturity of the Contract
  220.      *
  221.      * @return The Minimum Maturity of the Contract
  222.      */

  223.     public java.lang.String minimumMaturity()
  224.     {
  225.         return _strDeliverableGradeMinimumMaturity;
  226.     }

  227.     /**
  228.      * Retrieve the Deliverable Grade Maximum Maturity
  229.      *
  230.      * @param strDeliverableGradeMaximumMaturity Maximum Maturity of the Deliverable Grade
  231.      *
  232.      * @return TRUE - Maximum Maturity Successfully set
  233.      */

  234.     public boolean setMaximumMaturity (
  235.         final java.lang.String strDeliverableGradeMaximumMaturity)
  236.     {
  237.         return null == (_strDeliverableGradeMaximumMaturity = strDeliverableGradeMaximumMaturity) ||
  238.             _strDeliverableGradeMaximumMaturity.isEmpty() ? false : true;
  239.     }

  240.     /**
  241.      * Retrieve the Maximum Maturity of the Contract
  242.      *
  243.      * @return The Maximum Maturity of the Contract
  244.      */

  245.     public java.lang.String maximumMaturity()
  246.     {
  247.         return _strDeliverableGradeMaximumMaturity;
  248.     }

  249.     /**
  250.      * Set the Delivery Months
  251.      *
  252.      * @param aiDeliveryMonth Array of Delivery Months
  253.      *
  254.      * @return TRUE - Delivery Months successfully set
  255.      */

  256.     public boolean setDeliveryMonths (
  257.         final int[] aiDeliveryMonth)
  258.     {
  259.         return null == (_aiDeliveryMonth = aiDeliveryMonth) || 0 == _aiDeliveryMonth.length ? false : true;
  260.     }

  261.     /**
  262.      * Retrieve the Array of Delivery Months
  263.      *
  264.      * @return Array of Delivery Months
  265.      */

  266.     public int[] deliveryMonths()
  267.     {
  268.         return _aiDeliveryMonth;
  269.     }

  270.     /**
  271.      * Set the Last Trading Day Lag
  272.      *
  273.      * @param iLastTradingDayLag The Last Trading Day Lag
  274.      *
  275.      * @return TRUE - Last Trading Day Lag Successfully Set
  276.      */

  277.     public boolean setLastTradingDayLag (
  278.         final int iLastTradingDayLag)
  279.     {
  280.         return 0 > (_iLastTradingDayLag = iLastTradingDayLag) ? false : true;
  281.     }

  282.     /**
  283.      * Retrieve the Last Trading Day Lag
  284.      *
  285.      * @return Last Trading Day Lag
  286.      */

  287.     public int lastTradingDayLag()
  288.     {
  289.         return _iLastTradingDayLag;
  290.     }

  291.     /**
  292.      * Retrieve the Minimum Price Movement
  293.      *
  294.      * @param dblMinimumPriceMovement The Minimum Price Movement
  295.      *
  296.      * @return TRUE - The Minimum Price Movement Successfully Set
  297.      */

  298.     public boolean setMinimumPriceMovement (
  299.         final double dblMinimumPriceMovement)
  300.     {
  301.         return org.drip.numerical.common.NumberUtil.IsValid (_dblMinimumPriceMovement = dblMinimumPriceMovement);
  302.     }

  303.     /**
  304.      * Retrieve the Minimum Price Movement
  305.      *
  306.      * @return The Minimum Price Movement
  307.      */

  308.     public double minimumPriceMovement()
  309.     {
  310.         return _dblMinimumPriceMovement;
  311.     }

  312.     /**
  313.      * Retrieve the Tick Value
  314.      *
  315.      * @param dblTickValue The Tick Value
  316.      *
  317.      * @return TRUE - The Tick Value Successfully Set
  318.      */

  319.     public boolean setTickValue (
  320.         final double dblTickValue)
  321.     {
  322.         return org.drip.numerical.common.NumberUtil.IsValid (_dblTickValue = dblTickValue);
  323.     }

  324.     /**
  325.      * Retrieve the Tick Value
  326.      *
  327.      * @return The Tick Value
  328.      */

  329.     public double tickValue()
  330.     {
  331.         return _dblTickValue;
  332.     }

  333.     /**
  334.      * Retrieve the Bond Basket Array
  335.      *
  336.      * @return The Bond Basket Array
  337.      */

  338.     public org.drip.product.definition.Bond[] basket()
  339.     {
  340.         return _aBond;
  341.     }

  342.     /**
  343.      * Retrieve the Conversion Factor Array
  344.      *
  345.      * @return The Conversion Factor Array
  346.      */

  347.     public double[] conversionFactor()
  348.     {
  349.         return _adblConversionFactor;
  350.     }

  351.     /**
  352.      * Set the Futures Expiration Date
  353.      *
  354.      * @param dtExpiry The Futures Expiration Date
  355.      *
  356.      * @return TRUE - The Futures Expiration Date Successfully Set
  357.      */

  358.     public boolean setExpiry (
  359.         final org.drip.analytics.date.JulianDate dtExpiry)
  360.     {
  361.         if (null == dtExpiry) return false;

  362.         _dtExpiry = dtExpiry;
  363.         return true;
  364.     }

  365.     /**
  366.      * Retrieve the Futures Expiration Date
  367.      *
  368.      * @return The Futures Expiration Date
  369.      */

  370.     public org.drip.analytics.date.JulianDate expiry()
  371.     {
  372.         return _dtExpiry;
  373.     }

  374.     /**
  375.      * Extract the Cheapest-to-deliver Entry in the Basket Using the Current Market Parameters
  376.      *
  377.      * @param iValueDate The Valuation Date
  378.      * @param csqc The Market Parameters
  379.      * @param vcp Valuation Customization Parameters
  380.      * @param adblCleanPrice Array of the Bond Clean Prices
  381.      * @param iForwardPriceMethod Forward Price Calculation Method
  382.      *
  383.      * @return The Cheapest-to-deliver Entry in the Basket Using the Current Market Parameters
  384.      */

  385.     public org.drip.product.params.CTDEntry cheapestToDeliver (
  386.         final int iValueDate,
  387.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  388.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  389.         final double[] adblCleanPrice,
  390.         final int iForwardPriceMethod)
  391.     {
  392.         if (null == adblCleanPrice) return null;

  393.         int iStartIndex = 0;
  394.         int iBasketSize = adblCleanPrice.length;

  395.         if (iBasketSize != _aBond.length) return null;

  396.         for (int i = 0; i < iBasketSize; ++i) {
  397.             if (org.drip.numerical.common.NumberUtil.IsValid (adblCleanPrice[i])) {
  398.                 iStartIndex = i;
  399.                 break;
  400.             }
  401.         }

  402.         if (iBasketSize <= iStartIndex) return null;

  403.         int iCTDIndex = iStartIndex;
  404.         double dblMinimumScaledPrice = adblCleanPrice[iStartIndex] / _adblConversionFactor[iStartIndex];

  405.         int iExpiryDate = _dtExpiry.julian();

  406.         if (iExpiryDate <= iValueDate) return null;

  407.         org.drip.param.valuation.ValuationParams valParamsSpot =
  408.             org.drip.param.valuation.ValuationParams.Spot (iValueDate);

  409.         org.drip.param.valuation.ValuationParams valParamsExpiry =
  410.             org.drip.param.valuation.ValuationParams.Spot (iExpiryDate);

  411.         for (int i = iStartIndex; i < iBasketSize; ++i) {
  412.             if (!org.drip.numerical.common.NumberUtil.IsValid (adblCleanPrice[i])) continue;

  413.             double dblForwardPrice = java.lang.Double.NaN;

  414.             try {
  415.                 if (FORWARD_PRICE_YIELD == iForwardPriceMethod)
  416.                     dblForwardPrice = org.drip.analytics.support.FuturesHelper.ForwardBondYieldPrice
  417.                         (_aBond[i], valParamsSpot, valParamsExpiry, csqc, vcp, adblCleanPrice[i]);
  418.                 else if (FORWARD_PRICE_OAS == iForwardPriceMethod)
  419.                     dblForwardPrice = org.drip.analytics.support.FuturesHelper.ForwardBondOASPrice
  420.                         (_aBond[i], valParamsSpot, valParamsExpiry, csqc, vcp, adblCleanPrice[i]);
  421.                 else if (FORWARD_PRICE_ZSPREAD == iForwardPriceMethod)
  422.                     dblForwardPrice = org.drip.analytics.support.FuturesHelper.ForwardBondZSpreadPrice
  423.                         (_aBond[i], valParamsSpot, valParamsExpiry, csqc, vcp, adblCleanPrice[i]);
  424.                 else if (FORWARD_PRICE_CREDIT_BASIS == iForwardPriceMethod)
  425.                     dblForwardPrice = org.drip.analytics.support.FuturesHelper.ForwardBondCreditPrice
  426.                         (_aBond[i], valParamsSpot, valParamsExpiry, csqc, vcp, adblCleanPrice[i]);
  427.                 else
  428.                     return null;
  429.             } catch (java.lang.Exception e) {
  430.                 e.printStackTrace();

  431.                 return null;
  432.             }

  433.             double dblScaledPrice = dblForwardPrice / _adblConversionFactor[i];

  434.             if (dblScaledPrice < dblMinimumScaledPrice) {
  435.                 iCTDIndex = i;
  436.                 dblMinimumScaledPrice = dblScaledPrice;
  437.             }
  438.         }

  439.         try {
  440.             return new org.drip.product.params.CTDEntry (_aBond[iCTDIndex], _adblConversionFactor[iCTDIndex],
  441.                 dblMinimumScaledPrice * _adblConversionFactor[iCTDIndex]);
  442.         } catch (java.lang.Exception e) {
  443.             e.printStackTrace();
  444.         }

  445.         return null;
  446.     }

  447.     /**
  448.      * Extract the Cheapest-to-deliver Entry in the Basket Using the Current Market Prices Alone
  449.      *
  450.      * @param iValueDate The Valuation Date
  451.      * @param adblCleanPrice Array of the Bond Clean Prices
  452.      *
  453.      * @return The Cheapest-to-deliver Entry in the Basket Using the Current Market Prices Alone
  454.      */

  455.     public org.drip.product.params.CTDEntry cheapestToDeliverYield (
  456.         final int iValueDate,
  457.         final double[] adblCleanPrice)
  458.     {
  459.         return cheapestToDeliver (iValueDate, null, null, adblCleanPrice, FORWARD_PRICE_YIELD);
  460.     }

  461.     /**
  462.      * Extract the Cheapest-to-deliver Entry in the Basket Using Bond OAS Metric
  463.      *
  464.      * @param iValueDate The Valuation Date
  465.      * @param csqc The Market Parameters
  466.      * @param adblCleanPrice Array of the Bond Clean Prices
  467.      *
  468.      * @return The Cheapest-to-deliver Entry in the Basket Using Bond OAS Metric
  469.      */

  470.     public org.drip.product.params.CTDEntry cheapestToDeliverOAS (
  471.         final int iValueDate,
  472.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  473.         final double[] adblCleanPrice)
  474.     {
  475.         return cheapestToDeliver (iValueDate, csqc, null, adblCleanPrice, FORWARD_PRICE_OAS);
  476.     }

  477.     /**
  478.      * Extract the Cheapest-to-deliver Entry in the Basket Using Bond Z Spread Metric
  479.      *
  480.      * @param iValueDate The Valuation Date
  481.      * @param csqc The Market Parameters
  482.      * @param adblCleanPrice Array of the Bond Clean Prices
  483.      *
  484.      * @return The Cheapest-to-deliver Entry in the Basket Using Bond Z Spread Metric
  485.      */

  486.     public org.drip.product.params.CTDEntry cheapestToDeliverZSpread (
  487.         final int iValueDate,
  488.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  489.         final double[] adblCleanPrice)
  490.     {
  491.         return cheapestToDeliver (iValueDate, csqc, null, adblCleanPrice, FORWARD_PRICE_ZSPREAD);
  492.     }

  493.     /**
  494.      * Extract the Cheapest-to-deliver Entry in the Basket Using Bond Credit Basis Metric
  495.      *
  496.      * @param iValueDate The Valuation Date
  497.      * @param csqc The Market Parameters
  498.      * @param adblCleanPrice Array of the Bond Clean Prices
  499.      *
  500.      * @return The Cheapest-to-deliver Entry in the Basket Using Bond Credit Basis Metric
  501.      */

  502.     public org.drip.product.params.CTDEntry cheapestToDeliverCreditBasis (
  503.         final int iValueDate,
  504.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  505.         final double[] adblCleanPrice)
  506.     {
  507.         return cheapestToDeliver (iValueDate, csqc, null, adblCleanPrice, FORWARD_PRICE_CREDIT_BASIS);
  508.     }

  509.     @Override public java.lang.String name()
  510.     {
  511.         return (null == _strType || _strType.isEmpty() ? _aBond[0].currency() : _strType) +
  512.             (null == _strDeliverableGradeMaximumMaturity || _strDeliverableGradeMaximumMaturity.isEmpty() ?
  513.                 _aBond[0].tenor() : _strDeliverableGradeMaximumMaturity);
  514.     }

  515.     @Override public org.drip.param.valuation.CashSettleParams cashSettleParams()
  516.     {
  517.         return _csp;
  518.     }

  519.     @Override public org.drip.analytics.output.CompositePeriodCouponMetrics couponMetrics (
  520.         final int iAccrualEndDate,
  521.         final org.drip.param.valuation.ValuationParams valParams,
  522.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs)
  523.     {
  524.         return null;
  525.     }

  526.     @Override public java.util.List<org.drip.analytics.cashflow.CompositePeriod> couponPeriods()
  527.     {
  528.         return null;
  529.     }

  530.     @Override public org.drip.analytics.date.JulianDate effectiveDate()
  531.     {
  532.         return _dtExpiry.subtractTenor ("3M");
  533.     }

  534.     @Override public org.drip.analytics.date.JulianDate firstCouponDate()
  535.     {
  536.         return null;
  537.     }

  538.     @Override public int freq()
  539.     {
  540.         return _aBond[0].freq();
  541.     }

  542.     @Override public double initialNotional()
  543.     {
  544.         return _dblNotionalValue;
  545.     }

  546.     @Override public double notional (
  547.         final int iDate)
  548.         throws java.lang.Exception
  549.     {
  550.         return _dblNotionalValue;
  551.     }

  552.     @Override public double notional (
  553.         final int iDate1,
  554.         final int iDate2)
  555.         throws java.lang.Exception
  556.     {
  557.         return _dblNotionalValue;
  558.     }

  559.     @Override public org.drip.analytics.date.JulianDate maturityDate()
  560.     {
  561.         return _dtExpiry;
  562.     }

  563.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String> couponCurrency()
  564.     {
  565.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String> mapCouponCurrency = new
  566.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String>();

  567.         for (org.drip.product.definition.Bond bond : _aBond)
  568.             mapCouponCurrency.putAll (bond.couponCurrency());

  569.         return 0 == mapCouponCurrency.size() ? null : mapCouponCurrency;
  570.     }

  571.     @Override public java.lang.String principalCurrency()
  572.     {
  573.         return _aBond[0].principalCurrency();
  574.     }

  575.     @Override public java.lang.String payCurrency()
  576.     {
  577.         return _aBond[0].payCurrency();
  578.     }

  579.     @Override public org.drip.state.identifier.EntityCDSLabel creditLabel()
  580.     {
  581.         return _aBond[0].creditLabel();
  582.     }

  583.     @Override public
  584.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  585.             forwardLabel()
  586.     {
  587.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  588.             mapForwardLabel = new
  589.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>();

  590.         for (org.drip.product.definition.Bond bond : _aBond)
  591.             mapForwardLabel.putAll (bond.forwardLabel());

  592.         return 0 == mapForwardLabel.size() ? null : mapForwardLabel;
  593.     }

  594.     @Override public
  595.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.OTCFixFloatLabel>
  596.             otcFixFloatLabel()
  597.     {
  598.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.OTCFixFloatLabel>
  599.             mapOTCFixFloatLabel = new
  600.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.OTCFixFloatLabel>();

  601.         for (org.drip.product.definition.Bond bond : _aBond)
  602.             mapOTCFixFloatLabel.putAll (bond.otcFixFloatLabel());

  603.         return 0 == mapOTCFixFloatLabel.size() ? null : mapOTCFixFloatLabel;
  604.     }

  605.     @Override public org.drip.state.identifier.FundingLabel fundingLabel()
  606.     {
  607.         return _aBond[0].fundingLabel();
  608.     }

  609.     @Override public org.drip.state.identifier.GovvieLabel govvieLabel()
  610.     {
  611.         return _aBond[0].govvieLabel();
  612.     }

  613.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.FXLabel>
  614.         fxLabel()
  615.     {
  616.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.FXLabel> mapFXLabel = new
  617.             org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.FXLabel>();

  618.         for (org.drip.product.definition.Bond bond : _aBond)
  619.             mapFXLabel.putAll (bond.fxLabel());

  620.         return 0 == mapFXLabel.size() ? null : mapFXLabel;
  621.     }

  622.     @Override public
  623.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.VolatilityLabel>
  624.             volatilityLabel()
  625.     {
  626.         return null;
  627.     }

  628.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> value (
  629.         final org.drip.param.valuation.ValuationParams valParams,
  630.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  631.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  632.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  633.     {
  634.         int iNumBond = _aBond.length;
  635.         double dblCTDRepoRate = java.lang.Double.NaN;
  636.         double[] adblCleanPrice = new double[iNumBond];
  637.         double dblCTDTreasuryYield = java.lang.Double.NaN;

  638.         int iValueDate = valParams.valueDate();

  639.         for (int i = 0; i < iNumBond; ++i) {
  640.             org.drip.param.definition.ProductQuote pqBond = csqc.productQuote (_aBond[i].name());

  641.             if (null == pqBond || !pqBond.containsQuote ("Price") ||
  642.                 !org.drip.numerical.common.NumberUtil.IsValid (adblCleanPrice[i] = pqBond.quote ("Price").value
  643.                     ("mid")))
  644.                 return null;
  645.         }

  646.         org.drip.product.params.CTDEntry ctdEntry = cheapestToDeliverYield (iValueDate, adblCleanPrice);

  647.         if (null == ctdEntry || null == csqc) return null;

  648.         org.drip.product.definition.Bond bondCTD = ctdEntry.bond();

  649.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBondFuturesMeasure =
  650.             bondCTD.value (valParams, pricerParams, csqc, vcp);

  651.         if (null == mapBondFuturesMeasure || null == (mapBondFuturesMeasure =
  652.             org.drip.numerical.common.CollectionUtil.PrefixKeys (bondCTD.value (valParams, pricerParams, csqc,
  653.                 vcp), "CTD::")))
  654.             return null;

  655.         double dblCTDForwardPrice = ctdEntry.forwardPrice();

  656.         double dblCTDConversionFactor = ctdEntry.conversionFactor();

  657.         mapBondFuturesMeasure.put ("CTDConversionFactor", dblCTDConversionFactor);

  658.         mapBondFuturesMeasure.put ("CTDForwardPrice", dblCTDForwardPrice);

  659.         org.drip.state.repo.RepoCurve repoState = csqc.repoState
  660.             (org.drip.state.identifier.RepoLabel.Standard (bondCTD.name()));

  661.         org.drip.state.govvie.GovvieCurve gc = csqc.govvieState (govvieLabel());

  662.         int iExpiryDate = _dtExpiry.julian();

  663.         try {
  664.             if (null != repoState)
  665.                 mapBondFuturesMeasure.put ("CTDRepoRate", dblCTDRepoRate = repoState.repo (iExpiryDate));

  666.             if (null != gc)
  667.                 mapBondFuturesMeasure.put ("CTDTreasuryYield", dblCTDTreasuryYield = gc.yield (iExpiryDate));
  668.         } catch (java.lang.Exception e) {
  669.             e.printStackTrace();

  670.             return null;
  671.         }

  672.         double dblCTDSpotPrice = csqc.productQuote (bondCTD.name()).quote ("Price").value ("mid");

  673.         mapBondFuturesMeasure.put ("CTDSpotPrice", dblCTDSpotPrice);

  674.         if (org.drip.numerical.common.NumberUtil.IsValid (dblCTDRepoRate) &&
  675.             org.drip.numerical.common.NumberUtil.IsValid (dblCTDTreasuryYield))
  676.             mapBondFuturesMeasure.put ("CostOfCarry", dblCTDRepoRate - dblCTDTreasuryYield);

  677.         org.drip.param.definition.ProductQuote pqFutures = csqc.productQuote (name());

  678.         if (null != pqFutures && pqFutures.containsQuote ("Price")) {
  679.             double dblFuturesQuote = pqFutures.quote ("Price").value ("mid");

  680.             if (org.drip.numerical.common.NumberUtil.IsValid (dblFuturesQuote)) {
  681.                 if (iExpiryDate > iValueDate) {
  682.                     double dblImpliedRepoRate = 365.25 * (((dblFuturesQuote - dblCTDSpotPrice) /
  683.                         dblCTDSpotPrice) - 1.) / (iExpiryDate - iValueDate);

  684.                     mapBondFuturesMeasure.put ("ImpliedRepo", dblImpliedRepoRate);

  685.                     mapBondFuturesMeasure.put ("ImpliedRepoRate", dblImpliedRepoRate);

  686.                     if (org.drip.numerical.common.NumberUtil.IsValid (dblCTDRepoRate))
  687.                         mapBondFuturesMeasure.put ("NetBasis", dblImpliedRepoRate - dblCTDRepoRate);
  688.                 }

  689.                 double dblSettlementAmount = dblFuturesQuote * dblCTDConversionFactor - dblCTDForwardPrice;

  690.                 mapBondFuturesMeasure.put ("PV", dblSettlementAmount);

  691.                 mapBondFuturesMeasure.put ("SettlementAmount", dblSettlementAmount);

  692.                 mapBondFuturesMeasure.put ("SettlePV", dblSettlementAmount);

  693.                 org.drip.state.discount.MergedDiscountForwardCurve dcFunding = csqc.fundingState
  694.                     (fundingLabel());

  695.                 if (null != dcFunding) {
  696.                     try {
  697.                         mapBondFuturesMeasure.put ("SpotPV", dblSettlementAmount * dcFunding.df
  698.                             (iExpiryDate));
  699.                     } catch (java.lang.Exception e) {
  700.                         e.printStackTrace();
  701.                     }
  702.                 }
  703.             }
  704.         }

  705.         return mapBondFuturesMeasure;
  706.     }

  707.     @Override public java.util.Set<java.lang.String> measureNames()
  708.     {
  709.         java.util.Set<java.lang.String> setMeasure = _aBond[0].measureNames();

  710.         setMeasure.add ("CostOfCarry");

  711.         setMeasure.add ("CTDConversionFactor");

  712.         setMeasure.add ("CTDForwardPrice");

  713.         setMeasure.add ("CTDRepoRate");

  714.         setMeasure.add ("CTDSpotPrice");

  715.         setMeasure.add ("CTDTreasuryYield");

  716.         setMeasure.add ("ImpliedRepo");

  717.         setMeasure.add ("ImpliedRepoRate");

  718.         setMeasure.add ("NetBasis");

  719.         setMeasure.add ("PV");

  720.         setMeasure.add ("SettlementAmount");

  721.         setMeasure.add ("SettlePV");

  722.         setMeasure.add ("SpotPV");

  723.         return setMeasure;
  724.     }

  725.     @Override public double pv (
  726.         final org.drip.param.valuation.ValuationParams valParams,
  727.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  728.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  729.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  730.         throws java.lang.Exception
  731.     {
  732.         int iNumBond = _aBond.length;
  733.         double[] adblCleanPrice = new double[iNumBond];

  734.         int iValueDate = valParams.valueDate();

  735.         for (int i = 0; i < iNumBond; ++i) {
  736.             org.drip.param.definition.ProductQuote pqBond = csqc.productQuote (_aBond[i].name());

  737.             if (null == pqBond || !pqBond.containsQuote ("Price") ||
  738.                 !org.drip.numerical.common.NumberUtil.IsValid (adblCleanPrice[i] = pqBond.quote ("Price").value
  739.                     ("mid")))
  740.                 throw new java.lang.Exception ("BondFutures::pv - Invalid Inputs");
  741.         }

  742.         org.drip.product.params.CTDEntry ctdEntry = cheapestToDeliverYield (iValueDate, adblCleanPrice);

  743.         if (null == ctdEntry || null == csqc)
  744.             throw new java.lang.Exception ("BondFutures::pv - Invalid Inputs");

  745.         double dblFuturesQuote = java.lang.Double.NaN;

  746.         double dblCTDForwardPrice = ctdEntry.forwardPrice();

  747.         double dblCTDConversionFactor = ctdEntry.conversionFactor();

  748.         org.drip.param.definition.ProductQuote pqFutures = csqc.productQuote (name());

  749.         if (null != pqFutures && pqFutures.containsQuote ("Price"))
  750.             dblFuturesQuote = pqFutures.quote ("Price").value ("mid");

  751.         double dblAccrued = ctdEntry.bond().accrued (iValueDate, csqc);

  752.         return org.drip.numerical.common.NumberUtil.IsValid (dblFuturesQuote) ? dblFuturesQuote *
  753.             dblCTDConversionFactor + dblAccrued : dblCTDForwardPrice + dblAccrued;
  754.     }
  755. }