BondClientCurve.java

  1. package org.drip.sample.service;

  2. import org.drip.analytics.date.*;
  3. import org.drip.json.parser.Converter;
  4. import org.drip.json.simple.JSONObject;
  5. import org.drip.service.env.EnvManager;
  6. import org.drip.service.json.KeyHoleSkeleton;

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

  10. /*!
  11.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  12.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  13.  *
  14.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  15.  *      libraries targeting analysts and developers
  16.  *      https://lakshmidrip.github.io/DRIP/
  17.  *  
  18.  *  DRIP is composed of four main libraries:
  19.  *  
  20.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  21.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  22.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  23.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  24.  *
  25.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  26.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  27.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  28.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  29.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  30.  *
  31.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  32.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  33.  *
  34.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  35.  *
  36.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  37.  *
  38.  *  Licensed under the Apache License, Version 2.0 (the "License");
  39.  *      you may not use this file except in compliance with the License.
  40.  *  
  41.  *  You may obtain a copy of the License at
  42.  *      http://www.apache.org/licenses/LICENSE-2.0
  43.  *  
  44.  *  Unless required by applicable law or agreed to in writing, software
  45.  *      distributed under the License is distributed on an "AS IS" BASIS,
  46.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  47.  *  
  48.  *  See the License for the specific language governing permissions and
  49.  *      limitations under the License.
  50.  */

  51. /**
  52.  * BondClientCurve demonstrates the Invocation and Examination of the JSON-based Bond Valuation Service for
  53.  *  generating the Curve Metrics.
  54.  *
  55.  * @author Lakshmi Krishnamurthy
  56.  */

  57. public class BondClientCurve {

  58.     @SuppressWarnings ("unchecked") public static final void main (
  59.         final String[] astrArgs)
  60.         throws Exception
  61.     {
  62.         EnvManager.InitEnv ("");

  63.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  64.             2017,
  65.             DateUtil.MAY,
  66.             9
  67.         );

  68.         String strCurrency = "USD";

  69.         String[] astrDepositMaturityTenor = new String[] {
  70.             "2D"
  71.         };

  72.         double[] adblDepositQuote = new double[] {
  73.             0.0103456 // 2D
  74.         };

  75.         double[] adblFuturesQuote = new double[] {
  76.             0.01070,
  77.             0.01235,
  78.             0.01360
  79.         };

  80.         String[] astrFixFloatMaturityTenor = new String[] {
  81.             "01Y",
  82.             "02Y",
  83.             "03Y",
  84.             "04Y",
  85.             "05Y",
  86.             "06Y",
  87.             "07Y",
  88.             "08Y",
  89.             "09Y",
  90.             "10Y",
  91.             "11Y",
  92.             "12Y",
  93.             "15Y",
  94.             "20Y",
  95.             "25Y",
  96.             "30Y",
  97.             "40Y",
  98.             "50Y"
  99.         };

  100.         double[] adblFixFloatQuote = new double[] {
  101.             0.012484, //  1Y
  102.             0.014987, //  2Y
  103.             0.017036, //  3Y
  104.             0.018624, //  4Y
  105.             0.019868, //  5Y
  106.             0.020921, //  6Y
  107.             0.021788, //  7Y
  108.             0.022530, //  8Y
  109.             0.023145, //  9Y
  110.             0.023685, // 10Y
  111.             0.024153, // 11Y
  112.             0.024562, // 12Y
  113.             0.025389, // 15Y
  114.             0.026118, // 20Y
  115.             0.026368, // 25Y
  116.             0.026432, // 30Y
  117.             0.026339, // 40Y
  118.             0.026122  // 50Y
  119.         };

  120.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  121.             2012,
  122.             DateUtil.APRIL,
  123.             12
  124.         );

  125.         JulianDate dtMaturity = DateUtil.CreateFromYMD (
  126.             2027,
  127.             DateUtil.APRIL,
  128.             12
  129.         );

  130.         String strTreasuryCode = "UST";

  131.         String[] astrTreasuryTenor = new String[] {
  132.             "1Y",
  133.             "2Y",
  134.             "3Y",
  135.             "5Y",
  136.             "7Y",
  137.             "10Y",
  138.             "20Y",
  139.             "30Y"
  140.         };

  141.         double[] adblTreasuryYield = new double[] {
  142.             0.0083, //  1Y
  143.             0.0122, //  2Y
  144.             0.0149, //  3Y
  145.             0.0193, //  5Y
  146.             0.0227, //  7Y
  147.             0.0248, // 10Y
  148.             0.0280, // 20Y
  149.             0.0308  // 30Y
  150.         };

  151.         JSONObject jsonParameters = new JSONObject();

  152.         jsonParameters.put ("SpotDate", dtSpot.toString());

  153.         jsonParameters.put ("Currency", strCurrency);

  154.         jsonParameters.put ("DepositTenor", Converter.Array (astrDepositMaturityTenor));

  155.         jsonParameters.put ("DepositQuote", Converter.Array (adblDepositQuote));

  156.         jsonParameters.put ("FuturesQuote", Converter.Array (adblFuturesQuote));

  157.         jsonParameters.put ("FixFloatTenor", Converter.Array (astrFixFloatMaturityTenor));

  158.         jsonParameters.put ("FixFloatQuote", Converter.Array (adblFixFloatQuote));

  159.         jsonParameters.put ("TreasuryCode", strTreasuryCode);

  160.         jsonParameters.put ("TreasuryTenor", Converter.Array (astrTreasuryTenor));

  161.         jsonParameters.put ("TreasuryYield", Converter.Array (adblTreasuryYield));

  162.         jsonParameters.put ("BondName", "  PDVSA  5.3750 12-APR-2027 ");

  163.         jsonParameters.put ("BondCoupon", 0.053750);

  164.         jsonParameters.put ("BondFrequency", 2);

  165.         jsonParameters.put ("BondDayCount", "30/360");

  166.         jsonParameters.put ("BondEffectiveDate", dtEffective.toString());

  167.         jsonParameters.put ("BondMaturityDate", dtMaturity.toString());

  168.         jsonParameters.put ("BondCleanPrice", 0.38239);

  169.         JSONObject jsonRequest = new JSONObject();

  170.         jsonRequest.put ("API", "BOND::CURVEMETRICS");

  171.         jsonRequest.put ("Parameters", jsonParameters);

  172.         System.out.println ("\n\t|---------------- JSON REQUEST -----------------|\n");

  173.         System.out.println (jsonRequest.toJSONString());

  174.         System.out.println ("\n\t|---------------- JSON RESPONSE ----------------|\n");

  175.         System.out.println (KeyHoleSkeleton.Thunker (jsonRequest.toJSONString()));

  176.         EnvManager.TerminateEnv();
  177.     }
  178. }