HUFShapePreserving1YStart.java

  1. package org.drip.sample.fundinghistorical;

  2. import java.util.Map;

  3. import org.drip.analytics.date.JulianDate;
  4. import org.drip.feed.loader.*;
  5. import org.drip.historical.state.FundingCurveMetrics;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;
  8. import org.drip.service.state.FundingCurveAPI;
  9. import org.drip.service.template.LatentMarketStateBuilder;

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

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

  74. /**
  75.  * <i>HUFShapePreserving1YStart</i> Generates the Historical HUF Shape Preserving Funding Curve Native
  76.  * Compounded Forward Rate starting at 1Y Tenor.
  77.  *  
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  81.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  82.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  83.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/fundinghistorical/README.md">Multi-Mode Funding Curve Historical Forwards</a></li>
  84.  *  </ul>
  85.  * <br><br>
  86.  *
  87.  * @author Lakshmi Krishnamurthy
  88.  */

  89. public class HUFShapePreserving1YStart {

  90.     public static final void main (
  91.         final String[] astrArgs)
  92.         throws Exception
  93.     {
  94.         EnvManager.InitEnv ("");

  95.         String strCurrency = "HUF";
  96.         String strClosesLocation = "C:\\DROP\\Daemons\\Transforms\\FundingStateMarks\\" + strCurrency + "ShapePreservingReconstitutor.csv";
  97.         String[] astrInTenor = new String[] {
  98.             "1Y"
  99.         };
  100.         String[] astrForTenor = new String[] {
  101.             "1Y",
  102.             "2Y",
  103.             "3Y",
  104.             "4Y",
  105.             "5Y",
  106.             "6Y",
  107.             "7Y",
  108.             "8Y",
  109.             "9Y",
  110.             "10Y",
  111.             "11Y",
  112.             "12Y",
  113.             "15Y",
  114.             "20Y",
  115.             "25Y",
  116.         };
  117.         String[] astrFixFloatMaturityTenor = new String[] {
  118.             "1Y",
  119.             "2Y",
  120.             "3Y",
  121.             "4Y",
  122.             "5Y",
  123.             "6Y",
  124.             "7Y",
  125.             "8Y",
  126.             "9Y",
  127.             "10Y",
  128.             "11Y",
  129.             "12Y",
  130.             "15Y",
  131.             "20Y",
  132.             "25Y",
  133.             "30Y",
  134.             "40Y",
  135.             "50Y"
  136.         };

  137.         CSVGrid csvGrid = CSVParser.StringGrid (
  138.             strClosesLocation,
  139.             true
  140.         );

  141.         JulianDate[] adtClose = csvGrid.dateArrayAtColumn (0);

  142.         double[] adblFixFloatQuote1Y = csvGrid.doubleArrayAtColumn (1);

  143.         double[] adblFixFloatQuote2Y = csvGrid.doubleArrayAtColumn (2);

  144.         double[] adblFixFloatQuote3Y = csvGrid.doubleArrayAtColumn (3);

  145.         double[] adblFixFloatQuote4Y = csvGrid.doubleArrayAtColumn (4);

  146.         double[] adblFixFloatQuote5Y = csvGrid.doubleArrayAtColumn (5);

  147.         double[] adblFixFloatQuote6Y = csvGrid.doubleArrayAtColumn (6);

  148.         double[] adblFixFloatQuote7Y = csvGrid.doubleArrayAtColumn (7);

  149.         double[] adblFixFloatQuote8Y = csvGrid.doubleArrayAtColumn (8);

  150.         double[] adblFixFloatQuote9Y = csvGrid.doubleArrayAtColumn (9);

  151.         double[] adblFixFloatQuote10Y = csvGrid.doubleArrayAtColumn (10);

  152.         double[] adblFixFloatQuote11Y = csvGrid.doubleArrayAtColumn (11);

  153.         double[] adblFixFloatQuote12Y = csvGrid.doubleArrayAtColumn (12);

  154.         double[] adblFixFloatQuote15Y = csvGrid.doubleArrayAtColumn (13);

  155.         double[] adblFixFloatQuote20Y = csvGrid.doubleArrayAtColumn (14);

  156.         double[] adblFixFloatQuote25Y = csvGrid.doubleArrayAtColumn (15);

  157.         double[] adblFixFloatQuote30Y = csvGrid.doubleArrayAtColumn (16);

  158.         double[] adblFixFloatQuote40Y = csvGrid.doubleArrayAtColumn (17);

  159.         double[] adblFixFloatQuote50Y = csvGrid.doubleArrayAtColumn (18);

  160.         int iNumClose = adtClose.length;
  161.         JulianDate[] adtSpot = new JulianDate[iNumClose];
  162.         double[][] aadblFixFloatQuote = new double[iNumClose][18];

  163.         for (int i = 0; i < iNumClose; ++i) {
  164.             adtSpot[i] = adtClose[i];
  165.             aadblFixFloatQuote[i][0] = adblFixFloatQuote1Y[i];
  166.             aadblFixFloatQuote[i][1] = adblFixFloatQuote2Y[i];
  167.             aadblFixFloatQuote[i][2] = adblFixFloatQuote3Y[i];
  168.             aadblFixFloatQuote[i][3] = adblFixFloatQuote4Y[i];
  169.             aadblFixFloatQuote[i][4] = adblFixFloatQuote5Y[i];
  170.             aadblFixFloatQuote[i][5] = adblFixFloatQuote6Y[i];
  171.             aadblFixFloatQuote[i][6] = adblFixFloatQuote7Y[i];
  172.             aadblFixFloatQuote[i][7] = adblFixFloatQuote8Y[i];
  173.             aadblFixFloatQuote[i][8] = adblFixFloatQuote9Y[i];
  174.             aadblFixFloatQuote[i][9] = adblFixFloatQuote10Y[i];
  175.             aadblFixFloatQuote[i][10] = adblFixFloatQuote11Y[i];
  176.             aadblFixFloatQuote[i][11] = adblFixFloatQuote12Y[i];
  177.             aadblFixFloatQuote[i][12] = adblFixFloatQuote15Y[i];
  178.             aadblFixFloatQuote[i][13] = adblFixFloatQuote20Y[i];
  179.             aadblFixFloatQuote[i][14] = adblFixFloatQuote25Y[i];
  180.             aadblFixFloatQuote[i][15] = adblFixFloatQuote30Y[i];
  181.             aadblFixFloatQuote[i][16] = adblFixFloatQuote40Y[i];
  182.             aadblFixFloatQuote[i][17] = adblFixFloatQuote50Y[i];
  183.         }

  184.         String strDump = "Date";

  185.         for (String strInTenor : astrInTenor) {
  186.             for (String strForTenor : astrForTenor)
  187.                 strDump += "," + strInTenor + strForTenor;
  188.         }

  189.         System.out.println (strDump);

  190.         Map<JulianDate, FundingCurveMetrics> mapFCM = FundingCurveAPI.HorizonMetrics (
  191.             adtSpot,
  192.             astrFixFloatMaturityTenor,
  193.             aadblFixFloatQuote,
  194.             astrInTenor,
  195.             astrForTenor,
  196.             strCurrency,
  197.             LatentMarketStateBuilder.SHAPE_PRESERVING
  198.         );

  199.         for (int i = 0; i < iNumClose; ++i) {
  200.             FundingCurveMetrics fcm = mapFCM.get (adtSpot[i]);

  201.             strDump = adtSpot[i].toString();

  202.             for (String strInTenor : astrInTenor) {
  203.                 for (String strForTenor : astrForTenor)
  204.                     strDump += "," + FormatUtil.FormatDouble (
  205.                         fcm.nativeForwardRate (
  206.                             strInTenor,
  207.                             strForTenor
  208.                         ), 1, 5, 100.
  209.                     );
  210.             }

  211.             System.out.println (strDump);
  212.         }

  213.         EnvManager.TerminateEnv();
  214.     }
  215. }