FixedCouponRVMeasures.java

  1. package org.drip.sample.bondapi;

  2. import java.util.Map;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.output.BondRVMeasures;
  5. import org.drip.numerical.common.FormatUtil;
  6. import org.drip.service.env.EnvManager;
  7. import org.drip.service.product.FixedBondAPI;

  8. /*
  9.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  10.  */

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

  83. /**
  84.  * <i>FixedCouponRVMeasures</i> demonstrates the Invocation and Examination of the Relative Value Metrics for
  85.  * the Fixed Coupon Bond.
  86.  *  
  87.  * <br><br>
  88.  *  <ul>
  89.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  90.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  91.  *      <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>
  92.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bondapi/README.md">Fixed Coupon KRD + RV Measures</a></li>
  93.  *  </ul>
  94.  * <br><br>
  95.  *
  96.  * @author Lakshmi Krishnamurthy
  97.  */

  98. public class FixedCouponRVMeasures {

  99.     public static final void main (
  100.         final String[] astrArgs)
  101.         throws Exception
  102.     {
  103.         EnvManager.InitEnv (
  104.             "",
  105.             true
  106.         );

  107.         int iSpotDate = DateUtil.CreateFromYMD (
  108.             2015,
  109.             DateUtil.NOVEMBER,
  110.             18
  111.         ).julian();

  112.         String[] astrFundingCurveDepositTenor = new String[] {
  113.             "2D",
  114.             "1W",
  115.             "1M",
  116.             "2M",
  117.             "3M"
  118.         };

  119.         double[] adblFundingCurveDepositQuote = new double[] {
  120.             0.00195, // 2D
  121.             0.00176, // 1W
  122.             0.00301, // 1M
  123.             0.00401, // 2M
  124.             0.00492  // 3M
  125.         };

  126.         String strFundingCurveDepositMeasure = "ForwardRate";

  127.         double[] adblFundingCurveFuturesQuote = new double[] {
  128.             0.00609,
  129.             0.00687
  130.         };

  131.         String strFundingCurveFuturesMeasure = "ForwardRate";

  132.         String[] astrFundingCurveFixFloatTenor = new String[] {
  133.             "01Y",
  134.             "02Y",
  135.             "03Y",
  136.             "04Y",
  137.             "05Y",
  138.             "06Y",
  139.             "07Y",
  140.             "08Y",
  141.             "09Y",
  142.             "10Y",
  143.             "11Y",
  144.             "12Y",
  145.             "15Y",
  146.             "20Y",
  147.             "25Y",
  148.             "30Y",
  149.             "40Y",
  150.             "50Y"
  151.         };

  152.         double[] adblFundingCurveFixFloatQuote = new double[] {
  153.             0.00762, //  1Y
  154.             0.01055, //  2Y
  155.             0.01300, //  3Y
  156.             0.01495, //  4Y
  157.             0.01651, //  5Y
  158.             0.01787, //  6Y
  159.             0.01904, //  7Y
  160.             0.02005, //  8Y
  161.             0.02090, //  9Y
  162.             0.02166, // 10Y
  163.             0.02231, // 11Y
  164.             0.02289, // 12Y
  165.             0.02414, // 15Y
  166.             0.02570, // 20Y
  167.             0.02594, // 25Y
  168.             0.02627, // 30Y
  169.             0.02648, // 40Y
  170.             0.02632  // 50Y
  171.         };

  172.         String strFundingFixFloatMeasure = "SwapRate";

  173.         int[] aiGovvieCurveTreasuryEffective = new int[] {
  174.             iSpotDate,
  175.             iSpotDate,
  176.             iSpotDate,
  177.             iSpotDate,
  178.             iSpotDate,
  179.             iSpotDate,
  180.             iSpotDate
  181.         };

  182.         int[] aiGovvieCurveTreasuryMaturity = new int[] {
  183.             new JulianDate (iSpotDate).addTenor ("1Y").julian(),
  184.             new JulianDate (iSpotDate).addTenor ("2Y").julian(),
  185.             new JulianDate (iSpotDate).addTenor ("3Y").julian(),
  186.             new JulianDate (iSpotDate).addTenor ("5Y").julian(),
  187.             new JulianDate (iSpotDate).addTenor ("7Y").julian(),
  188.             new JulianDate (iSpotDate).addTenor ("10Y").julian(),
  189.             new JulianDate (iSpotDate).addTenor ("30Y").julian()
  190.         };

  191.         double[] adblGovvieCurveTreasuryCoupon = new double[] {
  192.             0.0100,
  193.             0.0100,
  194.             0.0125,
  195.             0.0150,
  196.             0.0200,
  197.             0.0225,
  198.             0.0300
  199.         };

  200.         double[] adblGovvieCurveTreasuryYield = new double[] {
  201.             0.00692,
  202.             0.00945,
  203.             0.01257,
  204.             0.01678,
  205.             0.02025,
  206.             0.02235,
  207.             0.02972
  208.         };

  209.         String strGovvieCurveTreasuryMeasure = "Yield";

  210.         String[] astrCreditCurveCDSTenor = new String[] {
  211.             "06M",
  212.             "01Y",
  213.             "02Y",
  214.             "03Y",
  215.             "04Y",
  216.             "05Y",
  217.             "07Y",
  218.             "10Y"
  219.         };

  220.         double[] adblCreditCurveCDSCoupon = new double[] {
  221.              60.,   //  6M
  222.              68.,   //  1Y
  223.              88.,   //  2Y
  224.             102.,   //  3Y
  225.             121.,   //  4Y
  226.             138.,   //  5Y
  227.             168.,   //  7Y
  228.             188.    // 10Y
  229.         };

  230.         String strIssuerName = "AEG";
  231.         int iBondCouponFrequency = 2;
  232.         String strBondCouponDayCount = "30/360";
  233.         String strBondCouponCurrency = "USD";
  234.         String strGovvieCode = "UST";

  235.         JulianDate[] adtBondEffective = new JulianDate[] {
  236.             DateUtil.CreateFromYMD (2007, 12, 20),
  237.             DateUtil.CreateFromYMD (1996,  7, 25),
  238.             DateUtil.CreateFromYMD (1996, 10, 29),
  239.             DateUtil.CreateFromYMD (2014, 12,  9),
  240.             DateUtil.CreateFromYMD (1997,  4, 29),
  241.             DateUtil.CreateFromYMD (2014,  9, 25),
  242.             DateUtil.CreateFromYMD (2008,  5, 22),
  243.             DateUtil.CreateFromYMD (2011,  7, 21)
  244.         };

  245.         JulianDate[] adtBondMaturity = new JulianDate[] {
  246.             DateUtil.CreateFromYMD (2018,  1, 15),
  247.             DateUtil.CreateFromYMD (2025,  7, 15),
  248.             DateUtil.CreateFromYMD (2026, 10, 15),
  249.             DateUtil.CreateFromYMD (2026, 12, 15),
  250.             DateUtil.CreateFromYMD (2027,  4, 29),
  251.             DateUtil.CreateFromYMD (2027, 10,  1),
  252.             DateUtil.CreateFromYMD (2038,  5, 15),
  253.             DateUtil.CreateFromYMD (2041,  7, 15)
  254.         };

  255.         double[] adblBondCoupon = new double[] {
  256.             0.06000,
  257.             0.07750,
  258.             0.07625,
  259.             0.04125,
  260.             0.08000,
  261.             0.04250,
  262.             0.06400,
  263.             0.05600
  264.         };

  265.         double[] adblCleanPrice = new double[] {
  266.             1.08529,
  267.             1.27021,
  268.             1.27274,
  269.             1.01235,
  270.             1.31537,
  271.             1.02263,
  272.             1.27570,
  273.             1.17460
  274.         };

  275.         BondRVMeasures[] aBMRV = new BondRVMeasures[adblCleanPrice.length];

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

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

  278.         System.out.println ("\t|  Issuer Bond Relative Value Metrics                                                                  ||");

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

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

  281.         System.out.println ("\t|  L -> R                                                                                              ||");

  282.         System.out.println ("\t|          Bond Issue Name                                                                             ||");

  283.         System.out.println ("\t|          Asset Swap Spread                                                                           ||");

  284.         System.out.println ("\t|          Bond Basis                                                                                  ||");

  285.         System.out.println ("\t|          Credit Basis                                                                                ||");

  286.         System.out.println ("\t|          Discount Margin                                                                             ||");

  287.         System.out.println ("\t|          G Spread                                                                                    ||");

  288.         System.out.println ("\t|          I Spread                                                                                    ||");

  289.         System.out.println ("\t|          Option Adjusted Spread                                                                      ||");

  290.         System.out.println ("\t|          Par Equivalent CDS Spread (PECS)                                                            ||");

  291.         System.out.println ("\t|          Treasury Spread                                                                             ||");

  292.         System.out.println ("\t|          Yield Spread                                                                                ||");

  293.         System.out.println ("\t|          Z Spread                                                                                    ||");

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

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

  296.         for (int i = 0; i < adblCleanPrice.length; ++i) {
  297.             aBMRV[i] = FixedBondAPI.RelativeValueMetrics (
  298.                 strIssuerName,
  299.                 adtBondEffective[i].julian(),
  300.                 adtBondMaturity[i].julian(),
  301.                 adblBondCoupon[i],
  302.                 iBondCouponFrequency,
  303.                 strBondCouponDayCount,
  304.                 strBondCouponCurrency,
  305.                 iSpotDate,
  306.                 astrFundingCurveDepositTenor,
  307.                 adblFundingCurveDepositQuote,
  308.                 strFundingCurveDepositMeasure,
  309.                 adblFundingCurveFuturesQuote,
  310.                 strFundingCurveFuturesMeasure,
  311.                 astrFundingCurveFixFloatTenor,
  312.                 adblFundingCurveFixFloatQuote,
  313.                 strFundingFixFloatMeasure,
  314.                 strGovvieCode,
  315.                 aiGovvieCurveTreasuryEffective,
  316.                 aiGovvieCurveTreasuryMaturity,
  317.                 adblGovvieCurveTreasuryCoupon,
  318.                 adblGovvieCurveTreasuryYield,
  319.                 strGovvieCurveTreasuryMeasure,
  320.                 strIssuerName,
  321.                 astrCreditCurveCDSTenor,
  322.                 adblCreditCurveCDSCoupon,
  323.                 adblCreditCurveCDSCoupon,
  324.                 "FairPremium",
  325.                 adblCleanPrice[i]
  326.             );

  327.             Map<String, Double> mapRV = aBMRV[i].toMap ("");

  328.             System.out.println (
  329.                 "\t| " + strIssuerName + " " + FormatUtil.FormatDouble (adblBondCoupon[i], 1, 4, 100.) + " " + adtBondMaturity[i] + " " +
  330.                 " | " + FormatUtil.FormatDouble (mapRV.get ("AssetSwapSpread"), 3, 0, 10000.) +
  331.                 " | " + FormatUtil.FormatDouble (mapRV.get ("BondBasis"), 3, 0, 10000.) +
  332.                 " | " + FormatUtil.FormatDouble (mapRV.get ("CreditBasis"), 3, 0, 1.) +
  333.                 " | " + FormatUtil.FormatDouble (mapRV.get ("DiscountMargin"), 3, 0, 1.) +
  334.                 " | " + FormatUtil.FormatDouble (mapRV.get ("GSpread"), 3, 0, 10000.) +
  335.                 " | " + FormatUtil.FormatDouble (mapRV.get ("ISpread"), 3, 0, 10000.) +
  336.                 " | " + FormatUtil.FormatDouble (mapRV.get ("OAS"), 3, 0, 10000.) +
  337.                 " | " + FormatUtil.FormatDouble (mapRV.get ("PECS"), 3, 0, 1.) +
  338.                 " | " + FormatUtil.FormatDouble (mapRV.get ("TSYSpread"), 3, 0, 10000.) +
  339.                 " | " + FormatUtil.FormatDouble (mapRV.get ("YieldSpread"), 3, 0, 10000.) +
  340.                 " | " + FormatUtil.FormatDouble (mapRV.get ("ZSpread"), 3, 0, 10000.) + " ||"
  341.             );
  342.         }

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

  344.         EnvManager.TerminateEnv();
  345.     }
  346. }