BulletAgency.java

  1. package org.drip.sample.bondfixed;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.output.BondRVMeasures;
  5. import org.drip.analytics.support.Helper;
  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.creator.BondBuilder;
  12. import org.drip.product.credit.BondComponent;
  13. import org.drip.product.definition.*;
  14. import org.drip.service.env.EnvManager;
  15. import org.drip.service.template.*;
  16. import org.drip.state.discount.MergedDiscountForwardCurve;
  17. import org.drip.state.govvie.GovvieCurve;

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

  21. /*!
  22.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  23.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  24.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  25.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  26.  *
  27.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  28.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  29.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  30.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  31.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  32.  *      and computational support.
  33.  *  
  34.  *      https://lakshmidrip.github.io/DROP/
  35.  *  
  36.  *  DROP is composed of three modules:
  37.  *  
  38.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  39.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  40.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  41.  *
  42.  *  DROP Product Core implements libraries for the following:
  43.  *  - Fixed Income Analytics
  44.  *  - Loan Analytics
  45.  *  - Transaction Cost Analytics
  46.  *
  47.  *  DROP Portfolio Core implements libraries for the following:
  48.  *  - Asset Allocation Analytics
  49.  *  - Asset Liability Management Analytics
  50.  *  - Capital Estimation Analytics
  51.  *  - Exposure Analytics
  52.  *  - Margin Analytics
  53.  *  - XVA Analytics
  54.  *
  55.  *  DROP Computational Core implements libraries for the following:
  56.  *  - Algorithm Support
  57.  *  - Computation Support
  58.  *  - Function Analysis
  59.  *  - Model Validation
  60.  *  - Numerical Analysis
  61.  *  - Numerical Optimizer
  62.  *  - Spline Builder
  63.  *  - Statistical Learning
  64.  *
  65.  *  Documentation for DROP is Spread Over:
  66.  *
  67.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  68.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  69.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  70.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  71.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  72.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  73.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  74.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  75.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  76.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  77.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  78.  *
  79.  *  Licensed under the Apache License, Version 2.0 (the "License");
  80.  *      you may not use this file except in compliance with the License.
  81.  *  
  82.  *  You may obtain a copy of the License at
  83.  *      http://www.apache.org/licenses/LICENSE-2.0
  84.  *  
  85.  *  Unless required by applicable law or agreed to in writing, software
  86.  *      distributed under the License is distributed on an "AS IS" BASIS,
  87.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  88.  *  
  89.  *  See the License for the specific language governing permissions and
  90.  *      limitations under the License.
  91.  */

  92. /**
  93.  * <i>BulletAgency</i> demonstrates Non-EOS Fixed Coupon Agency Bond Pricing and Relative Value Measure
  94.  * Generation Functionality.
  95.  *  
  96.  * <br><br>
  97.  *  <ul>
  98.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  99.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  100.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  101.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bondfixed/README.md">Fixed Coupon Agency/Corporate Bonds</a></li>
  102.  *  </ul>
  103.  * <br><br>
  104.  *
  105.  * @author Lakshmi Krishnamurthy
  106.  */

  107. public class BulletAgency {

  108.     private static final MergedDiscountForwardCurve FundingCurve (
  109.         final JulianDate dtSpot,
  110.         final String strCurrency)
  111.         throws Exception
  112.     {
  113.         String[] astrDepositMaturityTenor = new String[] {
  114.             "2D"
  115.         };

  116.         double[] adblDepositQuote = new double[] {
  117.             0.0103456 // 2D
  118.         };

  119.         double[] adblFuturesQuote = new double[] {
  120.             0.01070,
  121.             0.01235,
  122.             0.01360
  123.         };

  124.         String[] astrFixFloatMaturityTenor = new String[] {
  125.             "01Y",
  126.             "02Y",
  127.             "03Y",
  128.             "04Y",
  129.             "05Y",
  130.             "06Y",
  131.             "07Y",
  132.             "08Y",
  133.             "09Y",
  134.             "10Y",
  135.             "11Y",
  136.             "12Y",
  137.             "15Y",
  138.             "20Y",
  139.             "25Y",
  140.             "30Y",
  141.             "40Y",
  142.             "50Y"
  143.         };

  144.         double[] adblFixFloatQuote = new double[] {
  145.             0.012484, //  1Y
  146.             0.014987, //  2Y
  147.             0.017036, //  3Y
  148.             0.018624, //  4Y
  149.             0.019868, //  5Y
  150.             0.020921, //  6Y
  151.             0.021788, //  7Y
  152.             0.022530, //  8Y
  153.             0.023145, //  9Y
  154.             0.023685, // 10Y
  155.             0.024153, // 11Y
  156.             0.024562, // 12Y
  157.             0.025389, // 15Y
  158.             0.026118, // 20Y
  159.             0.026368, // 25Y
  160.             0.026432, // 30Y
  161.             0.026339, // 40Y
  162.             0.026122  // 50Y
  163.         };

  164.         MergedDiscountForwardCurve dcFunding = LatentMarketStateBuilder.SmoothFundingCurve (
  165.             dtSpot,
  166.             strCurrency,
  167.             astrDepositMaturityTenor,
  168.             adblDepositQuote,
  169.             "ForwardRate",
  170.             adblFuturesQuote,
  171.             "ForwardRate",
  172.             astrFixFloatMaturityTenor,
  173.             adblFixFloatQuote,
  174.             "SwapRate"
  175.         );

  176.         Component[] aDepositComp = OTCInstrumentBuilder.FundingDeposit (
  177.             dtSpot,
  178.             strCurrency,
  179.             astrDepositMaturityTenor
  180.         );

  181.         Component[] aFuturesComp = ExchangeInstrumentBuilder.ForwardRateFuturesPack (
  182.             dtSpot,
  183.             adblFuturesQuote.length,
  184.             strCurrency
  185.         );

  186.         Component[] aFixFloatComp = OTCInstrumentBuilder.FixFloatStandard (
  187.             dtSpot,
  188.             strCurrency,
  189.             "ALL",
  190.             astrFixFloatMaturityTenor,
  191.             "MAIN",
  192.             0.
  193.         );

  194.         ValuationParams valParams = new ValuationParams (
  195.             dtSpot,
  196.             dtSpot,
  197.             strCurrency
  198.         );

  199.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  200.             dcFunding,
  201.             null,
  202.             null,
  203.             null,
  204.             null,
  205.             null,
  206.             null
  207.         );

  208.         System.out.println();

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

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

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

  212.         for (int i = 0; i < aDepositComp.length; ++i)
  213.             System.out.println ("\t| [" + aDepositComp[i].maturityDate() + "] =" +
  214.                 FormatUtil.FormatDouble (aDepositComp[i].measureValue (
  215.                     valParams,
  216.                     null,
  217.                     csqc,
  218.                     null,
  219.                     "ForwardRate"
  220.                 ), 1, 6, 1.) + " |" +
  221.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 6, 1.) + " ||"
  222.             );

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

  224.         System.out.println();

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

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

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

  228.         for (int i = 0; i < aFuturesComp.length; ++i)
  229.             System.out.println ("\t| [" + aFuturesComp[i].maturityDate() + "] =" +
  230.                 FormatUtil.FormatDouble (aFuturesComp[i].measureValue (
  231.                     valParams,
  232.                     null,
  233.                     csqc,
  234.                     null,
  235.                     "ForwardRate"
  236.                 ), 1, 6, 1.) + " |" +
  237.                 FormatUtil.FormatDouble (adblFuturesQuote[i], 1, 6, 1.) + " ||"
  238.             );

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

  240.         System.out.println();

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

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

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

  244.         for (int i = 0; i < aFixFloatComp.length; ++i)
  245.             System.out.println ("\t| [" + aFixFloatComp[i].maturityDate() + "] =" +
  246.                 FormatUtil.FormatDouble (aFixFloatComp[i].measureValue (
  247.                     valParams,
  248.                     null,
  249.                     csqc,
  250.                     null,
  251.                     "CalibSwapRate"
  252.                 ), 1, 6, 1.) + " |" +
  253.                 FormatUtil.FormatDouble (adblFixFloatQuote[i], 1, 6, 1.) + " |" +
  254.                 FormatUtil.FormatDouble (aFixFloatComp[i].measureValue (
  255.                     valParams,
  256.                     null,
  257.                     csqc,
  258.                     null,
  259.                     "FairPremium"
  260.                 ), 1, 6, 1.) + " ||"
  261.             );

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

  263.         System.out.println();

  264.         return dcFunding;
  265.     }

  266.     private static final Map<String, GovvieCurve> GovvieCurve (
  267.         final JulianDate dtSpot,
  268.         final String strCode,
  269.         final double[] adblCoupon,
  270.         final double[] adblYield)
  271.         throws Exception
  272.     {
  273.         JulianDate[] adtEffective = new JulianDate[] {
  274.             dtSpot,
  275.             dtSpot,
  276.             dtSpot,
  277.             dtSpot,
  278.             dtSpot,
  279.             dtSpot,
  280.             dtSpot,
  281.             dtSpot
  282.         };

  283.         JulianDate[] adtMaturity = new JulianDate[] {
  284.             dtSpot.addTenor ("1Y"),
  285.             dtSpot.addTenor ("2Y"),
  286.             dtSpot.addTenor ("3Y"),
  287.             dtSpot.addTenor ("5Y"),
  288.             dtSpot.addTenor ("7Y"),
  289.             dtSpot.addTenor ("10Y"),
  290.             dtSpot.addTenor ("20Y"),
  291.             dtSpot.addTenor ("30Y")
  292.         };

  293.         Map<String, GovvieCurve> mapGovvieCurve = LatentMarketStateBuilder.BumpedGovvieCurve (
  294.             strCode,
  295.             dtSpot,
  296.             adtEffective,
  297.             adtMaturity,
  298.             adblCoupon,
  299.             adblYield,
  300.             "Yield",
  301.             LatentMarketStateBuilder.SHAPE_PRESERVING,
  302.             0.0001,
  303.             false
  304.         );

  305.         BondComponent[] aComp = TreasuryBuilder.FromCode (
  306.             strCode,
  307.             adtEffective,
  308.             adtMaturity,
  309.             adblCoupon
  310.         );

  311.         ValuationParams valParams = ValuationParams.Spot (dtSpot.julian());

  312.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

  313.         csqc.setGovvieState (mapGovvieCurve.get ("BASE"));

  314.         System.out.println();

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

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

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

  318.         for (int i = 0; i < aComp.length; ++i)
  319.             System.out.println ("\t| " + aComp[i].name() + " | " +
  320.                 FormatUtil.FormatDouble (adblYield[i], 1, 3, 100.) + "% | " +
  321.                 FormatUtil.FormatDouble (aComp[i].yieldFromPrice (
  322.                     valParams,
  323.                     null,
  324.                     null,
  325.                     aComp[i].maturityDate().julian(),
  326.                     1.,
  327.                     aComp[i].priceFromYield (
  328.                         valParams,
  329.                         null,
  330.                         null,
  331.                         mapGovvieCurve.get ("BASE").yield (aComp[i].maturityDate().julian())
  332.                     )
  333.                 ), 1, 3, 100.) + "% ||"
  334.             );

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

  336.         return mapGovvieCurve;
  337.     }

  338.     private static final void AccumulateBondMarketQuote (
  339.         final CurveSurfaceQuoteContainer csqc,
  340.         final String[] astrOnTheRunCode,
  341.         final double[] adblYield)
  342.         throws Exception
  343.     {
  344.         for (int i = 0; i < astrOnTheRunCode.length; ++i) {
  345.             ProductMultiMeasure pmmq = new ProductMultiMeasure();

  346.             pmmq.addQuote (
  347.                 "Yield",
  348.                 new MultiSided (
  349.                     "mid",
  350.                     adblYield[i]
  351.                 ),
  352.                 true
  353.             );

  354.             csqc.setProductQuote (
  355.                 astrOnTheRunCode[i],
  356.                 pmmq
  357.             );
  358.         }
  359.     }

  360.     private static final Bond Agency (
  361.         final JulianDate dtEffective,
  362.         final JulianDate dtMaturity,
  363.         final double dblCoupon)
  364.         throws Exception
  365.     {
  366.         return BondBuilder.CreateSimpleFixed (
  367.             "AGENCY " + FormatUtil.FormatDouble (dblCoupon, 1, 4, 100.) + " " + dtMaturity,
  368.             "USD",
  369.             "",
  370.             dblCoupon,
  371.             2,
  372.             "30/360",
  373.             dtEffective,
  374.             dtMaturity,
  375.             null,
  376.             null
  377.         );
  378.     }

  379.     private static final double[] RVMeasures (
  380.         final Bond[] aBond,
  381.         final JulianDate dtValue,
  382.         final CurveSurfaceQuoteContainer csqc,
  383.         final double[] adblCleanPrice)
  384.         throws Exception
  385.     {
  386.         JulianDate dtSettle = dtValue.addBusDays (
  387.             3,
  388.             aBond[0].currency()
  389.         );

  390.         ValuationParams valParams = new ValuationParams (
  391.             dtValue,
  392.             dtSettle,
  393.             aBond[0].currency()
  394.         );

  395.         System.out.println();

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

  397.         System.out.println ("\t| Trade Date       : " + dtValue + " ||");

  398.         System.out.println ("\t| Cash Settle Date : " + dtSettle + " ||");

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

  400.         System.out.println();

  401.         String strCurveMetrics = "";
  402.         String strSecularMetrics = "";
  403.         double[] adblOAS = new double[aBond.length];

  404.         for (int i = 0; i < aBond.length; ++i) {
  405.             System.out.println ("Doing " + aBond[i].name());

  406.             WorkoutInfo wi = aBond[i].exerciseYieldFromPrice (
  407.                 valParams,
  408.                 csqc,
  409.                 null,
  410.                 adblCleanPrice[i]
  411.             );

  412.             BondRVMeasures rvm = aBond[i].standardMeasures (
  413.                 valParams,
  414.                 null,
  415.                 csqc,
  416.                 null,
  417.                 wi,
  418.                 adblCleanPrice[i]
  419.             );

  420.             strSecularMetrics += "\t| " +
  421.                 aBond[i].name() + " | " +
  422.                 aBond[i].effectiveDate() + " | " +
  423.                 aBond[i].maturityDate() + " |  " +
  424.                 aBond[i].firstCouponDate() + "  |" +
  425.                 FormatUtil.FormatDouble (adblCleanPrice[i], 3, 3, 100.) + " |" +
  426.                 FormatUtil.FormatDouble (wi.yield(), 1, 2, 100.) + "% | " +
  427.                 FormatUtil.FormatDouble (rvm.macaulayDuration(), 2, 2, 1.) + "  | " +
  428.                 FormatUtil.FormatDouble (rvm.modifiedDuration(), 2, 2, 10000.) + "  |  " +
  429.                 FormatUtil.FormatDouble (rvm.yield01(), 2, 2, 10000.) + "  |" +
  430.                 FormatUtil.FormatDouble (rvm.yield01(), 4, 0, 1000000.) + " |" +
  431.                 FormatUtil.FormatDouble (rvm.convexity(), 1, 2, 1000000.) + " |   " +
  432.                 FormatUtil.FormatDouble (rvm.bondBasis(), 3, 0, 10000.) + "     ||" + "\n";

  433.             adblOAS[i] = rvm.oas();

  434.             double dblCleanPriceOASUp = aBond[i].priceFromOAS (
  435.                 valParams,
  436.                 csqc,
  437.                 null,
  438.                 adblOAS[i] + 0.0001
  439.             );

  440.             double dblCleanPriceOASDown = aBond[i].priceFromOAS (
  441.                 valParams,
  442.                 csqc,
  443.                 null,
  444.                 adblOAS[i] - 0.0001
  445.             );

  446.             strCurveMetrics += "\t| " +
  447.                 aBond[i].name() + " |" +
  448.                 FormatUtil.FormatDouble (adblCleanPrice[i], 3, 3, 100.) + " |" +
  449.                 FormatUtil.FormatDouble (wi.yield(), 1, 2, 100.) + "% |   " +
  450.                 FormatUtil.FormatDouble (rvm.zSpread(), 3, 0, 10000.) + "   |" +
  451.                 FormatUtil.FormatDouble (adblOAS[i], 3, 0, 10000.) + " | " +
  452.                 FormatUtil.FormatDouble (0.5 * (dblCleanPriceOASDown - dblCleanPriceOASUp) / adblCleanPrice[i], 2, 2, 10000.) + "  |  " +
  453.                 FormatUtil.FormatDouble ((dblCleanPriceOASDown + dblCleanPriceOASUp - 2. * adblCleanPrice[i]) / adblCleanPrice[i], 2, 2, 1000000.) + "   |" +
  454.                 FormatUtil.FormatDouble (rvm.asw(), 3, 0, 10000.) + " |  " +
  455.                 FormatUtil.FormatDouble (rvm.gSpread(), 3, 0, 10000.) + "    |   " +
  456.                 FormatUtil.FormatDouble (rvm.iSpread(), 3, 0, 10000.) + "   |    " +
  457.                 FormatUtil.FormatDouble (rvm.tsySpread(), 3, 0, 10000.) + "    |  " +
  458.                 Helper.BaseTsyBmk (
  459.                     dtValue.julian(),
  460.                     aBond[i].maturityDate().julian()
  461.                 ) + "  ||" + "\n";
  462.         }

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

  464.         System.out.println ("\t|             BOND           |  EFFECTIVE  |   MATURITY  |  FIRST COUPON |  PRICE  | YIELD | MAC DUR | MOD DUR | YIELD 01 | DV01 | CONV | BOND BASIS ||");

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

  466.         System.out.print (strSecularMetrics);

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

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

  469.         System.out.println ("\t|             BOND           |  PRICE  | YIELD | Z SPREAD | OAS | OAS DUR |  OAS CONV | ASW | G SPREAD | I SPREAD | TSY SPREAD | TSY BMK ||");

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

  471.         System.out.print (strCurveMetrics);

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

  473.         return adblOAS;
  474.     }

  475.     public static final void main (
  476.         final String[] astrArgs)
  477.         throws Exception
  478.     {
  479.         EnvManager.InitEnv (
  480.             "",
  481.             true
  482.         );

  483.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  484.             2017,
  485.             DateUtil.FEBRUARY,
  486.             2
  487.         );

  488.         String strCurrency = "USD";
  489.         String strTreasuryCode = "UST";

  490.         MergedDiscountForwardCurve dcFunding = FundingCurve (
  491.             dtSpot,
  492.             strCurrency
  493.         );

  494.         double[] adblTreasuryCoupon = new double[] {
  495.             0.0100,
  496.             0.0100,
  497.             0.0125,
  498.             0.0150,
  499.             0.0200,
  500.             0.0225,
  501.             0.0250,
  502.             0.0300
  503.         };

  504.         double[] adblTreasuryYield = new double[] {
  505.             0.0083, //  1Y
  506.             0.0122, //  2Y
  507.             0.0149, //  3Y
  508.             0.0193, //  5Y
  509.             0.0227, //  7Y
  510.             0.0248, // 10Y
  511.             0.0280, // 20Y
  512.             0.0308  // 30Y
  513.         };

  514.         Map<String, GovvieCurve> mapGovvieCurve = GovvieCurve (
  515.             dtSpot,
  516.             strTreasuryCode,
  517.             adblTreasuryCoupon,
  518.             adblTreasuryYield
  519.         );

  520.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  521.             dcFunding,
  522.             null,
  523.             null,
  524.             null,
  525.             null,
  526.             null,
  527.             null
  528.         );

  529.         csqc.setGovvieState (mapGovvieCurve.get ("BASE"));

  530.         AccumulateBondMarketQuote (
  531.             csqc,
  532.             new String[] {
  533.                 "01YON",
  534.                 "02YON",
  535.                 "03YON",
  536.                 "05YON",
  537.                 "07YON",
  538.                 "10YON",
  539.                 "20YON",
  540.                 "30YON"
  541.             },
  542.             adblTreasuryYield
  543.         );

  544.         Bond[] aAgencyBond = new Bond[] {
  545.             Agency (DateUtil.CreateFromYMD (2016,  8, 30), DateUtil.CreateFromYMD (2028,  8, 28), 0.01000),
  546.             Agency (DateUtil.CreateFromYMD (2012, 10, 30), DateUtil.CreateFromYMD (2020,  4, 30), 0.01500),
  547.             Agency (DateUtil.CreateFromYMD (2016,  1, 12), DateUtil.CreateFromYMD (2026,  1, 12), 0.03020),
  548.             Agency (DateUtil.CreateFromYMD (2016,  7, 12), DateUtil.CreateFromYMD (2027,  7, 12), 0.02500),
  549.             Agency (DateUtil.CreateFromYMD (2013,  4, 10), DateUtil.CreateFromYMD (2028,  4, 10), 0.04000),
  550.             Agency (DateUtil.CreateFromYMD (2013, 10,  4), DateUtil.CreateFromYMD (2028,  9,  1), 0.04000),
  551.             Agency (DateUtil.CreateFromYMD (2013, 12,  8), DateUtil.CreateFromYMD (2028, 12,  8), 0.04000),
  552.             Agency (DateUtil.CreateFromYMD (2014,  4, 11), DateUtil.CreateFromYMD (2029,  4, 11), 0.04000),
  553.             Agency (DateUtil.CreateFromYMD (2014,  6,  4), DateUtil.CreateFromYMD (2029,  6,  8), 0.03375),
  554.             Agency (DateUtil.CreateFromYMD (2015,  5, 28), DateUtil.CreateFromYMD (2029,  8,  1), 0.03350),
  555.             Agency (DateUtil.CreateFromYMD (2013,  4, 24), DateUtil.CreateFromYMD (2029, 10, 24), 0.04000),
  556.             Agency (DateUtil.CreateFromYMD (2016,  2,  8), DateUtil.CreateFromYMD (2030,  2,  8), 0.03280),
  557.             Agency (DateUtil.CreateFromYMD (2016,  9, 29), DateUtil.CreateFromYMD (2030,  3, 29), 0.02990),
  558.             Agency (DateUtil.CreateFromYMD (2015,  8,  1), DateUtil.CreateFromYMD (2030,  8,  1), 0.03500),
  559.             Agency (DateUtil.CreateFromYMD (2012, 10, 24), DateUtil.CreateFromYMD (2030, 10, 24), 0.03050),
  560.             Agency (DateUtil.CreateFromYMD (2015, 11, 27), DateUtil.CreateFromYMD (2030, 11, 27), 0.03300),
  561.             Agency (DateUtil.CreateFromYMD (2015, 12, 23), DateUtil.CreateFromYMD (2030, 12, 23), 0.03530),
  562.             Agency (DateUtil.CreateFromYMD (2016,  1, 14), DateUtil.CreateFromYMD (2031,  1, 14), 0.03340),
  563.             Agency (DateUtil.CreateFromYMD (2016,  1, 27), DateUtil.CreateFromYMD (2031,  1, 27), 0.03390),
  564.             Agency (DateUtil.CreateFromYMD (2016,  2, 11), DateUtil.CreateFromYMD (2031,  2, 11), 0.03040),
  565.             Agency (DateUtil.CreateFromYMD (2016,  3, 10), DateUtil.CreateFromYMD (2031,  3, 10), 0.03100),
  566.             Agency (DateUtil.CreateFromYMD (2016,  7, 11), DateUtil.CreateFromYMD (2031,  7, 11), 0.02750),
  567.             Agency (DateUtil.CreateFromYMD (2015,  5,  8), DateUtil.CreateFromYMD (2031,  8,  1), 0.03550),
  568.             Agency (DateUtil.CreateFromYMD (2016,  8,  8), DateUtil.CreateFromYMD (2031,  8,  8), 0.02700),
  569.             Agency (DateUtil.CreateFromYMD (2015,  6, 28), DateUtil.CreateFromYMD (2032,  6, 28), 0.02900),
  570.             Agency (DateUtil.CreateFromYMD (2015,  7, 20), DateUtil.CreateFromYMD (2032,  7, 20), 0.03500),
  571.             Agency (DateUtil.CreateFromYMD (2016,  2,  1), DateUtil.CreateFromYMD (2033,  2,  1), 0.03330),
  572.             Agency (DateUtil.CreateFromYMD (2016,  4, 21), DateUtil.CreateFromYMD (2033,  4, 21), 0.03000),
  573.             Agency (DateUtil.CreateFromYMD (2013, 10, 11), DateUtil.CreateFromYMD (2033, 10, 11), 0.04125),
  574.             Agency (DateUtil.CreateFromYMD (2014,  7, 24), DateUtil.CreateFromYMD (2034,  7, 24), 0.03990),
  575.             Agency (DateUtil.CreateFromYMD (2014,  9,  5), DateUtil.CreateFromYMD (2034,  9,  5), 0.03940),
  576.             Agency (DateUtil.CreateFromYMD (2016,  2,  2), DateUtil.CreateFromYMD (2035,  2,  2), 0.03300),
  577.             Agency (DateUtil.CreateFromYMD (2015,  6,  1), DateUtil.CreateFromYMD (2035,  6,  1), 0.03400),
  578.             Agency (DateUtil.CreateFromYMD (2015, 10, 22), DateUtil.CreateFromYMD (2035, 10, 22), 0.03625),
  579.             Agency (DateUtil.CreateFromYMD (2015, 11, 12), DateUtil.CreateFromYMD (2035, 11, 13), 0.03315),
  580.             Agency (DateUtil.CreateFromYMD (2015, 12, 28), DateUtil.CreateFromYMD (2035, 12, 28), 0.03670),
  581.             Agency (DateUtil.CreateFromYMD (2016,  2,  1), DateUtil.CreateFromYMD (2036,  2,  1), 0.03560),
  582.             Agency (DateUtil.CreateFromYMD (2016,  2,  6), DateUtil.CreateFromYMD (2036,  2,  6), 0.03130),
  583.             Agency (DateUtil.CreateFromYMD (2016,  2,  8), DateUtil.CreateFromYMD (2036,  2,  8), 0.03500),
  584.             Agency (DateUtil.CreateFromYMD (2016,  2, 22), DateUtil.CreateFromYMD (2036,  2, 22), 0.03440),
  585.             Agency (DateUtil.CreateFromYMD (2016,  4, 18), DateUtil.CreateFromYMD (2036,  4, 18), 0.03140),
  586.             Agency (DateUtil.CreateFromYMD (2016,  4, 29), DateUtil.CreateFromYMD (2036,  4, 29), 0.03000),
  587.             Agency (DateUtil.CreateFromYMD (2016,  5, 16), DateUtil.CreateFromYMD (2036,  5, 16), 0.03000),
  588.             Agency (DateUtil.CreateFromYMD (2016,  6,  9), DateUtil.CreateFromYMD (2036,  5, 20), 0.03040),
  589.             Agency (DateUtil.CreateFromYMD (2016,  5, 23), DateUtil.CreateFromYMD (2036,  5, 23), 0.03030),
  590.             Agency (DateUtil.CreateFromYMD (2006,  6, 16), DateUtil.CreateFromYMD (2036,  6, 16), 0.03000),
  591.             Agency (DateUtil.CreateFromYMD (2006,  7, 17), DateUtil.CreateFromYMD (2036,  7, 15), 0.05500),
  592.             Agency (DateUtil.CreateFromYMD (2016,  8, 22), DateUtil.CreateFromYMD (2036,  8, 22), 0.02700),
  593.             Agency (DateUtil.CreateFromYMD (2016,  9,  8), DateUtil.CreateFromYMD (2036,  9,  8), 0.02750),
  594.             Agency (DateUtil.CreateFromYMD (2016,  9,  8), DateUtil.CreateFromYMD (2036,  9,  8), 0.02700),
  595.             Agency (DateUtil.CreateFromYMD (2007,  7, 18), DateUtil.CreateFromYMD (2037,  7, 15), 0.05625),
  596.             Agency (DateUtil.CreateFromYMD (2015,  7,  6), DateUtil.CreateFromYMD (2037,  8,  6), 0.03950),
  597.             Agency (DateUtil.CreateFromYMD (2016, 11,  2), DateUtil.CreateFromYMD (2037, 11,  2), 0.02780),
  598.             Agency (DateUtil.CreateFromYMD (1998,  8,  6), DateUtil.CreateFromYMD (2038,  8,  6), 0.06210),
  599.             Agency (DateUtil.CreateFromYMD (2016,  7, 26), DateUtil.CreateFromYMD (2038,  8, 26), 0.02710),
  600.             Agency (DateUtil.CreateFromYMD (2016,  2,  2), DateUtil.CreateFromYMD (2039,  2,  2), 0.03500),
  601.             Agency (DateUtil.CreateFromYMD (2009,  9, 22), DateUtil.CreateFromYMD (2039,  9, 15), 0.05250),
  602.             Agency (DateUtil.CreateFromYMD (2016,  2,  2), DateUtil.CreateFromYMD (2041,  2,  2), 0.03650),
  603.             Agency (DateUtil.CreateFromYMD (2015,  4,  6), DateUtil.CreateFromYMD (2045,  4,  6), 0.03430),
  604.             Agency (DateUtil.CreateFromYMD (2006,  4,  3), DateUtil.CreateFromYMD (2056,  4,  1), 0.05375),
  605.             Agency (DateUtil.CreateFromYMD (2015,  9, 24), DateUtil.CreateFromYMD (2065,  9, 24), 0.04250),
  606.         };

  607.         double[] adblCleanPrice = new double[] {
  608.             0.9931592,  // (2018,  8, 28)
  609.             0.9934814,  // (2020,  4, 30)
  610.             0.9904951,  // (2026,  1, 12)
  611.             0.9479743,  // (2027,  7, 12)
  612.             1.0966930,  // (2028,  4, 10)
  613.             1.0935950,  // (2028,  9,  1)
  614.             1.0967200,  // (2028, 12,  8)
  615.             1.0065050,  // (2029,  4, 11)
  616.             1.0304410,  // (2029,  6,  8)
  617.             1.0110210,  // (2029,  8,  1)
  618.             1.0958790,  // (2029, 10, 24)
  619.             0.9880349,  // (2030,  2,  8)
  620.             0.9667400,  // (2030,  3, 29)
  621.             1.0189310,  // (2030,  8,  1)
  622.             0.9860338,  // (2030, 10, 24)
  623.             0.9759851,  // (2030, 11, 27)
  624.             0.9871626,  // (2030, 12, 23)
  625.             0.9770129,  // (2031,  1, 14)
  626.             0.9942566,  // (2031,  1, 27)
  627.             0.9536498,  // (2031,  2, 11)
  628.             0.9730267,  // (2031,  3, 10)
  629.             0.9399774,  // (2031,  7, 11)
  630.             1.0172150,  // (2031,  8,  1)
  631.             0.9329716,  // (2031,  8,  8)
  632.             0.9317174,  // (2032,  6, 28)
  633.             1.0240540,  // (2032,  7, 20)
  634.             0.9658405,  // (2033,  2,  1)
  635.             0.9424355,  // (2033,  4, 21)
  636.             1.0197810,  // (2033, 10, 11)
  637.             0.9988397,  // (2034,  7, 24)
  638.             0.9970544,  // (2034,  9,  5)
  639.             0.9770791,  // (2035,  2,  2)
  640.             1.0207810,  // (2035,  6,  1)
  641.             0.9765588,  // (2035, 10, 22)
  642.             0.9995269,  // (2035, 11, 13)
  643.             0.9889580,  // (2035, 12, 28)
  644.             0.9820512,  // (2036,  2,  1)
  645.             0.9267384,  // (2036,  2,  6)
  646.             0.9785613,  // (2036,  2,  8)
  647.             0.9731897,  // (2036,  2, 22)
  648.             0.9285945,  // (2036,  4, 18)
  649.             0.9132757,  // (2036,  4, 29)
  650.             0.9125336,  // (2036,  5, 16)
  651.             0.9385671,  // (2036,  5, 20)
  652.             0.9347221,  // (2036,  5, 23)
  653.             0.9343378,  // (2036,  6, 16)
  654.             1.3270050,  // (2036,  7, 15)
  655.             0.8896572,  // (2036,  8, 22)
  656.             0.8947115,  // (2036,  9,  8)
  657.             0.8985469,  // (2036,  9,  8)
  658.             1.3428920,  // (2037,  7, 15)
  659.             1.0576060,  // (2037,  8,  6)
  660.             0.8892567,  // (2037, 11,  2)
  661.             1.4447600,  // (2038,  8,  6)
  662.             0.8611548,  // (2038,  8, 26)
  663.             0.9764945,  // (2039,  2,  2)
  664.             1.2595240,  // (2039,  9, 15)
  665.             0.9811483,  // (2041,  2,  2)
  666.             0.9423921,  // (2045,  4,  6)
  667.             1.2715880,  // (2056,  4,  1)
  668.             1.0513800,  // (2065,  9, 15)
  669.         };

  670.         double[] adblOAS = RVMeasures (
  671.             aAgencyBond,
  672.             dtSpot,
  673.             csqc,
  674.             adblCleanPrice
  675.         );

  676.         ValuationParams valParams = new ValuationParams (
  677.             dtSpot,
  678.             dtSpot.addBusDays (
  679.                 3,
  680.                 dcFunding.currency()
  681.             ),
  682.             dcFunding.currency()
  683.         );

  684.         System.out.println();

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

  686.         System.out.print ("\t|             BOND          ");

  687.         for (Map.Entry<String, GovvieCurve> meGovvieCurve : mapGovvieCurve.entrySet()) {
  688.             if ("BASE".equalsIgnoreCase (meGovvieCurve.getKey()) || "BUMP".equalsIgnoreCase (meGovvieCurve.getKey()))
  689.                 continue;

  690.             System.out.print (" | " + meGovvieCurve.getKey());
  691.         }

  692.         System.out.println (" ||");

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

  694.         for (int i = 0; i < adblOAS.length; ++i) {
  695.             System.out.print ("\t| " + aAgencyBond[i].name());

  696.             for (Map.Entry<String, GovvieCurve> meGovvieCurve : mapGovvieCurve.entrySet()) {
  697.                 if ("BASE".equalsIgnoreCase (meGovvieCurve.getKey()) || "BUMP".equalsIgnoreCase (meGovvieCurve.getKey()))
  698.                     continue;

  699.                 csqc.setGovvieState (meGovvieCurve.getValue());

  700.                 System.out.print (" |      " +
  701.                     FormatUtil.FormatDouble (
  702.                         (adblCleanPrice[i] - aAgencyBond[i].priceFromOAS (
  703.                             valParams,
  704.                             csqc,
  705.                             null,
  706.                             adblOAS[i]
  707.                         )) / adblCleanPrice[i],
  708.                     2, 2, 10000.) + "     "
  709.                 );
  710.             }

  711.             System.out.println (" ||");
  712.         }

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

  714.         EnvManager.TerminateEnv();
  715.     }
  716. }