ER1Attribution.java

  1. package org.drip.sample.forwardratefuturespnl;

  2. import java.util.List;

  3. import org.drip.analytics.date.JulianDate;
  4. import org.drip.feed.loader.*;
  5. import org.drip.historical.attribution.*;
  6. import org.drip.numerical.common.FormatUtil;
  7. import org.drip.service.env.EnvManager;
  8. import org.drip.service.product.FundingFuturesAPI;

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

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

  73. /**
  74.  * <i>ER1Attribution</i> demonstrates the Invocation of the Historical PnL Horizon PnL Attribution analysis
  75.  * for the ER1 Series.
  76.  *  
  77.  * <br><br>
  78.  *  <ul>
  79.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/AnalyticsCore.md">Analytics Core Module</a></li>
  80.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  81.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">Sample</a></li>
  82.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/forwardratefuturespnl/README.md">Forward Rate Futures Feed PnL</a></li>
  83.  *  </ul>
  84.  * <br><br>
  85.  *
  86.  * @author Lakshmi Krishnamurthy
  87.  */

  88. public class ER1Attribution {

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

  94.         String strCurrency = "EUR";
  95.         String strPrintLocation = "C:\\DROP\\Daemons\\Transforms\\FundingFuturesCloses\\ER1ClosesReconstitutor.csv";

  96.         CSVGrid csvGrid = CSVParser.StringGrid (
  97.             strPrintLocation,
  98.             true
  99.         );

  100.         JulianDate[] adtSpot = csvGrid.dateArrayAtColumn (0);

  101.         double[] adblForwardRate = csvGrid.doubleArrayAtColumn (2);

  102.         JulianDate[] adtExpiry = csvGrid.dateArrayAtColumn (3);

  103.         List<PositionChangeComponents> lsPCC = FundingFuturesAPI.HorizonChangeAttribution (
  104.             adtSpot,
  105.             adtExpiry,
  106.             adblForwardRate,
  107.             strCurrency
  108.         );

  109.         System.out.println ("FirstDate, SecondDate, Previous DV01, Previous Forward Rate, Spot DV01, Spot Forward Rate, 1D Gross PnL, 1D Market PnL, 1D Roll-down PnL, 1D Accrual PnL, 1D Explained PnL, 1D Unexplianed PnL, Floater Label");

  110.         for (PositionChangeComponents pcc : lsPCC)
  111.             System.out.println (
  112.                 pcc.firstDate() + ", " +
  113.                 pcc.secondDate() + ", " +
  114.                 FormatUtil.FormatDouble (pcc.pmsFirst().r1 ("DV01"), 1, 8, 1.) + ", " +
  115.                 FormatUtil.FormatDouble (pcc.pmsFirst().r1 ("ForwardRate"), 1, 8, 100.) + ", " +
  116.                 FormatUtil.FormatDouble (pcc.pmsSecond().r1 ("DV01"), 1, 8, 1.) + ", " +
  117.                 FormatUtil.FormatDouble (pcc.pmsSecond().r1 ("ForwardRate"), 1, 8, 100.) + ", " +
  118.                 FormatUtil.FormatDouble (pcc.grossChange(), 1, 8, 10000.) + ", " +
  119.                 FormatUtil.FormatDouble (pcc.marketRealizationChange(), 1, 8, 10000.) + ", " +
  120.                 FormatUtil.FormatDouble (pcc.marketRollDownChange(), 1, 8, 10000.) + ", " +
  121.                 FormatUtil.FormatDouble (pcc.accrualChange(), 1, 8, 10000.) + ", " +
  122.                 FormatUtil.FormatDouble (pcc.explainedChange(), 1, 8, 10000.) + ", " +
  123.                 FormatUtil.FormatDouble (pcc.unexplainedChange(), 1, 8, 10000.) + ", " +
  124.                 pcc.pmsFirst().c1 ("FloaterLabel")
  125.             );

  126.         EnvManager.TerminateEnv();
  127.     }
  128. }