NZDSmooth1MForward.java

  1. package org.drip.sample.overnighthistorical;

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

  55. /**
  56.  * NZDSmooth1MForward Generates the Historical NZD Smoothened Overnight Curve Native 1M Compounded Forward
  57.  *  Rate.
  58.  *
  59.  * @author Lakshmi Krishnamurthy
  60.  */

  61. public class NZDSmooth1MForward {

  62.     public static final void main (
  63.         final String[] astrArgs)
  64.         throws Exception
  65.     {
  66.         EnvManager.InitEnv ("");

  67.         String strCurrency = "NZD";
  68.         String strClosesLocation = "C:\\DRIP\\CreditAnalytics\\Daemons\\Transforms\\OvernightOISMarks\\" + strCurrency + "OISSmoothReconstitutor.csv";
  69.         String[] astrForTenor = new String[] {
  70.             "1M"
  71.         };
  72.         String[] astrInTenor = new String[] {
  73.             "1W",
  74.             "2W",
  75.             "3W",
  76.             "1M",
  77.             "2M",
  78.             "3M",
  79.             "4M",
  80.             "5M",
  81.             "6M",
  82.             "9M",
  83.             "1Y",
  84.             "18M",
  85.             "2Y",
  86.             "3Y",
  87.             "4Y",
  88.             "5Y"
  89.         };
  90.         String[] astrOISMaturityTenor = new String[] {
  91.             "1W",
  92.             "2W",
  93.             "3W",
  94.             "1M",
  95.             "2M",
  96.             "3M",
  97.             "4M",
  98.             "5M",
  99.             "6M",
  100.             "9M",
  101.             "1Y",
  102.             "18M",
  103.             "2Y",
  104.             "3Y",
  105.             "4Y",
  106.             "5Y"
  107.         };

  108.         CSVGrid csvGrid = CSVParser.StringGrid (
  109.             strClosesLocation,
  110.             true
  111.         );

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

  113.         double[] adblOISQuote1W = csvGrid.doubleArrayAtColumn (1);

  114.         double[] adblOISQuote2W = csvGrid.doubleArrayAtColumn (2);

  115.         double[] adblOISQuote3W = csvGrid.doubleArrayAtColumn (3);

  116.         double[] adblOISQuote1M = csvGrid.doubleArrayAtColumn (4);

  117.         double[] adblOISQuote2M = csvGrid.doubleArrayAtColumn (5);

  118.         double[] adblOISQuote3M = csvGrid.doubleArrayAtColumn (6);

  119.         double[] adblOISQuote4M = csvGrid.doubleArrayAtColumn (7);

  120.         double[] adblOISQuote5M = csvGrid.doubleArrayAtColumn (8);

  121.         double[] adblOISQuote6M = csvGrid.doubleArrayAtColumn (9);

  122.         double[] adblOISQuote9M = csvGrid.doubleArrayAtColumn (10);

  123.         double[] adblOISQuote1Y = csvGrid.doubleArrayAtColumn (11);

  124.         double[] adblOISQuote18M = csvGrid.doubleArrayAtColumn (12);

  125.         double[] adblOISQuote2Y = csvGrid.doubleArrayAtColumn (13);

  126.         double[] adblOISQuote3Y = csvGrid.doubleArrayAtColumn (14);

  127.         double[] adblOISQuote4Y = csvGrid.doubleArrayAtColumn (15);

  128.         double[] adblOISQuote5Y = csvGrid.doubleArrayAtColumn (16);

  129.         int iNumClose = adtClose.length;
  130.         JulianDate[] adtSpot = new JulianDate[iNumClose];
  131.         double[][] aadblOISQuote = new double[iNumClose][16];

  132.         for (int i = 0; i < iNumClose; ++i) {
  133.             adtSpot[i] = adtClose[i];
  134.             aadblOISQuote[i][0] = adblOISQuote1W[i];
  135.             aadblOISQuote[i][1] = adblOISQuote2W[i];
  136.             aadblOISQuote[i][2] = adblOISQuote3W[i];
  137.             aadblOISQuote[i][3] = adblOISQuote1M[i];
  138.             aadblOISQuote[i][4] = adblOISQuote2M[i];
  139.             aadblOISQuote[i][5] = adblOISQuote3M[i];
  140.             aadblOISQuote[i][6] = adblOISQuote4M[i];
  141.             aadblOISQuote[i][7] = adblOISQuote5M[i];
  142.             aadblOISQuote[i][8] = adblOISQuote6M[i];
  143.             aadblOISQuote[i][9] = adblOISQuote9M[i];
  144.             aadblOISQuote[i][10] = adblOISQuote1Y[i];
  145.             aadblOISQuote[i][11] = adblOISQuote18M[i];
  146.             aadblOISQuote[i][12] = adblOISQuote2Y[i];
  147.             aadblOISQuote[i][13] = adblOISQuote3Y[i];
  148.             aadblOISQuote[i][14] = adblOISQuote4Y[i];
  149.             aadblOISQuote[i][15] = adblOISQuote5Y[i];
  150.         }

  151.         String strDump = "Date";

  152.         for (String strInTenor : astrInTenor) {
  153.             for (String strForTenor : astrForTenor)
  154.                 strDump += "," + strInTenor + strForTenor;
  155.         }

  156.         System.out.println (strDump);

  157.         Map<JulianDate, FundingCurveMetrics> mapFCM = OvernightCurveAPI.HorizonMetrics (
  158.             adtSpot,
  159.             astrOISMaturityTenor,
  160.             aadblOISQuote,
  161.             astrInTenor,
  162.             astrForTenor,
  163.             strCurrency,
  164.             LatentMarketStateBuilder.SMOOTH
  165.         );

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

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

  169.             for (String strInTenor : astrInTenor) {
  170.                 for (String strForTenor : astrForTenor)
  171.                     strDump += "," + FormatUtil.FormatDouble (
  172.                         fcm.nativeForwardRate (
  173.                             strInTenor,
  174.                             strForTenor
  175.                         ), 1, 5, 100.
  176.                     );
  177.             }

  178.             System.out.println (strDump);
  179.         }
  180.     }
  181. }