KeyHoleSkeleton.java

  1. package org.drip.service.json;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

  78. /**
  79.  * <i>KeyHoleSkeleton</i> forwards the JSON Request to the Appropriate Processor and retrieves the Response
  80.  * JSON.
  81.  *
  82.  * <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationSupportLibrary.md">Computation Support</a></li>
  86.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/service/README.md">Environment, Product/Definition Containers, and Scenario/State Manipulation APIs</a></li>
  87.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/service/json/README.md">JSON Based Valuation Request Service</a></li>
  88.  *  </ul>
  89.  * <br><br>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class KeyHoleSkeleton {

  94.     /**
  95.      * JSON Based in/out Generic Thunker
  96.      *
  97.      * @param jsonInput JSON Request
  98.      *
  99.      * @return JSON Response
  100.      */

  101.     public static final org.drip.json.simple.JSONObject Thunker (
  102.         final org.drip.json.simple.JSONObject jsonInput)
  103.     {
  104.         if (null == jsonInput || !jsonInput.containsKey ("API") || !jsonInput.containsKey ("Parameters"))
  105.             return null;

  106.         java.lang.Object objAPIName = jsonInput.get ("API");

  107.         if (!(objAPIName instanceof java.lang.String)) return null;

  108.         java.lang.String strAPIName = (java.lang.String) objAPIName;

  109.         org.drip.service.env.EnvManager.InitEnv ("");

  110.         java.lang.Object objParameter = jsonInput.get ("Parameters");

  111.         if (null == objParameter) return null;

  112.         org.drip.json.simple.JSONObject jsonParameter = (org.drip.json.simple.JSONObject)
  113.             org.drip.json.simple.JSONValue.parse (objParameter.toString());

  114.         if ("DATE::ISHOLIDAY".equalsIgnoreCase (strAPIName))
  115.             return org.drip.service.json.DateProcessor.IsHoliday (jsonParameter);

  116.         if ("DATE::ADDDAYS".equalsIgnoreCase (strAPIName))
  117.             return org.drip.service.json.DateProcessor.AddDays (jsonParameter);

  118.         if ("DATE::ADJUSTBUSINESSDAYS".equalsIgnoreCase (strAPIName))
  119.             return org.drip.service.json.DateProcessor.AdjustBusinessDays (jsonParameter);

  120.         if ("FUNDINGSTATE".equalsIgnoreCase (strAPIName))
  121.             return org.drip.service.json.LatentStateProcessor.FundingCurveThunker (jsonParameter);

  122.         if ("CREDITSTATE".equalsIgnoreCase (strAPIName))
  123.             return org.drip.service.json.LatentStateProcessor.CreditCurveThunker (jsonParameter);

  124.         if ("DEPOSIT::SECULARMETRICS".equalsIgnoreCase (strAPIName)) return null;

  125.         if ("DEPOSIT::CURVEMETRICS".equalsIgnoreCase (strAPIName))
  126.             return org.drip.service.json.DepositProcessor.CurveMetrics (jsonParameter);

  127.         if ("BOND::SECULARMETRICS".equalsIgnoreCase (strAPIName))
  128.             return org.drip.service.json.BondProcessor.SecularMetrics (jsonParameter);

  129.         if ("BOND::CURVEMETRICS".equalsIgnoreCase (strAPIName))
  130.             return org.drip.service.json.BondProcessor.CurveMetrics (jsonParameter);

  131.         if ("BOND::CASHFLOWS".equalsIgnoreCase (strAPIName))
  132.             return org.drip.service.json.BondProcessor.CashFlows (jsonParameter);

  133.         if ("FORWARDRATEFUTURES::SECULARMETRICS".equalsIgnoreCase (strAPIName)) return null;

  134.         if ("FORWARDRATEFUTURES::CURVEMETRICS".equalsIgnoreCase (strAPIName))
  135.             return org.drip.service.json.ForwardRateFuturesProcessor.CurveMetrics (jsonParameter);

  136.         if ("FIXFLOAT::SECULARMETRICS".equalsIgnoreCase (strAPIName))
  137.             return org.drip.service.json.FixFloatProcessor.CurveMetrics (jsonParameter);

  138.         if ("CREDITDEFAULTSWAP::SECULARMETRICS".equalsIgnoreCase (strAPIName)) return null;

  139.         if ("CREDITDEFAULTSWAP::CURVEMETRICS".equalsIgnoreCase (strAPIName))
  140.             return org.drip.service.json.CreditDefaultSwapProcessor.CurveMetrics (jsonParameter);

  141.         if ("FIXEDASSETBACKED::SECULARMETRICS".equalsIgnoreCase (strAPIName))
  142.             return org.drip.service.json.FixedAssetBackedProcessor.SecularMetrics (jsonParameter);

  143.         if ("PORTFOLIOALLOCATION::BUDGETCONSTRAINEDMEANVARIANCE".equalsIgnoreCase (strAPIName))
  144.             return org.drip.json.assetallocation.PortfolioConstructionProcessor.BudgetConstrainedAllocator
  145.                 (jsonParameter);

  146.         if ("PORTFOLIOALLOCATION::RETURNSCONSTRAINEDMEANVARIANCE".equalsIgnoreCase (strAPIName))
  147.             return org.drip.json.assetallocation.PortfolioConstructionProcessor.ReturnsConstrainedAllocator
  148.                 (jsonParameter);

  149.         if ("PREPAYASSETBACKED::SECULARMETRICS".equalsIgnoreCase (strAPIName))
  150.             return org.drip.service.json.PrepayAssetBackedProcessor.SecularMetrics (jsonParameter);

  151.         if ("TREASURYBOND::SECULARMETRICS".equalsIgnoreCase (strAPIName))
  152.             return org.drip.service.json.TreasuryBondProcessor.SecularMetrics (jsonParameter);

  153.         if ("BLACKLITTERMAN::BAYESIANMETRICS".equalsIgnoreCase (strAPIName))
  154.             return org.drip.json.assetallocation.BlackLittermanProcessor.Estimate (jsonParameter);

  155.         return null;
  156.     }

  157.     /**
  158.      * JSON String Based in/out Generic Thunker
  159.      *
  160.      * @param strJSONRequest JSON String Request
  161.      *
  162.      * @return JSON String Response
  163.      */

  164.     public static final java.lang.String Thunker (
  165.         final java.lang.String strJSONRequest)
  166.     {
  167.         if (null == strJSONRequest || strJSONRequest.isEmpty()) return null;

  168.         java.lang.Object objInput = org.drip.json.simple.JSONValue.parse (strJSONRequest);

  169.         if (null == objInput || !(objInput instanceof org.drip.json.simple.JSONObject)) return null;

  170.         org.drip.json.simple.JSONObject jsonResponse = Thunker ((org.drip.json.simple.JSONObject) objInput);

  171.         return null == jsonResponse ? null : jsonResponse.toJSONString();
  172.     }
  173. }