CalendarAPI.java

  1. package org.drip.sample.date;

  2. import java.util.*;

  3. import org.drip.analytics.date.*;
  4. import org.drip.analytics.daycount.Convention;
  5. import org.drip.service.env.EnvManager;

  6. /*
  7.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  8.  */

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

  85. /**
  86.  * <i>CalendarAPI</i> demonstrates Calendar API Functionality.
  87.  *  
  88.  * <br><br>
  89.  *  <ul>
  90.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  91.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  92.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  93.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/date/README.md">Calendar Date Roll Day Count</a></li>
  94.  *  </ul>
  95.  * <br><br>
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class CalendarAPI {

  100.     /**
  101.      * Sample demonstrating the calendar API
  102.      *
  103.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  104.      */

  105.     private static final void CalenderAPISample()
  106.         throws Exception
  107.     {
  108.         /*
  109.          * Get all the holiday locations in CreditAnalytics
  110.          */

  111.         /* Set<String> setLoc = CreditAnalytics.GetHolLocations();

  112.         System.out.println ("Num Hol Locations: " + setLoc.size());

  113.         for (String strLoc : setLoc)
  114.             System.out.println (strLoc); */

  115.         /*
  116.          * Get all the holidays in the year according the calendar set
  117.          */

  118.         /* JulianDate[] adtHols = CreditAnalytics.GetHolsInYear (
  119.             "USD,GBP",
  120.             2011
  121.         );

  122.         System.out.println ("USD,GBP has " + adtHols.length + " hols");

  123.         for (int i = 0; i < adtHols.length; ++i)
  124.             System.out.println (adtHols[i]); */

  125.         /*
  126.          * Get all the week day holidays in the year according the calendar set
  127.          */

  128.         /* JulianDate[] adtWeekDayHols = CreditAnalytics.GetWeekDayHolsInYear (
  129.             "USD,GBP",
  130.             2011
  131.         );

  132.         System.out.println ("USD,GBP has " + adtWeekDayHols.length + " week day hols");

  133.         for (int i = 0; i < adtWeekDayHols.length; ++i)
  134.             System.out.println (adtWeekDayHols[i]); */

  135.         /*
  136.          * Get all the weekend holidays in the year according the calendar set
  137.          */

  138.         /* JulianDate[] adtWeekendHols = CreditAnalytics.GetWeekendHolsInYear (
  139.             "USD,GBP",
  140.             2011
  141.         );

  142.         System.out.println ("USD,GBP has " + adtWeekendHols.length + " weekend hols");

  143.         for (int i = 0; i < adtWeekendHols.length; ++i)
  144.             System.out.println (adtWeekendHols[i]); */

  145.         /*
  146.          * Indicate which days correspond to the weekend for the given calendar set
  147.          */

  148.         /* int[] aiWkendDays = CreditAnalytics.GetWeekendDays ("USD,GBP");

  149.         for (int i = 0; i < aiWkendDays.length; ++i)
  150.             System.out.println (DateUtil.DayChars (aiWkendDays[i]));

  151.         System.out.println ("USD,GBP has " + aiWkendDays.length + " weekend days"); */

  152.         /*
  153.          * Check if the given day is a holiday
  154.          */

  155.         /* boolean bIsHoliday = CreditAnalytics.IsHoliday (
  156.             "USD,GBP",
  157.             DateUtil.CreateFromYMD (
  158.                 2011,
  159.                 12,
  160.                 28
  161.             )
  162.         );

  163.         System.out.println (DateUtil.CreateFromYMD (2011, 12, 28) + " is a USD,GBP holiday? " + bIsHoliday); */

  164.         JulianDate dtToday = DateUtil.Today();

  165.         /*
  166.          * List all the holidays between the specified days according to the calendar set
  167.          */

  168.         List<Integer> lsHols = Convention.HolidaySet
  169.             (dtToday.julian(), dtToday.addYears (1).julian(), "USD,GBP");

  170.         for (int iDate : lsHols)
  171.             System.out.println (new JulianDate (iDate).toOracleDate());
  172.     }

  173.     public static final void main (
  174.         final String astrArgs[])
  175.         throws Exception
  176.     {
  177.         // String strConfig = "c:\\Lakshmi\\BondAnal\\Config.xml";

  178.         String strConfig = "";

  179.         EnvManager.InitEnv (strConfig);

  180.         CalenderAPISample();

  181.         EnvManager.TerminateEnv();
  182.     }
  183. }