FixedBullet2.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>FixedBullet2</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 FixedBullet2 {

  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.             double dblCleanPriceOASUp = Double.NaN;
  410.             double dblCleanPriceOASDown = Double.NaN;

  411.             System.out.println ("Doing " + aBond[i].name());

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

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

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

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

  442.             try {
  443.                 dblCleanPriceOASUp = aBond[i].priceFromOAS (
  444.                     valParams,
  445.                     csqc,
  446.                     null,
  447.                     adblOAS[i] + 0.0001
  448.                 );

  449.                 dblCleanPriceOASDown = aBond[i].priceFromOAS (
  450.                     valParams,
  451.                     csqc,
  452.                     null,
  453.                     adblOAS[i] - 0.0001
  454.                 );
  455.             } catch (Exception e) {
  456.                 // e.printStackTrace();
  457.             }

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

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

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

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

  478.         System.out.print (strSecularMetrics);

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

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

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

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

  483.         System.out.print (strCurveMetrics);

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

  485.         return adblOAS;
  486.     }

  487.     public static final void main (
  488.         final String[] astrArgs)
  489.         throws Exception
  490.     {
  491.         EnvManager.InitEnv (
  492.             "",
  493.             true
  494.         );

  495.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  496.             2017,
  497.             DateUtil.MARCH,
  498.             13
  499.         );

  500.         String strCurrency = "USD";
  501.         String strTreasuryCode = "UST";

  502.         MergedDiscountForwardCurve dcFunding = FundingCurve (
  503.             dtSpot,
  504.             strCurrency
  505.         );

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

  516.         double[] adblTreasuryYield = new double[] {
  517.             0.0104, //  1Y
  518.             0.0137, //  2Y
  519.             0.0167, //  3Y
  520.             0.0213, //  5Y
  521.             0.0243, //  7Y
  522.             0.0260, // 10Y
  523.             0.0294, // 20Y
  524.             0.0319  // 30Y
  525.         };

  526.         Map<String, GovvieCurve> mapGovvieCurve = GovvieCurve (
  527.             dtSpot,
  528.             strTreasuryCode,
  529.             adblTreasuryCoupon,
  530.             adblTreasuryYield
  531.         );

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

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

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

  556.         Bond[] aCorporateBond = new Bond[] {
  557.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2013, 12, 11), DateUtil.CreateFromYMD (2028, 12,  8), 0.04000, 2, "30/360"),
  558.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2014,  6,  4), DateUtil.CreateFromYMD (2029,  6,  8), 0.03375, 2, "30/360"),
  559.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2013, 10, 24), DateUtil.CreateFromYMD (2029, 10, 24), 0.04000, 2, "30/360"),
  560.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2012, 10, 24), DateUtil.CreateFromYMD (2030, 10, 24), 0.03050, 2, "30/360"),
  561.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2015,  7, 20), DateUtil.CreateFromYMD (2032,  7, 20), 0.03500, 2, "30/360"),
  562.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2015,  6,  1), DateUtil.CreateFromYMD (2035,  6,  1), 0.03500, 2, "30/360"),
  563.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2015, 11, 12), DateUtil.CreateFromYMD (2035, 11, 13), 0.03315, 2, "30/360"),
  564.             Corporate ("AGENCY ", DateUtil.CreateFromYMD (2015,  7,  6), DateUtil.CreateFromYMD (2037,  8,  6), 0.03950, 2, "30/360"),
  565.         };

  566.         double[] adblCleanPrice = new double[] {
  567.             1.0790190,  // (2028, 12,  8)
  568.             1.0150450,  // (2029,  6,  8)
  569.             1.0761990,  // (2029, 10, 24)
  570.             0.9602829,  // (2030, 10, 24)
  571.             1.0062450,  // (2032,  7, 20)
  572.             0.9955769,  // (2035,  6,  1)
  573.             0.9745172,  // (2035, 11, 13)
  574.             1.0340070,  // (2037,  8,  6)
  575.             0.9381400,  // (2045,  4,  6)
  576.         };

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

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

  591.         System.out.println();

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

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

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

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

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

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

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

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

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

  607.                 String strDump = " |                ";

  608.                 try {
  609.                     strDump = " |      " +
  610.                         FormatUtil.FormatDouble (
  611.                             (adblCleanPrice[i] - aCorporateBond[i].priceFromOAS (
  612.                                 valParams,
  613.                                 csqc,
  614.                                 null,
  615.                                 adblOAS[i]
  616.                             )) / adblCleanPrice[i],
  617.                         2, 2, 10000.
  618.                     ) + "     ";
  619.                 } catch (Exception e) {
  620.                     // e.printStackTrace();
  621.                 }

  622.                 System.out.print (strDump);
  623.             }

  624.             System.out.println (" ||");
  625.         }

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

  627.         EnvManager.TerminateEnv();
  628.     }
  629. }