USTULTRA.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.  * USTULTRA demonstrates the Details behind the Implementation and the Pricing of the ULTRA LONG WN1 UST
  67.  *  Futures Contract.
  68.  *
  69.  * @author Lakshmi Krishnamurthy
  70.  */

  71. public class USTULTRA {

  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 ust912810QN = TreasuryBuilder.UST (
  557.             DateUtil.CreateFromYMD (
  558.                 2014,
  559.                 DateUtil.FEBRUARY,
  560.                 15
  561.             ),
  562.             DateUtil.CreateFromYMD (
  563.                 2041,
  564.                 DateUtil.FEBRUARY,
  565.                 15
  566.             ),
  567.             0.04750
  568.         );

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

  582.         Bond ust912810QS = TreasuryBuilder.UST (
  583.             DateUtil.CreateFromYMD (
  584.                 2014,
  585.                 DateUtil.AUGUST,
  586.                 15
  587.             ),
  588.             DateUtil.CreateFromYMD (
  589.                 2041,
  590.                 DateUtil.AUGUST,
  591.                 15
  592.             ),
  593.             0.03750
  594.         );

  595.         Bond ust912810RC = TreasuryBuilder.UST (
  596.             DateUtil.CreateFromYMD (
  597.                 2014,
  598.                 DateUtil.AUGUST,
  599.                 15
  600.             ),
  601.             DateUtil.CreateFromYMD (
  602.                 2043,
  603.                 DateUtil.AUGUST,
  604.                 15
  605.             ),
  606.             0.03625
  607.         );

  608.         Bond ust912810RD = TreasuryBuilder.UST (
  609.             DateUtil.CreateFromYMD (
  610.                 2014,
  611.                 DateUtil.NOVEMBER,
  612.                 15
  613.             ),
  614.             DateUtil.CreateFromYMD (
  615.                 2043,
  616.                 DateUtil.NOVEMBER,
  617.                 15
  618.             ),
  619.             0.03750
  620.         );

  621.         Bond ust912810QT = TreasuryBuilder.UST (
  622.             DateUtil.CreateFromYMD (
  623.                 2014,
  624.                 DateUtil.NOVEMBER,
  625.                 15
  626.             ),
  627.             DateUtil.CreateFromYMD (
  628.                 2041,
  629.                 DateUtil.NOVEMBER,
  630.                 15
  631.             ),
  632.             0.03125
  633.         );

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

  647.         Bond ust912810RE = TreasuryBuilder.UST (
  648.             DateUtil.CreateFromYMD (
  649.                 2014,
  650.                 DateUtil.FEBRUARY,
  651.                 15
  652.             ),
  653.             DateUtil.CreateFromYMD (
  654.                 2044,
  655.                 DateUtil.FEBRUARY,
  656.                 15
  657.             ),
  658.             0.03625
  659.         );

  660.         Bond ust912810QZ = TreasuryBuilder.UST (
  661.             DateUtil.CreateFromYMD (
  662.                 2014,
  663.                 DateUtil.FEBRUARY,
  664.                 15
  665.             ),
  666.             DateUtil.CreateFromYMD (
  667.                 2043,
  668.                 DateUtil.FEBRUARY,
  669.                 15
  670.             ),
  671.             0.03125
  672.         );

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

  686.         Bond ust912810RG = TreasuryBuilder.UST (
  687.             DateUtil.CreateFromYMD (
  688.                 2014,
  689.                 DateUtil.MAY,
  690.                 15
  691.             ),
  692.             DateUtil.CreateFromYMD (
  693.                 2044,
  694.                 DateUtil.MAY,
  695.                 15
  696.             ),
  697.             0.03625
  698.         );

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

  712.         Bond ust912810RB = TreasuryBuilder.UST (
  713.             DateUtil.CreateFromYMD (
  714.                 2014,
  715.                 DateUtil.MAY,
  716.                 15
  717.             ),
  718.             DateUtil.CreateFromYMD (
  719.                 2043,
  720.                 DateUtil.MAY,
  721.                 15
  722.             ),
  723.             0.02875
  724.         );

  725.         Bond ust912810QY = TreasuryBuilder.UST (
  726.             DateUtil.CreateFromYMD (
  727.                 2014,
  728.                 DateUtil.NOVEMBER,
  729.                 15
  730.             ),
  731.             DateUtil.CreateFromYMD (
  732.                 2042,
  733.                 DateUtil.NOVEMBER,
  734.                 15
  735.             ),
  736.             0.02750
  737.         );

  738.         Bond ust912810RH = TreasuryBuilder.UST (
  739.             DateUtil.CreateFromYMD (
  740.                 2014,
  741.                 DateUtil.AUGUST,
  742.                 15
  743.             ),
  744.             DateUtil.CreateFromYMD (
  745.                 2044,
  746.                 DateUtil.AUGUST,
  747.                 15
  748.             ),
  749.             0.03125
  750.         );

  751.         Bond ust912810RJ = TreasuryBuilder.UST (
  752.             DateUtil.CreateFromYMD (
  753.                 2014,
  754.                 DateUtil.NOVEMBER,
  755.                 15
  756.             ),
  757.             DateUtil.CreateFromYMD (
  758.                 2044,
  759.                 DateUtil.NOVEMBER,
  760.                 15
  761.             ),
  762.             0.03000
  763.         );

  764.         Bond ust912810RM = TreasuryBuilder.UST (
  765.             DateUtil.CreateFromYMD (
  766.                 2014,
  767.                 DateUtil.MAY,
  768.                 15
  769.             ),
  770.             DateUtil.CreateFromYMD (
  771.                 2045,
  772.                 DateUtil.MAY,
  773.                 15
  774.             ),
  775.             0.03000
  776.         );

  777.         Bond ust912810RP = TreasuryBuilder.UST (
  778.             DateUtil.CreateFromYMD (
  779.                 2014,
  780.                 DateUtil.NOVEMBER,
  781.                 15
  782.             ),
  783.             DateUtil.CreateFromYMD (
  784.                 2045,
  785.                 DateUtil.NOVEMBER,
  786.                 15
  787.             ),
  788.             0.03000
  789.         );

  790.         Bond ust912810RN = TreasuryBuilder.UST (
  791.             DateUtil.CreateFromYMD (
  792.                 2014,
  793.                 DateUtil.AUGUST,
  794.                 15
  795.             ),
  796.             DateUtil.CreateFromYMD (
  797.                 2045,
  798.                 DateUtil.AUGUST,
  799.                 15
  800.             ),
  801.             0.02875
  802.         );

  803.         Bond ust912810RK = TreasuryBuilder.UST (
  804.             DateUtil.CreateFromYMD (
  805.                 2014,
  806.                 DateUtil.FEBRUARY,
  807.                 15
  808.             ),
  809.             DateUtil.CreateFromYMD (
  810.                 2045,
  811.                 DateUtil.FEBRUARY,
  812.                 15
  813.             ),
  814.             0.02500
  815.         );

  816.         double dblContractSize = 100000.;
  817.         double dblFuturesPrice = 1.56687500;

  818.         Bond[] aBond = new Bond[] {
  819.             ust912810QN,
  820.             ust912810QQ,
  821.             ust912810QS,
  822.             ust912810RC,
  823.             ust912810RD,
  824.             ust912810QT,
  825.             ust912810QU,
  826.             ust912810RE,
  827.             ust912810QZ,
  828.             ust912810QW,
  829.             ust912810RG,
  830.             ust912810QX,
  831.             ust912810RB,
  832.             ust912810QY,
  833.             ust912810RH,
  834.             ust912810RJ,
  835.             ust912810RM,
  836.             ust912810RP,
  837.             ust912810RN,
  838.             ust912810RK
  839.         };

  840.         TreasuryFutures tu1 = new TreasuryFutures (
  841.             aBond,
  842.             new double[] {
  843.                 0.8392, // 912810QN
  844.                 0.7900, // 912810QQ
  845.                 0.7080, // 912810QS
  846.                 0.6821, // 912810RC
  847.                 0.6976, // 912810RD
  848.                 0.6253, // 912810QT
  849.                 0.6239, // 912810QU
  850.                 0.6798, // 912810RE
  851.                 0.6179, // 912810QZ
  852.                 0.6059, // 912810QW
  853.                 0.6448, // 912810RG
  854.                 0.5714, // 912810QX
  855.                 0.5831, // 912810RB
  856.                 0.5697, // 912810QY
  857.                 0.6097, // 912810RH
  858.                 0.5913, // 912810RJ
  859.                 0.5887, // 912810RM
  860.                 0.5861, // 912810RP
  861.                 0.5702, // 912810RN
  862.                 0.5217, // 912810RK
  863.             },
  864.             null
  865.         );

  866.         double[] adblRepoRate = new double[] {
  867.              0.00800,
  868.              0.00825,
  869.              0.00850,
  870.              0.00875,
  871.              0.00900,
  872.              0.00925,
  873.              0.00950,
  874.              0.00975,
  875.              0.01000,
  876.              0.01025,
  877.              0.01050,
  878.              0.01075,
  879.              0.01100,
  880.              0.01125,
  881.              0.01150,
  882.              0.01175,
  883.              0.01200,
  884.              0.01225,
  885.              0.01250,
  886.              0.01275
  887.         };

  888.         RepoCurves (
  889.             dtSpot,
  890.             csqc,
  891.             aBond,
  892.             adblRepoRate
  893.         );

  894.         tu1.setExpiry (
  895.             DateUtil.CreateFromYMD (
  896.                 2016,
  897.                 DateUtil.FEBRUARY,
  898.                 15
  899.             )
  900.         );

  901.         double[] adblCleanPrice = new double[] {
  902.             1.3200000,
  903.             1.2540625,
  904.             1.1412500,
  905.             1.1193750,
  906.             1.1450000,
  907.             1.0262500,
  908.             1.0256250,
  909.             1.1184375,
  910.             1.0181250,
  911.             0.9990625,
  912.             1.0659375,
  913.             0.9481250,
  914.             0.9681250,
  915.             0.9459375,
  916.             1.0153125,
  917.             0.9896875,
  918.             0.9890625,
  919.             0.9918750,
  920.             0.9656250,
  921.             0.8909375
  922.         };

  923.         FuturesQuote (
  924.             csqc,
  925.             tu1,
  926.             dblFuturesPrice
  927.         );

  928.         Bond bondCTD = tu1.cheapestToDeliverYield (
  929.             dtSpot.julian(),
  930.             adblCleanPrice
  931.         ).bond();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  947.         System.out.println ("\t|      Bond #14: " + ust912810QY.name() + "       ||");

  948.         System.out.println ("\t|      Bond #15: " + ust912810RH.name() + "       ||");

  949.         System.out.println ("\t|      Bond #16: " + ust912810RJ.name() + "       ||");

  950.         System.out.println ("\t|      Bond #17: " + ust912810RM.name() + "       ||");

  951.         System.out.println ("\t|      Bond #18: " + ust912810RP.name() + "       ||");

  952.         System.out.println ("\t|      Bond #19: " + ust912810RN.name() + "       ||");

  953.         System.out.println ("\t|      Bond #20: " + ust912810RK.name() + "       ||");

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

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

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

  957.         BondRVMeasuresSample (
  958.             (BondComponent) bondCTD,
  959.             dtSpot,
  960.             csqc,
  961.             1.3200000
  962.         );

  963.         ComputeFuturesMeasures (
  964.             tu1,
  965.             dtSpot,
  966.             csqc,
  967.             adblCleanPrice
  968.         );

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

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

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

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

  973.         System.out.println ("\t|---------------------------------------------||\n");
  974.     }
  975. }