UST02Y.java

  1. package org.drip.sample.treasuryfutures;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.daycount.Convention;
  5. import org.drip.analytics.output.BondRVMeasures;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.param.creator.MarketParamsBuilder;
  8. import org.drip.param.market.CurveSurfaceQuoteContainer;
  9. import org.drip.param.quote.*;
  10. import org.drip.param.valuation.*;
  11. import org.drip.product.credit.*;
  12. import org.drip.product.definition.*;
  13. import org.drip.product.govvie.TreasuryFutures;
  14. import org.drip.service.env.EnvManager;
  15. import org.drip.service.template.*;
  16. import org.drip.state.creator.ScenarioRepoCurveBuilder;
  17. import org.drip.state.discount.MergedDiscountForwardCurve;
  18. import org.drip.state.govvie.GovvieCurve;

  19. /*
  20.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  21.  */

  22. /*!
  23.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  24.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  25.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  26.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  27.  *
  28.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  29.  *      libraries targeting analysts and developers
  30.  *      https://lakshmidrip.github.io/DRIP/
  31.  *  
  32.  *  DRIP is composed of four main libraries:
  33.  *  
  34.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  35.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  36.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  37.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  38.  *
  39.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  40.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  41.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  42.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  43.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  44.  *
  45.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  46.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  47.  *
  48.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  49.  *
  50.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  51.  *
  52.  *  Licensed under the Apache License, Version 2.0 (the "License");
  53.  *      you may not use this file except in compliance with the License.
  54.  *  
  55.  *  You may obtain a copy of the License at
  56.  *      http://www.apache.org/licenses/LICENSE-2.0
  57.  *  
  58.  *  Unless required by applicable law or agreed to in writing, software
  59.  *      distributed under the License is distributed on an "AS IS" BASIS,
  60.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  61.  *  
  62.  *  See the License for the specific language governing permissions and
  63.  *      limitations under the License.
  64.  */

  65. /**
  66.  * UST02Y demonstrates the Details behind the Implementation and the Pricing of the 2Y TU1 UST Futures
  67.  *  Contract.
  68.  *
  69.  * @author Lakshmi Krishnamurthy
  70.  */

  71. public class UST02Y {

  72.     private static final MergedDiscountForwardCurve FundingCurve (
  73.         final JulianDate dtSpot,
  74.         final String strCurrency)
  75.         throws Exception
  76.     {
  77.         String[] astrDepositMaturityTenor = new String[] {
  78.             "2D",
  79.             "1W",
  80.             "1M",
  81.             "2M",
  82.             "3M"
  83.         };

  84.         double[] adblDepositQuote = new double[] {
  85.             0.00195, // 2D
  86.             0.00176, // 1W
  87.             0.00301, // 1M
  88.             0.00401, // 2M
  89.             0.00492  // 3M
  90.         };

  91.         double[] adblFuturesQuote = new double[] {
  92.             0.00609,
  93.             0.00687
  94.         };

  95.         String[] astrFixFloatMaturityTenor = new String[] {
  96.             "01Y",
  97.             "02Y",
  98.             "03Y",
  99.             "04Y",
  100.             "05Y",
  101.             "06Y",
  102.             "07Y",
  103.             "08Y",
  104.             "09Y",
  105.             "10Y",
  106.             "11Y",
  107.             "12Y",
  108.             "15Y",
  109.             "20Y",
  110.             "25Y",
  111.             "30Y",
  112.             "40Y",
  113.             "50Y"
  114.         };

  115.         double[] adblFixFloatQuote = new double[] {
  116.             0.00762, //  1Y
  117.             0.01055, //  2Y
  118.             0.01300, //  3Y
  119.             0.01495, //  4Y
  120.             0.01651, //  5Y
  121.             0.01787, //  6Y
  122.             0.01904, //  7Y
  123.             0.02005, //  8Y
  124.             0.02090, //  9Y
  125.             0.02166, // 10Y
  126.             0.02231, // 11Y
  127.             0.02289, // 12Y
  128.             0.02414, // 15Y
  129.             0.02570, // 20Y
  130.             0.02594, // 25Y
  131.             0.02627, // 30Y
  132.             0.02648, // 40Y
  133.             0.02632  // 50Y
  134.         };

  135.         MergedDiscountForwardCurve dcFunding = LatentMarketStateBuilder.SmoothFundingCurve (
  136.             dtSpot,
  137.             strCurrency,
  138.             astrDepositMaturityTenor,
  139.             adblDepositQuote,
  140.             "ForwardRate",
  141.             adblFuturesQuote,
  142.             "ForwardRate",
  143.             astrFixFloatMaturityTenor,
  144.             adblFixFloatQuote,
  145.             "SwapRate"
  146.         );

  147.         Component[] aDepositComp = OTCInstrumentBuilder.FundingDeposit (
  148.             dtSpot,
  149.             strCurrency,
  150.             astrDepositMaturityTenor
  151.         );

  152.         Component[] aFuturesComp = ExchangeInstrumentBuilder.ForwardRateFuturesPack (
  153.             dtSpot,
  154.             adblFuturesQuote.length,
  155.             strCurrency
  156.         );

  157.         Component[] aFixFloatComp = OTCInstrumentBuilder.FixFloatStandard (
  158.             dtSpot,
  159.             strCurrency,
  160.             "ALL",
  161.             astrFixFloatMaturityTenor,
  162.             "MAIN",
  163.             0.
  164.         );

  165.         ValuationParams valParams = new ValuationParams (
  166.             dtSpot,
  167.             dtSpot,
  168.             strCurrency
  169.         );

  170.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  171.             dcFunding,
  172.             null,
  173.             null,
  174.             null,
  175.             null,
  176.             null,
  177.             null
  178.         );

  179.         System.out.println ("\n\n\t|------------------------------------||");

  180.         System.out.println ("\t|       DEPOSIT INPUT vs. CALC       ||");

  181.         System.out.println ("\t|------------------------------------||");

  182.         for (int i = 0; i < aDepositComp.length; ++i)
  183.             System.out.println ("\t| [" + aDepositComp[i].maturityDate() + "] =" +
  184.                 FormatUtil.FormatDouble (aDepositComp[i].measureValue (
  185.                     valParams,
  186.                     null,
  187.                     csqc,
  188.                     null,
  189.                     "ForwardRate"
  190.                 ), 1, 6, 1.) + " |" +
  191.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.) + " ||"
  192.             );

  193.         System.out.println ("\t|------------------------------------||");

  194.         System.out.println ("\n\t|------------------------------------||");

  195.         System.out.println ("\t|       FUTURES INPUT vs. CALC       ||");

  196.         System.out.println ("\t|------------------------------------||");

  197.         for (int i = 0; i < aFuturesComp.length; ++i)
  198.             System.out.println ("\t| [" + aFuturesComp[i].maturityDate() + "] =" +
  199.                 FormatUtil.FormatDouble (aFuturesComp[i].measureValue (
  200.                     valParams,
  201.                     null,
  202.                     csqc,
  203.                     null,
  204.                     "ForwardRate"
  205.                 ), 1, 6, 1.) + " |" +
  206.                 FormatUtil.FormatDouble (adblFuturesQuote[i], 1, 6, 1.) + " ||"
  207.             );

  208.         System.out.println ("\t|------------------------------------||");

  209.         System.out.println ("\n\t|-----------------------------------------------|| ");

  210.         System.out.println ("\t|         FIX-FLOAT INPUTS vs CALIB             ||");

  211.         System.out.println ("\t|-----------------------------------------------|| ");

  212.         for (int i = 0; i < aFixFloatComp.length; ++i)
  213.             System.out.println ("\t| [" + aFixFloatComp[i].maturityDate() + "] =" +
  214.                 FormatUtil.FormatDouble (aFixFloatComp[i].measureValue (
  215.                     valParams,
  216.                     null,
  217.                     csqc,
  218.                     null,
  219.                     "CalibSwapRate"
  220.                 ), 1, 6, 1.) + " |" +
  221.                 FormatUtil.FormatDouble (adblFixFloatQuote[i], 1, 6, 1.) + " |" +
  222.                 FormatUtil.FormatDouble (aFixFloatComp[i].measureValue (
  223.                     valParams,
  224.                     null,
  225.                     csqc,
  226.                     null,
  227.                     "FairPremium"
  228.                 ), 1, 6, 1.) + " ||"
  229.             );

  230.         System.out.println ("\t|-----------------------------------------------|| \n");

  231.         return dcFunding;
  232.     }

  233.     private static final void OnTheRunQuote (
  234.         final CurveSurfaceQuoteContainer csqc,
  235.         final String[] astrOnTheRunCode,
  236.         final double[] adblYield)
  237.         throws Exception
  238.     {
  239.         for (int i = 0; i < astrOnTheRunCode.length; ++i) {
  240.             ProductMultiMeasure pmmq = new ProductMultiMeasure();

  241.             pmmq.addQuote (
  242.                 "Yield",
  243.                 new MultiSided (
  244.                     "mid",
  245.                     adblYield[i]
  246.                 ),
  247.                 true
  248.             );

  249.             csqc.setProductQuote (
  250.                 astrOnTheRunCode[i],
  251.                 pmmq
  252.             );
  253.         }
  254.     }

  255.     private static final void FuturesQuote (
  256.         final CurveSurfaceQuoteContainer csqc,
  257.         final TreasuryFutures bf,
  258.         final double dblFuturesPrice)
  259.         throws Exception
  260.     {
  261.         ProductMultiMeasure pmmq = new ProductMultiMeasure();

  262.         pmmq.addQuote (
  263.             "Price",
  264.             new MultiSided (
  265.                 "mid",
  266.                 dblFuturesPrice
  267.             ),
  268.             true
  269.         );

  270.         csqc.setProductQuote (
  271.             bf.name(),
  272.             pmmq
  273.         );
  274.     }

  275.     private static final void RepoCurves (
  276.         final JulianDate dtSpot,
  277.         final CurveSurfaceQuoteContainer csqc,
  278.         final Bond[] aBond,
  279.         final double[] adblRepoRate)
  280.         throws Exception
  281.     {
  282.         for (int i = 0; i < aBond.length; ++i) {
  283.             csqc.setRepoState (
  284.                 ScenarioRepoCurveBuilder.FlatRateRepoCurve (
  285.                     dtSpot,
  286.                     aBond[i],
  287.                     adblRepoRate[i]
  288.                 )
  289.             );
  290.         }
  291.     }

  292.     private static final GovvieCurve TreasuryCurve (
  293.         final JulianDate dtSpot,
  294.         final String strCode,
  295.         final double[] adblCoupon,
  296.         final double[] adblYield)
  297.         throws Exception
  298.     {
  299.         JulianDate[] adtEffective = new JulianDate[] {
  300.             dtSpot,
  301.             dtSpot,
  302.             dtSpot,
  303.             dtSpot,
  304.             dtSpot,
  305.             dtSpot,
  306.             dtSpot
  307.         };

  308.         JulianDate[] adtMaturity = new JulianDate[] {
  309.             dtSpot.addTenor ("1Y"),
  310.             dtSpot.addTenor ("2Y"),
  311.             dtSpot.addTenor ("3Y"),
  312.             dtSpot.addTenor ("5Y"),
  313.             dtSpot.addTenor ("7Y"),
  314.             dtSpot.addTenor ("10Y"),
  315.             dtSpot.addTenor ("30Y")
  316.         };

  317.         GovvieCurve gc = LatentMarketStateBuilder.ShapePreservingGovvieCurve (
  318.             strCode,
  319.             dtSpot,
  320.             adtEffective,
  321.             adtMaturity,
  322.             adblCoupon,
  323.             adblYield,
  324.             "Yield"
  325.         );

  326.         BondComponent[] aComp = TreasuryBuilder.FromCode (
  327.             strCode,
  328.             adtEffective,
  329.             adtMaturity,
  330.             adblCoupon
  331.         );

  332.         ValuationParams valParams = new ValuationParams (
  333.             dtSpot,
  334.             dtSpot,
  335.             "USD"
  336.         );

  337.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  338.         csqc.setGovvieState (gc);

  339.         System.out.println ("\n\t|--------------------------------------------||");

  340.         System.out.println ("\t|       TREASURY INPUT vs CALIB YIELD        ||");

  341.         System.out.println ("\t|--------------------------------------------||");

  342.         for (int i = 0; i < aComp.length; ++i)
  343.             System.out.println ("\t| " + aComp[i].name() + " | " +
  344.                 FormatUtil.FormatDouble (adblYield[i], 2, 2, 100.) + "% | " +
  345.                 FormatUtil.FormatDouble (aComp[i].yieldFromPrice (
  346.                     valParams,
  347.                     null,
  348.                     null,
  349.                     aComp[i].maturityDate().julian(),
  350.                     1.,
  351.                     aComp[i].priceFromYield (
  352.                         valParams,
  353.                         null,
  354.                         null,
  355.                         gc.yield (aComp[i].maturityDate().julian())
  356.                     )
  357.                 ), 2, 2, 100.) + "% ||"
  358.             );

  359.         System.out.println ("\t|--------------------------------------------||");

  360.         return gc;
  361.     }

  362.     private static final void AccumulateBondMarketQuote (
  363.         final CurveSurfaceQuoteContainer csqc,
  364.         final Bond[] aBond,
  365.         final double[] adblCleanPrice)
  366.         throws Exception
  367.     {
  368.         for (int i = 0; i < aBond.length; ++i) {
  369.             ProductMultiMeasure pmmq = new ProductMultiMeasure();

  370.             pmmq.addQuote (
  371.                 "Price",
  372.                 new MultiSided (
  373.                     "mid",
  374.                     adblCleanPrice[i]
  375.                 ),
  376.                 true
  377.             );

  378.             csqc.setProductQuote (
  379.                 aBond[i].name(),
  380.                 pmmq
  381.             );
  382.         }
  383.     }

  384.     /*
  385.      * Print the Bond RV Measures
  386.      *
  387.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  388.      */

  389.     private static final boolean PrintRVMeasures (
  390.         final String strPrefix,
  391.         final BondRVMeasures rv)
  392.         throws Exception
  393.     {
  394.         if (null == rv) return false;

  395.         System.out.println (strPrefix + "ASW               : " + FormatUtil.FormatDouble (rv.asw(), 2, 0, 10000.));

  396.         System.out.println (strPrefix + "Bond Basis        : " + FormatUtil.FormatDouble (rv.bondBasis(), 2, 0, 10000.));

  397.         System.out.println (strPrefix + "Convexity         : " + FormatUtil.FormatDouble (rv.convexity(), 1, 4, 1000000.));

  398.         System.out.println (strPrefix + "Discount Margin   : " + FormatUtil.FormatDouble (rv.discountMargin(), 2, 0, 10000.));

  399.         System.out.println (strPrefix + "G Spread          : " + FormatUtil.FormatDouble (rv.gSpread(), 2, 0, 10000.));

  400.         System.out.println (strPrefix + "I Spread          : " + FormatUtil.FormatDouble (rv.iSpread(), 2, 0, 10000.));

  401.         System.out.println (strPrefix + "Macaulay Duration : " + FormatUtil.FormatDouble (rv.macaulayDuration(), 1, 4, 1.));

  402.         System.out.println (strPrefix + "Modified Duration : " + FormatUtil.FormatDouble (rv.modifiedDuration(), 1, 4, 10000.));

  403.         System.out.println (strPrefix + "Price             : " + FormatUtil.FormatDouble (rv.price(), 2, 4, 100.));

  404.         System.out.println (strPrefix + "Workout Date      : " + new JulianDate (rv.wi().date()));

  405.         System.out.println (strPrefix + "Workout Factor    : " + FormatUtil.FormatDouble (rv.wi().factor(), 2, 4, 1.));

  406.         System.out.println (strPrefix + "Workout Type      : " + rv.wi().type());

  407.         System.out.println (strPrefix + "Workout Yield     : " + FormatUtil.FormatDouble (rv.wi().yield(), 1, 4, 100.) + "%");

  408.         System.out.println (strPrefix + "Yield01           : " + FormatUtil.FormatDouble (rv.yield01(), 1, 4, 10000.));

  409.         System.out.println (strPrefix + "Yield Basis       : " + FormatUtil.FormatDouble (rv.bondBasis(), 2, 0, 10000.));

  410.         System.out.println (strPrefix + "Yield Spread      : " + FormatUtil.FormatDouble (rv.bondBasis(), 2, 0, 10000.));

  411.         System.out.println (strPrefix + "Z Spread          : " + FormatUtil.FormatDouble (rv.zSpread(), 2, 0, 10000.));

  412.         return true;
  413.     }

  414.     private static final void BondRVMeasuresSample (
  415.         final BondComponent bond,
  416.         final JulianDate dtSpot,
  417.         final CurveSurfaceQuoteContainer csqc,
  418.         final double dblPrice)
  419.         throws Exception
  420.     {

  421.         ValuationParams valParams = ValuationParams.Spot (
  422.             dtSpot,
  423.             0,
  424.             "",
  425.             Convention.DATE_ROLL_ACTUAL
  426.         );

  427.         /*
  428.          * Compute the work-out date given the price.
  429.          */

  430.         WorkoutInfo wi = bond.exerciseYieldFromPrice (
  431.             valParams,
  432.             csqc,
  433.             null,
  434.             dblPrice
  435.         );

  436.         /*
  437.          * Compute the base RV measures to the work-out date.
  438.          */

  439.         org.drip.analytics.output.BondRVMeasures rvm = bond.standardMeasures (
  440.             valParams,
  441.             null,
  442.             csqc,
  443.             null,
  444.             wi,
  445.             dblPrice
  446.         );

  447.         System.out.println ("\t|---------------------------------------------||\n");

  448.         PrintRVMeasures ("\t|\t", rvm);

  449.         Map<String, Double> mapOutput = bond.value (
  450.             valParams,
  451.             null,
  452.             csqc,
  453.             null
  454.         );

  455.         System.out.println ("\t|---------------------------------------------||\n");

  456.         System.out.println ("\n\t|--------------------------------------------------------------------------||");

  457.         System.out.println ("\t|                  CTD Full Bond Measures                                  ||");

  458.         System.out.println ("\t|--------------------------------------------------------------------------||");

  459.         for (Map.Entry<String, Double> me : mapOutput.entrySet())
  460.             System.out.println ("\t|\t" + me.getKey() + " => " + me.getValue());

  461.         System.out.println ("\t|--------------------------------------------------------------------------||");
  462.     }

  463.     private static final void ComputeFuturesMeasures (
  464.         final TreasuryFutures bf,
  465.         final JulianDate dtSpot,
  466.         final CurveSurfaceQuoteContainer csqc,
  467.         final double[] adblCleanPrice)
  468.         throws Exception
  469.     {
  470.         ValuationParams valParams = ValuationParams.Spot (
  471.             dtSpot,
  472.             0,
  473.             "",
  474.             Convention.DATE_ROLL_ACTUAL
  475.         );

  476.         AccumulateBondMarketQuote (
  477.             csqc,
  478.             bf.basket(),
  479.             adblCleanPrice
  480.         );

  481.         Map<String, Double> mapOutput = bf.value (
  482.             valParams,
  483.             null,
  484.             csqc,
  485.             null
  486.         );

  487.         System.out.println ("\n\t|--------------------------------------------------------------------------||");

  488.         System.out.println ("\t|                  Bond Futures Measures                                   ||");

  489.         System.out.println ("\t|--------------------------------------------------------------------------||");

  490.         for (Map.Entry<String, Double> me : mapOutput.entrySet())
  491.             System.out.println ("\t|\t" + me.getKey() + " => " + me.getValue());

  492.         System.out.println ("\t|--------------------------------------------------------------------------||");
  493.     }

  494.     public static final void main (
  495.         final String[] astrArgs)
  496.         throws Exception
  497.     {
  498.         EnvManager.InitEnv ("");

  499.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  500.             2015,
  501.             DateUtil.NOVEMBER,
  502.             18
  503.         );

  504.         String strCurrency = "USD";
  505.         String strTreasuryCode = "UST";

  506.         MergedDiscountForwardCurve dcFunding = FundingCurve (
  507.             dtSpot,
  508.             strCurrency
  509.         );

  510.         double[] adblTreasuryCoupon = new double[] {
  511.             0.0100,
  512.             0.0100,
  513.             0.0125,
  514.             0.0150,
  515.             0.0200,
  516.             0.0225,
  517.             0.0300
  518.         };

  519.         double[] adblTreasuryYield = new double[] {
  520.             0.00692,
  521.             0.00945,
  522.             0.01257,
  523.             0.01678,
  524.             0.02025,
  525.             0.02235,
  526.             0.02972
  527.         };

  528.         GovvieCurve gc = TreasuryCurve (
  529.             dtSpot,
  530.             strTreasuryCode,
  531.             adblTreasuryCoupon,
  532.             adblTreasuryYield
  533.         );

  534.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  535.             dcFunding,
  536.             null,
  537.             null,
  538.             null,
  539.             null,
  540.             null,
  541.             null
  542.         );

  543.         csqc.setGovvieState (gc);

  544.         OnTheRunQuote (
  545.             csqc,
  546.             new String[] {
  547.                 "01YON",
  548.                 "02YON",
  549.                 "03YON",
  550.                 "05YON",
  551.                 "07YON",
  552.                 "10YON",
  553.                 "30YON"
  554.             },
  555.             adblTreasuryYield
  556.         );

  557.         Bond ust912828UE = TreasuryBuilder.UST (
  558.             DateUtil.CreateFromYMD (
  559.                 2014,
  560.                 DateUtil.DECEMBER,
  561.                 31
  562.             ),
  563.             DateUtil.CreateFromYMD (
  564.                 2017,
  565.                 DateUtil.DECEMBER,
  566.                 31
  567.             ),
  568.             0.00750
  569.         );

  570.         Bond ust912828G7 = TreasuryBuilder.UST (
  571.             DateUtil.CreateFromYMD (
  572.                 2014,
  573.                 DateUtil.DECEMBER,
  574.                 15
  575.             ),
  576.             DateUtil.CreateFromYMD (
  577.                 2017,
  578.                 DateUtil.DECEMBER,
  579.                 15
  580.             ),
  581.             0.01000
  582.         );

  583.         Bond ust912828UA = TreasuryBuilder.UST (
  584.             DateUtil.CreateFromYMD (
  585.                 2014,
  586.                 DateUtil.NOVEMBER,
  587.                 30
  588.             ),
  589.             DateUtil.CreateFromYMD (
  590.                 2017,
  591.                 DateUtil.NOVEMBER,
  592.                 30
  593.             ),
  594.             0.00625
  595.         );

  596.         Bond ust912828G2 = TreasuryBuilder.UST (
  597.             DateUtil.CreateFromYMD (
  598.                 2014,
  599.                 DateUtil.NOVEMBER,
  600.                 15
  601.             ),
  602.             DateUtil.CreateFromYMD (
  603.                 2017,
  604.                 DateUtil.NOVEMBER,
  605.                 15
  606.             ),
  607.             0.00875
  608.         );

  609.         Bond ust912828TW = TreasuryBuilder.UST (
  610.             DateUtil.CreateFromYMD (
  611.                 2014,
  612.                 DateUtil.OCTOBER,
  613.                 31
  614.             ),
  615.             DateUtil.CreateFromYMD (
  616.                 2017,
  617.                 DateUtil.OCTOBER,
  618.                 31
  619.             ),
  620.             0.00750
  621.         );

  622.         Bond ust912828F5 = TreasuryBuilder.UST (
  623.             DateUtil.CreateFromYMD (
  624.                 2014,
  625.                 DateUtil.OCTOBER,
  626.                 15
  627.             ),
  628.             DateUtil.CreateFromYMD (
  629.                 2017,
  630.                 DateUtil.OCTOBER,
  631.                 17
  632.             ),
  633.             0.00875
  634.         );

  635.         Bond ust912828TS = TreasuryBuilder.UST (
  636.             DateUtil.CreateFromYMD (
  637.                 2014,
  638.                 DateUtil.SEPTEMBER,
  639.                 30
  640.             ),
  641.             DateUtil.CreateFromYMD (
  642.                 2017,
  643.                 DateUtil.SEPTEMBER,
  644.                 30
  645.             ),
  646.             0.00625
  647.         );

  648.         Bond ust912828D9 = TreasuryBuilder.UST (
  649.             DateUtil.CreateFromYMD (
  650.                 2014,
  651.                 DateUtil.SEPTEMBER,
  652.                 15
  653.             ),
  654.             DateUtil.CreateFromYMD (
  655.                 2017,
  656.                 DateUtil.SEPTEMBER,
  657.                 15
  658.             ),
  659.             0.01000
  660.         );

  661.         Bond[] aBond = new Bond[] {
  662.             ust912828UE,
  663.             ust912828G7,
  664.             ust912828UA,
  665.             ust912828G2,
  666.             ust912828TW,
  667.             ust912828F5,
  668.             ust912828TS,
  669.             ust912828D9
  670.         };

  671.         double dblContractSize = 200000.;
  672.         double dblFuturesPrice = 1.0808594;

  673.         TreasuryFutures tu1 = new TreasuryFutures (
  674.             aBond,
  675.             new double[] {
  676.                 0.9024, // 912828UE
  677.                 0.9071, // 912828G7
  678.                 0.9040, // 912828UA
  679.                 0.9085, // 912828G2
  680.                 0.9101, // 912828TW
  681.                 0.9122, // 912828F5
  682.                 0.9119, // 912828TS
  683.                 0.9181, // 912828D9
  684.             },
  685.             null
  686.         );

  687.         double[] adblRepoRate = new double[] {
  688.              0.00800,
  689.              0.00825,
  690.              0.00850,
  691.              0.00875,
  692.              0.00900,
  693.              0.00925,
  694.              0.00950,
  695.              0.01000
  696.         };

  697.         RepoCurves (
  698.             dtSpot,
  699.             csqc,
  700.             aBond,
  701.             adblRepoRate
  702.         );

  703.         tu1.setExpiry (
  704.             DateUtil.CreateFromYMD (
  705.                 2016,
  706.                 DateUtil.FEBRUARY,
  707.                 15
  708.             )
  709.         );

  710.         double[] adblCleanPrice = new double[] {
  711.              0.9956250,
  712.              1.0009375,
  713.              0.9937500,
  714.              0.9990625,
  715.              0.9975000,
  716.              1.0000000,
  717.              0.9953125,
  718.              1.0025000
  719.         };

  720.         FuturesQuote (
  721.             csqc,
  722.             tu1,
  723.             dblFuturesPrice
  724.         );

  725.         Bond bondCTD = tu1.cheapestToDeliverYield (
  726.             dtSpot.julian(),
  727.             adblCleanPrice
  728.         ).bond();

  729.         System.out.println ("\n\t|---------------------------------------------||");

  730.         System.out.println ("\t|                                             ||");

  731.         System.out.println ("\t|       Bond #1: " + ust912828UE.name() + "       ||");

  732.         System.out.println ("\t|       Bond #2: " + ust912828G7.name() + "       ||");

  733.         System.out.println ("\t|       Bond #3: " + ust912828UA.name() + "       ||");

  734.         System.out.println ("\t|       Bond #4: " + ust912828G2.name() + "       ||");

  735.         System.out.println ("\t|       Bond #5: " + ust912828TW.name() + "       ||");

  736.         System.out.println ("\t|       Bond #6: " + ust912828F5.name() + "       ||");

  737.         System.out.println ("\t|       Bond #7: " + ust912828TS.name() + "       ||");

  738.         System.out.println ("\t|       Bond #8: " + ust912828D9.name() + "       ||");

  739.         System.out.println ("\t|                                             ||");

  740.         System.out.println ("\t|---------------------------------------------||");

  741.         System.out.println ("\t| Cheapest to Deliver: " + bondCTD.name() + " ||");

  742.         BondRVMeasuresSample (
  743.             (BondComponent) bondCTD,
  744.             dtSpot,
  745.             csqc,
  746.             1.0025000
  747.         );

  748.         ComputeFuturesMeasures (
  749.             tu1,
  750.             dtSpot,
  751.             csqc,
  752.             adblCleanPrice
  753.         );

  754.         System.out.println ("\n\t|---------------------------------------------||");

  755.         System.out.println ("\t|      Futures Price  : " + FormatUtil.FormatDouble (dblFuturesPrice, 2, 5, 100.) + "            ||");

  756.         System.out.println ("\t|      Contract Size  : " + FormatUtil.FormatDouble (dblContractSize, 1, 2, 1.) + "            ||");

  757.         System.out.println ("\t|      Contract Value : " + FormatUtil.FormatDouble (dblContractSize * dblFuturesPrice, 1, 2, 1.) + "            ||");

  758.         System.out.println ("\t|---------------------------------------------||\n");
  759.     }
  760. }