FixedBullet1.java

  1. package org.drip.sample.agency;

  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>FixedBullet1</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/agency/README.md">Agency Bond Analytical Measures Generation</a></li>
  102.  *  </ul>
  103.  * <br><br>
  104.  *
  105.  * @author Lakshmi Krishnamurthy
  106.  */

  107. public class FixedBullet1 {

  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.0111956 // 2D
  118.         };

  119.         double[] adblFuturesQuote = new double[] {
  120.             0.011375,   // 98.8625
  121.             0.013350,   // 98.6650
  122.             0.014800,   // 98.5200
  123.             0.016450,   // 98.3550
  124.             0.017850,   // 98.2150
  125.             0.019300    // 98.0700
  126.         };

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

  146.         double[] adblFixFloatQuote = new double[] {
  147.             0.017029, //  2Y
  148.             0.019354, //  3Y
  149.             0.021044, //  4Y
  150.             0.022291, //  5Y
  151.             0.023240, //  6Y
  152.             0.024025, //  7Y
  153.             0.024683, //  8Y
  154.             0.025243, //  9Y
  155.             0.025720, // 10Y
  156.             0.026130, // 11Y
  157.             0.026495, // 12Y
  158.             0.027230, // 15Y
  159.             0.027855, // 20Y
  160.             0.028025, // 25Y
  161.             0.028028, // 30Y
  162.             0.027902, // 40Y
  163.             0.027655  // 50Y
  164.         };

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

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

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

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

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

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

  209.         System.out.println();

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

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

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

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

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

  225.         System.out.println();

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

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

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

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

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

  241.         System.out.println();

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

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

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

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

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

  264.         System.out.println();

  265.         return dcFunding;
  266.     }

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

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

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

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

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

  313.         CurveSurfaceQuoteContainer csqc = new CurveSurfaceQuoteContainer();

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

  315.         System.out.println();

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

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

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

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

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

  337.         return mapGovvieCurve;
  338.     }

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

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

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

  361.     private static final Bond Corporate (
  362.         final String strName,
  363.         final JulianDate dtEffective,
  364.         final JulianDate dtMaturity,
  365.         final double dblCoupon,
  366.         final int iFreq,
  367.         final String strDayCount)
  368.         throws Exception
  369.     {
  370.         return BondBuilder.CreateSimpleFixed (
  371.             strName + FormatUtil.FormatDouble (dblCoupon, 1, 4, 100.) + " " + dtMaturity,
  372.             "USD",
  373.             "",
  374.             dblCoupon,
  375.             iFreq,
  376.             strDayCount,
  377.             dtEffective,
  378.             dtMaturity,
  379.             null,
  380.             null
  381.         );
  382.     }

  383.     private static final double[] RVMeasures (
  384.         final Bond[] aBond,
  385.         final JulianDate dtValue,
  386.         final CurveSurfaceQuoteContainer csqc,
  387.         final double[] adblCleanPrice)
  388.         throws Exception
  389.     {
  390.         JulianDate dtSettle = dtValue.addBusDays (
  391.             0,
  392.             aBond[0].currency()
  393.         );

  394.         ValuationParams valParams = new ValuationParams (
  395.             dtValue,
  396.             dtSettle,
  397.             aBond[0].currency()
  398.         );

  399.         System.out.println();

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

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

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

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

  404.         System.out.println();

  405.         String strCurveMetrics = "";
  406.         String strSecularMetrics = "";
  407.         double[] adblOAS = new double[aBond.length];

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

  410.             WorkoutInfo wi = aBond[i].exerciseYieldFromPrice (
  411.                 valParams,
  412.                 csqc,
  413.                 null,
  414.                 adblCleanPrice[i]
  415.             );

  416.             BondRVMeasures rvm = aBond[i].standardMeasures (
  417.                 valParams,
  418.                 null,
  419.                 csqc,
  420.                 null,
  421.                 wi,
  422.                 adblCleanPrice[i]
  423.             );

  424.             strSecularMetrics += "\t| " +
  425.                 aBond[i].name() + " | " +
  426.                 aBond[i].effectiveDate() + " | " +
  427.                 aBond[i].maturityDate() + " |  " +
  428.                 aBond[i].firstCouponDate() + "  |" +
  429.                 FormatUtil.FormatDouble (adblCleanPrice[i], 3, 3, 100.) + " |" +
  430.                 FormatUtil.FormatDouble (aBond[i].accrued (dtSettle.julian(), csqc), 1, 5, 100.) + " |" +
  431.                 FormatUtil.FormatDouble (wi.yield(), 1, 2, 100.) + "% | " +
  432.                 FormatUtil.FormatDouble (rvm.macaulayDuration(), 2, 2, 1.) + "  | " +
  433.                 FormatUtil.FormatDouble (rvm.modifiedDuration(), 2, 2, 10000.) + "  |  " +
  434.                 FormatUtil.FormatDouble (rvm.yield01(), 2, 2, 10000.) + "  |" +
  435.                 FormatUtil.FormatDouble (rvm.yield01(), 4, 0, 1000000.) + " |" +
  436.                 FormatUtil.FormatDouble (rvm.convexity(), 1, 2, 1000000.) + " |" +
  437.                 FormatUtil.FormatDouble (aBond[i].weightedAverageLife (valParams, csqc), 2, 2, 1.) + " |   " +
  438.                 FormatUtil.FormatDouble (rvm.bondBasis(), 3, 0, 10000.) + "     ||" + "\n";

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

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

  446.             double dblCleanPriceOASDown = aBond[i].priceFromOAS (
  447.                 valParams,
  448.                 csqc,
  449.                 null,
  450.                 adblOAS[i] - 0.0001
  451.             );

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

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

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

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

  472.         System.out.print (strSecularMetrics);

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

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

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

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

  477.         System.out.print (strCurveMetrics);

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

  479.         return adblOAS;
  480.     }

  481.     public static final void main (
  482.         final String[] astrArgs)
  483.         throws Exception
  484.     {
  485.         EnvManager.InitEnv (
  486.             "",
  487.             true
  488.         );

  489.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  490.             2017,
  491.             DateUtil.MARCH,
  492.             13
  493.         );

  494.         String strCurrency = "USD";
  495.         String strTreasuryCode = "UST";

  496.         MergedDiscountForwardCurve dcFunding = FundingCurve (
  497.             dtSpot,
  498.             strCurrency
  499.         );

  500.         double[] adblTreasuryCoupon = new double[] {
  501.             0.0100,
  502.             0.0100,
  503.             0.0125,
  504.             0.0150,
  505.             0.0200,
  506.             0.0225,
  507.             0.0250,
  508.             0.0300
  509.         };

  510.         double[] adblTreasuryYield = new double[] {
  511.             0.0104, //  1Y
  512.             0.0137, //  2Y
  513.             0.0167, //  3Y
  514.             0.0213, //  5Y
  515.             0.0243, //  7Y
  516.             0.0260, // 10Y
  517.             0.0294, // 20Y
  518.             0.0319  // 30Y
  519.         };

  520.         Map<String, GovvieCurve> mapGovvieCurve = GovvieCurve (
  521.             dtSpot,
  522.             strTreasuryCode,
  523.             adblTreasuryCoupon,
  524.             adblTreasuryYield
  525.         );

  526.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  527.             dcFunding,
  528.             null,
  529.             null,
  530.             null,
  531.             null,
  532.             null,
  533.             null
  534.         );

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

  536.         AccumulateBondMarketQuote (
  537.             csqc,
  538.             new String[] {
  539.                 "01YON",
  540.                 "02YON",
  541.                 "03YON",
  542.                 "05YON",
  543.                 "07YON",
  544.                 "10YON",
  545.                 "20YON",
  546.                 "30YON"
  547.             },
  548.             adblTreasuryYield
  549.         );

  550.         Bond[] aCorporateBond = new Bond[] {
  551.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2013, 10, 10), DateUtil.CreateFromYMD (2028,  4, 10), 0.04000, 2, "30/360"),
  552.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2013, 10,  4), DateUtil.CreateFromYMD (2028,  9,  1), 0.04000, 2, "30/360"),
  553.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2016,  2,  2), DateUtil.CreateFromYMD (2035,  2,  2), 0.03300, 2, "30/360"),
  554.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2016,  6,  9), DateUtil.CreateFromYMD (2036,  5, 20), 0.03040, 2, "30/360"),
  555.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2006,  7, 17), DateUtil.CreateFromYMD (2036,  7, 15), 0.05500, 2, "30/360"),
  556.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2007,  7, 18), DateUtil.CreateFromYMD (2037,  7, 15), 0.05625, 2, "30/360"),
  557.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2016, 11,  2), DateUtil.CreateFromYMD (2037, 11,  2), 0.02780, 2, "30/360"),
  558.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (1998,  8,  6), DateUtil.CreateFromYMD (2038,  8,  6), 0.06210, 2, "30/360"),
  559.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2016,  7, 26), DateUtil.CreateFromYMD (2038,  8, 26), 0.02710, 2, "30/360"),
  560.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2016,  2,  2), DateUtil.CreateFromYMD (2039,  2,  2), 0.03500, 2, "30/360"),
  561.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2009,  9, 22), DateUtil.CreateFromYMD (2039,  9, 15), 0.05250, 2, "30/360"),
  562.         };

  563.         double[] adblCleanPrice = new double[] {
  564.             1.0822160,  // (2028,  4, 10)
  565.             1.0751340,  // (2028,  9,  1)
  566.             0.9566711,  // (2035,  2,  2)
  567.             0.9161351,  // (2036,  5, 20)
  568.             1.2964900,  // (2036,  7, 15)
  569.             1.3208360,  // (2037,  7, 15)
  570.             0.8635154,  // (2037, 11,  2)
  571.             1.4179350,  // (2038,  8,  6)
  572.             0.8431670,  // (2038,  8, 26)
  573.             0.9582438,  // (2039,  2,  2)
  574.             1.2435400,  // (2039,  9, 15)
  575.         };

  576.         double[] adblOAS = RVMeasures (
  577.             aCorporateBond,
  578.             dtSpot,
  579.             csqc,
  580.             adblCleanPrice
  581.         );

  582.         ValuationParams valParams = new ValuationParams (
  583.             dtSpot,
  584.             dtSpot.addBusDays (
  585.                 3,
  586.                 dcFunding.currency()
  587.             ),
  588.             dcFunding.currency()
  589.         );

  590.         System.out.println();

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

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

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

  596.             System.out.print (" | " + meGovvieCurve.getKey());
  597.         }

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

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

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

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

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

  606.                 System.out.print (" |      " +
  607.                     FormatUtil.FormatDouble (
  608.                         (adblCleanPrice[i] - aCorporateBond[i].priceFromOAS (
  609.                             valParams,
  610.                             csqc,
  611.                             null,
  612.                             adblOAS[i]
  613.                         )) / adblCleanPrice[i],
  614.                     2, 2, 10000.) + "     "
  615.                 );
  616.             }

  617.             System.out.println (" ||");
  618.         }

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

  620.         EnvManager.TerminateEnv();
  621.     }
  622. }