DCAct_Act_ISDA.java

  1. package org.drip.analytics.daycount;

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

  81. /**
  82.  * <i>DCAct_Act_ISDA</i> implements the ISDA Act/Act day count convention.
  83.  *
  84.  *  <br><br>
  85.  *  <ul>
  86.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  87.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  88.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/README.md">Date, Cash Flow, and Cash Flow Period Measure Generation Utilities</a></li>
  89.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/daycount/README.md">Day Count Year Fraction Utilities</a></li>
  90.  *  </ul>
  91.  *
  92.  * @author Lakshmi Krishnamurthy
  93.  */

  94. public class DCAct_Act_ISDA implements org.drip.analytics.daycount.DCFCalculator {

  95.     /**
  96.      * Empty DCAct_Act_ISDA constructor
  97.      */

  98.     public DCAct_Act_ISDA()
  99.     {
  100.     }

  101.     @Override public java.lang.String baseCalculationType()
  102.     {
  103.         return "DCAct_Act_ISDA";
  104.     }

  105.     @Override public java.lang.String[] alternateNames()
  106.     {
  107.         return new java.lang.String[] {"Actual/Actual ISDA", "Act/Act ISDA", "US:WIT Act/Act",
  108.             "DCAct_Act_ISDA"};
  109.     }

  110.     @Override public double yearFraction (
  111.         final int iStartDate,
  112.         final int iEndDate,
  113.         final boolean bApplyEOMAdj,
  114.         final ActActDCParams actactParams,
  115.         final java.lang.String strCalendar)
  116.         throws java.lang.Exception
  117.     {
  118.         DateEOMAdjustment dm = DateEOMAdjustment.MakeDEOMA (iStartDate, iEndDate, bApplyEOMAdj);

  119.         if (null == dm)
  120.             throw new java.lang.Exception ("DCAct_Act_ISDA::yearFraction => Cannot create DateEOMAdjustment!");

  121.         return 1. * ((org.drip.analytics.date.DateUtil.DaysRemaining (iStartDate) - dm.anterior()) /
  122.             (org.drip.analytics.date.DateUtil.IsLeapYear (iStartDate) ? 366. : 365.)) +
  123.                 ((org.drip.analytics.date.DateUtil.DaysElapsed (iEndDate) + dm.posterior()) /
  124.                     (org.drip.analytics.date.DateUtil.IsLeapYear (iEndDate) ? 366. : 365.)) +
  125.                         org.drip.analytics.date.DateUtil.Year (iEndDate) -
  126.                             org.drip.analytics.date.DateUtil.Year (iStartDate) - 1;
  127.     }

  128.     @Override public int daysAccrued (
  129.         final int iStartDate,
  130.         final int iEndDate,
  131.         final boolean bApplyEOMAdj,
  132.         final ActActDCParams actactParams,
  133.         final java.lang.String strCalendar)
  134.         throws java.lang.Exception
  135.     {
  136.         DateEOMAdjustment dm = DateEOMAdjustment.MakeDEOMA (iStartDate, iEndDate, bApplyEOMAdj);

  137.         if (null == dm)
  138.             throw new java.lang.Exception ("DCAct_Act_ISDA::daysAccrued => Cannot create DateEOMAdjustment!");

  139.         int iDaysAccrued = 0;

  140.         int iStartYear = org.drip.analytics.date.DateUtil.Year (iStartDate);

  141.         int iEndYear = org.drip.analytics.date.DateUtil.Year (iEndDate);

  142.         if (iEndYear == iStartYear) iDaysAccrued -= 0 == iEndYear % 4 ? 366 : 365;

  143.         for (int iYear = iStartYear + 1; iYear < iEndYear; ++iYear)
  144.             iDaysAccrued += 0 == iYear % 4 ? 366 : 365;

  145.         return iDaysAccrued + org.drip.analytics.date.DateUtil.DaysRemaining (iStartDate) - dm.anterior() +
  146.             org.drip.analytics.date.DateUtil.DaysElapsed (iEndDate) + dm.posterior();
  147.     }
  148. }