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

  52. /**
  53.  * CreditDefaultSwapClient demonstrates the Invocation and Examination of the JSON-based CDS Service Client.
  54.  *
  55.  * @author Lakshmi Krishnamurthy
  56.  */

  57. public class CreditDefaultSwapClient {

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

  63.         JulianDate dtSpot = DateUtil.Today();

  64.         String strCurrency = "USD";
  65.         String strReferenceEntity = "DRIP";

  66.         String[] astrDepositMaturityTenor = new String[] {
  67.             "04D",
  68.             "07D",
  69.             "14D",
  70.             "30D",
  71.             "60D"
  72.         };

  73.         double[] adblDepositQuote = new double[] {
  74.             0.0017,     //  2D
  75.             0.0017,     //  7D
  76.             0.0018,     // 14D
  77.             0.0020,     // 30D
  78.             0.0023      // 60D
  79.         };

  80.         double[] adblFuturesQuote = new double[] {
  81.             0.0027,
  82.             0.0032,
  83.             0.0041,
  84.             0.0054,
  85.             0.0077,
  86.             0.0104,
  87.             0.0134,
  88.             0.0160
  89.         };

  90.         String[] astrFixFloatMaturityTenor = new String[] {
  91.             "04Y",
  92.             "05Y",
  93.             "06Y",
  94.             "07Y",
  95.             "08Y",
  96.             "09Y",
  97.             "10Y",
  98.             "11Y",
  99.             "12Y",
  100.             "15Y",
  101.             "20Y",
  102.             "25Y",
  103.             "30Y",
  104.             "40Y",
  105.             "50Y"
  106.         };

  107.         double[] adblFixFloatQuote = new double[] {
  108.             0.0166,     //   4Y
  109.             0.0206,     //   5Y
  110.             0.0241,     //   6Y
  111.             0.0269,     //   7Y
  112.             0.0292,     //   8Y
  113.             0.0311,     //   9Y
  114.             0.0326,     //  10Y
  115.             0.0340,     //  11Y
  116.             0.0351,     //  12Y
  117.             0.0375,     //  15Y
  118.             0.0393,     //  20Y
  119.             0.0402,     //  25Y
  120.             0.0407,     //  30Y
  121.             0.0409,     //  40Y
  122.             0.0409      //  50Y
  123.         };

  124.         String[] astrCDSMaturityTenor = new String[] {
  125.             "06M",
  126.             "01Y",
  127.             "02Y",
  128.             "03Y",
  129.             "04Y",
  130.             "05Y",
  131.             "07Y",
  132.             "10Y"
  133.         };

  134.         double[] adblCDSQuote = new double[] {
  135.              60.,   //  6M
  136.              68.,   //  1Y
  137.              88.,   //  2Y
  138.             102.,   //  3Y
  139.             121.,   //  4Y
  140.             138.,   //  5Y
  141.             168.,   //  7Y
  142.             188.    // 10Y
  143.         };

  144.         JSONObject jsonParameters = new JSONObject();

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

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

  147.         jsonParameters.put ("ReferenceEntity", strReferenceEntity);

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

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

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

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

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

  153.         jsonParameters.put ("CDSTenor", Converter.Array (astrCDSMaturityTenor));

  154.         jsonParameters.put ("CDSQuote", Converter.Array (adblCDSQuote));

  155.         jsonParameters.put ("CDSMaturity", "05Y");

  156.         jsonParameters.put ("CDSCoupon", 0.0100);

  157.         JSONObject jsonRequest = new JSONObject();

  158.         jsonRequest.put ("API", "CREDITDEFAULTSWAP::CURVEMETRICS");

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

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

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

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

  163.         System.out.println (KeyHoleSkeleton.Thunker (jsonRequest.toJSONString()));
  164.     }
  165. }