BulletCorporate1.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>BulletCorporate1</i> demonstrates Non-EOS Fixed Coupon Corporate Bond Pricing and Relative Value
  94.  * Measure 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 BulletCorporate1 {

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

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

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

  398.         System.out.println();

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

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

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

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

  403.         System.out.println();

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

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

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

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

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

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

  437.             double dblCleanPriceOASUp = aBond[i].priceFromOAS (
  438.                 valParams,
  439.                 csqc,
  440.                 null,
  441.                 adblOAS[i] + 0.0001
  442.             );

  443.             double dblCleanPriceOASDown = aBond[i].priceFromOAS (
  444.                 valParams,
  445.                 csqc,
  446.                 null,
  447.                 adblOAS[i] - 0.0001
  448.             );

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

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

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

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

  469.         System.out.print (strSecularMetrics);

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

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

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

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

  474.         System.out.print (strCurveMetrics);

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

  476.         return adblOAS;
  477.     }

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

  486.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  487.             2017,
  488.             DateUtil.FEBRUARY,
  489.             2
  490.         );

  491.         String strCurrency = "USD";
  492.         String strTreasuryCode = "UST";

  493.         MergedDiscountForwardCurve dcFunding = FundingCurve (
  494.             dtSpot,
  495.             strCurrency
  496.         );

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

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

  517.         Map<String, GovvieCurve> mapGovvieCurve = GovvieCurve (
  518.             dtSpot,
  519.             strTreasuryCode,
  520.             adblTreasuryCoupon,
  521.             adblTreasuryYield
  522.         );

  523.         CurveSurfaceQuoteContainer csqc = MarketParamsBuilder.Create (
  524.             dcFunding,
  525.             null,
  526.             null,
  527.             null,
  528.             null,
  529.             null,
  530.             null
  531.         );

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

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

  547.         Bond[] aCorporateBond = new Bond[] {
  548.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  3, 10), DateUtil.CreateFromYMD (2017,  3, 10), 0.01350, 2, "30/360"),
  549.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2012,  5, 11), DateUtil.CreateFromYMD (2017,  5, 11), 0.03750, 2, "30/360"),
  550.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  6, 11), DateUtil.CreateFromYMD (2017,  6,  9), 0.01350, 2, "30/360"),
  551.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2012, 10,  1), DateUtil.CreateFromYMD (2017, 10,  2), 0.02125, 2, "30/360"),
  552.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015, 11, 13), DateUtil.CreateFromYMD (2018,  7, 16), 0.03875, 2, "30/360"),
  553.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2008, 12, 11), DateUtil.CreateFromYMD (2019,  1, 15), 0.08250, 2, "30/360"),
  554.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2009,  2,  3), DateUtil.CreateFromYMD (2019,  2, 15), 0.08125, 2, "30/360"),
  555.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2007,  5,  4), DateUtil.CreateFromYMD (2019,  3, 15), 0.05490, 2, "30/360"),
  556.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2009,  3, 17), DateUtil.CreateFromYMD (2019,  3, 15), 0.09375, 2, "30/360"),
  557.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2009,  2,  6), DateUtil.CreateFromYMD (2019,  8, 16), 0.09250, 2, "30/360"),
  558.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2009, 10,  9), DateUtil.CreateFromYMD (2019, 10, 15), 0.07375, 2, "30/360"),
  559.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010,  1, 15), DateUtil.CreateFromYMD (2020,  1, 31), 0.07875, 2, "30/360"),
  560.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2009, 12, 11), DateUtil.CreateFromYMD (2020,  2, 15), 0.06250, 2, "30/360"),
  561.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010,  4, 26), DateUtil.CreateFromYMD (2020,  4, 30), 0.06375, 2, "30/360 NON-EOM"),
  562.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010,  5, 10), DateUtil.CreateFromYMD (2020,  5, 15), 0.08500, 2, "30/360"),
  563.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010,  9, 17), DateUtil.CreateFromYMD (2020,  9, 15), 0.05875, 2, "30/360"),
  564.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010,  9, 29), DateUtil.CreateFromYMD (2020,  9, 29), 0.06375, 2, "30/360"),
  565.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2010, 11, 15), DateUtil.CreateFromYMD (2020, 11, 15), 0.05500, 2, "ISMA-30/360"),
  566.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2016,  3, 17), DateUtil.CreateFromYMD (2021,  3,  1), 0.05000, 2, "30/360"),
  567.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  5, 23), DateUtil.CreateFromYMD (2021, 11,  1), 0.05375, 2, "30/360"),
  568.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2011, 11, 15), DateUtil.CreateFromYMD (2021, 11, 15), 0.04450, 2, "ISMA-30/360"),
  569.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2012,  4, 15), DateUtil.CreateFromYMD (2022,  4, 15), 0.05125, 2, "30/360"),
  570.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2007,  4, 10), DateUtil.CreateFromYMD (2022,  4, 19), 0.05983, 2, "30/360"),
  571.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2008,  4, 14), DateUtil.CreateFromYMD (2022, 10,  8), 0.06821, 2, "30/360"),
  572.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2007, 12, 13), DateUtil.CreateFromYMD (2023,  1, 15), 0.06251, 2, "30/360"),
  573.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013,  8, 23), DateUtil.CreateFromYMD (2023,  3, 15), 0.04375, 2, "30/360"),
  574.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013,  5, 22), DateUtil.CreateFromYMD (2023,  6,  1), 0.03750, 2, "30/360"),
  575.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013,  8, 15), DateUtil.CreateFromYMD (2023,  8, 15), 0.06125, 2, "30/360"),
  576.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013, 10,  2), DateUtil.CreateFromYMD (2023, 10,  2), 0.05000, 2, "30/360"),
  577.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015, 11,  9), DateUtil.CreateFromYMD (2023, 11, 15), 0.06125, 2, "30/360"),
  578.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013, 12, 11), DateUtil.CreateFromYMD (2024,  1, 15), 0.04150, 2, "30/360"),
  579.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  2, 11), DateUtil.CreateFromYMD (2024,  2, 15), 0.04350, 2, "30/360"),
  580.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  3,  3), DateUtil.CreateFromYMD (2024,  3,  3), 0.04000, 2, "30/360"),
  581.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  3, 14), DateUtil.CreateFromYMD (2024,  4,  1), 0.04600, 2, "30/360"),
  582.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  3,  9), DateUtil.CreateFromYMD (2024,  4,  1), 0.04400, 2, "30/360"),
  583.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  4,  8), DateUtil.CreateFromYMD (2024,  4,  8), 0.03800, 2, "ISMA-30/360"),
  584.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  6, 20), DateUtil.CreateFromYMD (2024,  7,  1), 0.05000, 2, "30/360"),
  585.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015,  1, 26), DateUtil.CreateFromYMD (2025,  2,  1), 0.04000, 2, "30/360"),
  586.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015,  2, 24), DateUtil.CreateFromYMD (2025,  2, 15), 0.04350, 2, "30/360"),
  587.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014, 12,  4), DateUtil.CreateFromYMD (2025,  2, 15), 0.04450, 2, "30/360"),
  588.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015, 11, 24), DateUtil.CreateFromYMD (2025, 11, 24), 0.04750, 2, "30/360"),
  589.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2012, 12, 16), DateUtil.CreateFromYMD (2025, 12, 16), 0.04500, 2, "30/360"),
  590.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2012, 11,  9), DateUtil.CreateFromYMD (2027, 11,  9), 0.04375, 2, "30/360"),
  591.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2001,  3,  2), DateUtil.CreateFromYMD (2031,  3,  3), 0.07125, 2, "30/360"),
  592.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015, 10,  1), DateUtil.CreateFromYMD (2035,  7, 29), 0.04950, 2, "ISMA-30/360"),
  593.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2015,  5,  9), DateUtil.CreateFromYMD (2035, 11,  1), 0.06250, 2, "30/360"),
  594.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2006, 11,  9), DateUtil.CreateFromYMD (2036, 10,  1), 0.05558, 2, "30/360"),
  595.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013,  8,  1), DateUtil.CreateFromYMD (2043,  8, 15), 0.06503, 12, "30/360"),
  596.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2003, 10,  1), DateUtil.CreateFromYMD (2043, 10,  1), 0.05937, 2, "30/360"),
  597.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2005,  2, 24), DateUtil.CreateFromYMD (2047, 12, 15), 0.05270, 2, "30/360"),
  598.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2005,  3,  1), DateUtil.CreateFromYMD (2049,  5, 15), 0.05690, 2, "30/360"),
  599.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2005,  4, 26), DateUtil.CreateFromYMD (2050,  6, 15), 0.05524, 2, "ISMA-30/360"),
  600.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2014,  6,  2), DateUtil.CreateFromYMD (2050,  6, 15), 0.05912, 2, "30/360"),
  601.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2006,  7,  1), DateUtil.CreateFromYMD (2051,  1,  1), 0.05521, 2, "30/360"),
  602.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2006, 11,  1), DateUtil.CreateFromYMD (2051, 10,  1), 0.05658, 2, "30/360"),
  603.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2007, 12,  4), DateUtil.CreateFromYMD (2053,  6, 15), 0.06171, 2, "30/360"),
  604.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2007, 12,  4), DateUtil.CreateFromYMD (2053,  6, 15), 0.08421, 2, "30/360"),
  605.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2013,  8,  1), DateUtil.CreateFromYMD (2053,  8, 15), 0.06803, 2, "30/360"),
  606.             Corporate ("CORPORA", DateUtil.CreateFromYMD (2008, 11,  4), DateUtil.CreateFromYMD (2053,  9, 15), 0.07500, 2, "30/360"),
  607.         };

  608.         double[] adblCleanPrice = new double[] {
  609.             1.0004420,  // (2017,  3, 10)
  610.             1.0070520,  // (2017,  5, 11)
  611.             1.0030200,  // (2017,  6,  9)
  612.             1.0027010,  // (2017, 10,  2)
  613.             1.0210990,  // (2018,  7, 16)
  614.             1.1229040,  // (2018, 12, 11)
  615.             1.1101630,  // (2019,  2, 15)
  616.             1.0622680,  // (2019,  3, 15)
  617.             1.1503290,  // (2019,  3, 15)
  618.             1.1771910,  // (2019,  8, 16)
  619.             1.1299690,  // (2019, 10, 15)
  620.             1.1391860,  // (2020,  1, 31)
  621.             1.1063470,  // (2020,  2, 15)
  622.             1.1061200,  // (2020,  4, 30)
  623.             1.1154030,  // (2020,  5, 15)
  624.             1.0756280,  // (2020,  9, 15)
  625.             1.1310700,  // (2020,  9, 29)
  626.             1.0886500,  // (2020, 11, 15)
  627.             1.0783280,  // (2021,  3,  1)
  628.             1.0248690,  // (2021, 11,  1)
  629.             1.0366210,  // (2021, 11, 15)
  630.             1.1100210,  // (2022,  4, 15)
  631.             1.1030640,  // (2022,  4, 19)
  632.             1.1515940,  // (2022, 10,  8)
  633.             1.1458440,  // (2023,  1, 15)
  634.             1.0075000,  // (2023,  3, 15)
  635.             1.0077190,  // (2023,  6,  1)
  636.             1.0452330,  // (2023,  8, 15)
  637.             1.0545460,  // (2023, 10,  2)
  638.             1.0748650,  // (2023, 11, 15)
  639.             1.0500690,  // (2024,  1, 15)
  640.             0.9578745,  // (2024,  2, 15)
  641.             1.0283760,  // (2024,  3,  3)
  642.             1.0263960,  // (2024,  4,  1)
  643.             0.9989979,  // (2024,  4,  1)
  644.             0.9891589,  // (2024,  4,  8)
  645.             1.0542700,  // (2024,  7,  1)
  646.             0.9759940,  // (2025,  2,  1)
  647.             0.9980053,  // (2025,  2, 15)
  648.             0.9772800,  // (2025,  2, 15)
  649.             1.0065140,  // (2025, 11, 24)
  650.             1.0318190,  // (2025, 12, 16)
  651.             1.0575060,  // (2027, 11,  9)
  652.             1.3593050,  // (2031,  3,  3)
  653.             1.0600360,  // (2035,  7, 29)
  654.             1.0899400,  // (2035, 11,  1)
  655.             1.1337930,  // (2036, 10,  1)
  656.             1.1776690,  // (2043,  8,  1)
  657.             1.1227270,  // (2043, 10,  1)
  658.             1.0392280,  // (2047, 12, 15)
  659.             1.1496480,  // (2049,  5, 15)
  660.             1.0961770,  // (2050,  6, 15)
  661.             1.2025960,  // (2050,  6, 15)
  662.             0.9276792,  // (2051,  1,  1)
  663.             1.0181790,  // (2051, 10,  1)
  664.             0.9694037,  // (2053,  6, 15)
  665.             1.0446570,  // (2053,  6, 15)
  666.             1.3776140,  // (2053,  8, 15)
  667.             1.3822020,  // (2053,  9, 15)
  668.         };

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

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

  683.         System.out.println();

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

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

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

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

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

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

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

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

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

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

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

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

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