UST30Y.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.  * UST30Y demonstrates the Details behind the Implementation and the Pricing of the 30Y LONG BOND US1 UST
  67.  *  Futures Contract.
  68.  *
  69.  * @author Lakshmi Krishnamurthy
  70.  */

  71. public class UST30Y {

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

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

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

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

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

  336.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  337.         csqc.setGovvieState (gc);

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

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

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

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

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

  359.         return gc;
  360.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  411.         return true;
  412.     }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  542.         csqc.setGovvieState (gc);

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

  556.         Bond ust912810FT = TreasuryBuilder.UST (
  557.             DateUtil.CreateFromYMD (
  558.                 2014,
  559.                 DateUtil.FEBRUARY,
  560.                 15
  561.             ),
  562.             DateUtil.CreateFromYMD (
  563.                 2036,
  564.                 DateUtil.FEBRUARY,
  565.                 15
  566.             ),
  567.             0.04500
  568.         );

  569.         Bond ust912810PU = TreasuryBuilder.UST (
  570.             DateUtil.CreateFromYMD (
  571.                 2014,
  572.                 DateUtil.MAY,
  573.                 15
  574.             ),
  575.             DateUtil.CreateFromYMD (
  576.                 2037,
  577.                 DateUtil.MAY,
  578.                 15
  579.             ),
  580.             0.05000
  581.         );

  582.         Bond ust912810PT = TreasuryBuilder.UST (
  583.             DateUtil.CreateFromYMD (
  584.                 2014,
  585.                 DateUtil.FEBRUARY,
  586.                 15
  587.             ),
  588.             DateUtil.CreateFromYMD (
  589.                 2037,
  590.                 DateUtil.FEBRUARY,
  591.                 15
  592.             ),
  593.             0.04750
  594.         );

  595.         Bond ust912810PX = TreasuryBuilder.UST (
  596.             DateUtil.CreateFromYMD (
  597.                 2014,
  598.                 DateUtil.MAY,
  599.                 15
  600.             ),
  601.             DateUtil.CreateFromYMD (
  602.                 2038,
  603.                 DateUtil.MAY,
  604.                 15
  605.             ),
  606.             0.04500
  607.         );

  608.         Bond ust912810PW = TreasuryBuilder.UST (
  609.             DateUtil.CreateFromYMD (
  610.                 2014,
  611.                 DateUtil.FEBRUARY,
  612.                 15
  613.             ),
  614.             DateUtil.CreateFromYMD (
  615.                 2038,
  616.                 DateUtil.FEBRUARY,
  617.                 15
  618.             ),
  619.             0.04375
  620.         );

  621.         Bond ust912810QC = TreasuryBuilder.UST (
  622.             DateUtil.CreateFromYMD (
  623.                 2014,
  624.                 DateUtil.AUGUST,
  625.                 15
  626.             ),
  627.             DateUtil.CreateFromYMD (
  628.                 2039,
  629.                 DateUtil.AUGUST,
  630.                 15
  631.             ),
  632.             0.04500
  633.         );

  634.         Bond ust912810QE = TreasuryBuilder.UST (
  635.             DateUtil.CreateFromYMD (
  636.                 2014,
  637.                 DateUtil.FEBRUARY,
  638.                 15
  639.             ),
  640.             DateUtil.CreateFromYMD (
  641.                 2040,
  642.                 DateUtil.FEBRUARY,
  643.                 15
  644.             ),
  645.             0.04625
  646.         );

  647.         Bond ust912810QB = TreasuryBuilder.UST (
  648.             DateUtil.CreateFromYMD (
  649.                 2014,
  650.                 DateUtil.MAY,
  651.                 15
  652.             ),
  653.             DateUtil.CreateFromYMD (
  654.                 2039,
  655.                 DateUtil.MAY,
  656.                 15
  657.             ),
  658.             0.04250
  659.         );

  660.         Bond ust912810QD = TreasuryBuilder.UST (
  661.             DateUtil.CreateFromYMD (
  662.                 2014,
  663.                 DateUtil.NOVEMBER,
  664.                 15
  665.             ),
  666.             DateUtil.CreateFromYMD (
  667.                 2039,
  668.                 DateUtil.NOVEMBER,
  669.                 15
  670.             ),
  671.             0.04375
  672.         );

  673.         Bond ust912810QH = TreasuryBuilder.UST (
  674.             DateUtil.CreateFromYMD (
  675.                 2014,
  676.                 DateUtil.MAY,
  677.                 15
  678.             ),
  679.             DateUtil.CreateFromYMD (
  680.                 2040,
  681.                 DateUtil.MAY,
  682.                 15
  683.             ),
  684.             0.04375
  685.         );

  686.         Bond ust912810QL = TreasuryBuilder.UST (
  687.             DateUtil.CreateFromYMD (
  688.                 2014,
  689.                 DateUtil.NOVEMBER,
  690.                 15
  691.             ),
  692.             DateUtil.CreateFromYMD (
  693.                 2040,
  694.                 DateUtil.NOVEMBER,
  695.                 15
  696.             ),
  697.             0.04250
  698.         );

  699.         Bond ust912810QK = TreasuryBuilder.UST (
  700.             DateUtil.CreateFromYMD (
  701.                 2014,
  702.                 DateUtil.AUGUST,
  703.                 15
  704.             ),
  705.             DateUtil.CreateFromYMD (
  706.                 2040,
  707.                 DateUtil.AUGUST,
  708.                 15
  709.             ),
  710.             0.03875
  711.         );

  712.         Bond ust912810QA = TreasuryBuilder.UST (
  713.             DateUtil.CreateFromYMD (
  714.                 2014,
  715.                 DateUtil.FEBRUARY,
  716.                 15
  717.             ),
  718.             DateUtil.CreateFromYMD (
  719.                 2039,
  720.                 DateUtil.FEBRUARY,
  721.                 15
  722.             ),
  723.             0.03500
  724.         );

  725.         double dblContractSize = 100000.;
  726.         double dblFuturesPrice = 1.5375000;

  727.         Bond[] aBond = new Bond[] {
  728.             ust912810FT,
  729.             ust912810PU,
  730.             ust912810PT,
  731.             ust912810PX,
  732.             ust912810PW,
  733.             ust912810QC,
  734.             ust912810QE,
  735.             ust912810QB,
  736.             ust912810QD,
  737.             ust912810QH,
  738.             ust912810QL,
  739.             ust912810QK,
  740.             ust912810QA
  741.         };

  742.         TreasuryFutures tu1 = new TreasuryFutures (
  743.             aBond,
  744.             new double[] {
  745.                 0.8266, // 912810FT
  746.                 0.8807, // 912810PU
  747.                 0.8519, // 912810PT
  748.                 0.8170, // 912810PX
  749.                 0.8029, // 912810PW
  750.                 0.8123, // 912810QC
  751.                 0.8263, // 912810QE
  752.                 0.7820, // 912810QB
  753.                 0.7956, // 912810QD
  754.                 0.7939, // 912810QH
  755.                 0.7758, // 912810QL
  756.                 0.7290, // 912810QK
  757.                 0.6903, // 912810QA
  758.             },
  759.             null
  760.         );

  761.         double[] adblRepoRate = new double[] {
  762.              0.00800,
  763.              0.00825,
  764.              0.00850,
  765.              0.00875,
  766.              0.00900,
  767.              0.00925,
  768.              0.00950,
  769.              0.00975,
  770.              0.01000,
  771.              0.01025,
  772.              0.01050,
  773.              0.01075,
  774.              0.01100
  775.         };

  776.         RepoCurves (
  777.             dtSpot,
  778.             csqc,
  779.             aBond,
  780.             adblRepoRate
  781.         );

  782.         tu1.setExpiry (
  783.             DateUtil.CreateFromYMD (
  784.                 2016,
  785.                 DateUtil.FEBRUARY,
  786.                 15
  787.             )
  788.         );

  789.         double[] adblCleanPrice = new double[] {
  790.             1.2765625,
  791.             1.3643750,
  792.             1.3203125,
  793.             1.2775000,
  794.             1.2556250,
  795.             1.2731250,
  796.             1.2956250,
  797.             1.2287500,
  798.             1.2506250,
  799.             1.2506250,
  800.             1.2281250,
  801.             1.1603125,
  802.             1.1009375
  803.         };

  804.         FuturesQuote (
  805.             csqc,
  806.             tu1,
  807.             dblFuturesPrice
  808.         );

  809.         Bond bondCTD = tu1.cheapestToDeliverYield (
  810.             dtSpot.julian(),
  811.             adblCleanPrice
  812.         ).bond();

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

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

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

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

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

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

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

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

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

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

  823.         System.out.println ("\t|       Bond # 9: " + ust912810QD.name() + "      ||");

  824.         System.out.println ("\t|       Bond #10: " + ust912810QH.name() + "      ||");

  825.         System.out.println ("\t|       Bond #11: " + ust912810QL.name() + "      ||");

  826.         System.out.println ("\t|       Bond #12: " + ust912810QK.name() + "      ||");

  827.         System.out.println ("\t|       Bond #13: " + ust912810QA.name() + "      ||");

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

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

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

  831.         BondRVMeasuresSample (
  832.             (BondComponent) bondCTD,
  833.             dtSpot,
  834.             csqc,
  835.             1.2765625
  836.         );

  837.         ComputeFuturesMeasures (
  838.             tu1,
  839.             dtSpot,
  840.             csqc,
  841.             adblCleanPrice
  842.         );

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

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

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

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

  847.         System.out.println ("\t|---------------------------------------------||\n");
  848.     }
  849. }