Locale.java

  1. package org.drip.analytics.eventday;

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

  82. /**
  83.  * <i>Locale</i> contains the set of regular holidays and the weekend holidays for a location. It also
  84.  * provides the functionality to add custom holidays and weekends.
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  89.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  90.  *      <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>
  91.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/eventday/README.md">Fixed, Variable, and Custom Holiday Creation</a></li>
  92.  *  </ul>
  93.  *
  94.  * @author Lakshmi Krishnamurthy
  95.  */

  96. public class Locale {
  97.     private Weekend _wkend = null;

  98.     private java.util.Set<Base> _setHolidays = new java.util.HashSet<Base>();

  99.     /**
  100.      * Construct an empty LocHolidays instance
  101.      */

  102.     public Locale()
  103.     {
  104.     }

  105.     /**
  106.      * Add the array of weekend days
  107.      *
  108.      * @param aiDays Array of weekend days
  109.      *
  110.      * @return Succeeded (true), failure (false)
  111.      */

  112.     public boolean addWeekend (
  113.         final int[] aiDays)
  114.     {
  115.         try {
  116.             return null != (_wkend = new Weekend (aiDays));
  117.         } catch (java.lang.Exception e) {
  118.             e.printStackTrace();
  119.         }

  120.         return false;
  121.     }

  122.     /**
  123.      * Add the regular SATURDAY/SUNDAY weekend
  124.      *
  125.      * @return Succeeded (true), failure (false)
  126.      */

  127.     public boolean addStandardWeekend()
  128.     {
  129.         _wkend = Weekend.StandardWeekend();

  130.         return true;
  131.     }

  132.     /**
  133.      * Add the given date as a static holiday
  134.      *
  135.      * @param dt Date
  136.      * @param strDescription Description
  137.      *
  138.      * @return Succeeded (true), failure (false)
  139.      */

  140.     public boolean addStaticHoliday (
  141.         final org.drip.analytics.date.JulianDate dt,
  142.         final java.lang.String strDescription)
  143.     {
  144.         if (null == dt) return false;

  145.         try {
  146.             _setHolidays.add (new Static (dt, strDescription));

  147.             return true;
  148.         } catch (java.lang.Exception e) {
  149.             System.out.println (e.getMessage());
  150.         }

  151.         return false;
  152.     }

  153.     /**
  154.      * Add the given string date as a static holiday
  155.      *
  156.      * @param strDate Date string
  157.      * @param strDescription Description
  158.      *
  159.      * @return Succeeded (true), failure (false)
  160.      */

  161.     public boolean addStaticHoliday (
  162.         final java.lang.String strDate,
  163.         final java.lang.String strDescription)
  164.     {
  165.         if (null == strDate || strDate.isEmpty()) return false;

  166.         org.drip.analytics.date.JulianDate dtStaticHoliday =
  167.             org.drip.analytics.date.DateUtil.CreateFromDDMMMYYYY (strDate);

  168.         if (null == dtStaticHoliday) return false;

  169.         return addStaticHoliday (dtStaticHoliday, strDescription);
  170.     }

  171.     /**
  172.      * Add a fixed holiday from the day and month
  173.      *
  174.      * @param iDay Day
  175.      * @param iMonth Month
  176.      * @param strDescription Description
  177.      *
  178.      * @return Succeeded (true), failure (false)
  179.      */

  180.     public boolean addFixedHoliday (
  181.         final int iDay,
  182.         final int iMonth,
  183.         final java.lang.String strDescription)
  184.     {
  185.         _setHolidays.add (new Fixed (iDay, iMonth, _wkend, strDescription));

  186.         return true;
  187.     }

  188.     /**
  189.      * Add a floating holiday from the week in month, the day in week, the month, and whether holidays are
  190.      *      calculated from front/back.
  191.      *
  192.      * @param iWeekInMonth Week in the Month
  193.      * @param iWeekDay Day in the week
  194.      * @param iMonth Month
  195.      * @param bFromFront Holidays are calculated from the start of the month (True)
  196.      * @param strDescription Description
  197.      *
  198.      * @return Succeeded (true), failure (false)
  199.      */

  200.     public boolean addFloatingHoliday (
  201.         final int iWeekInMonth,
  202.         final int iWeekDay,
  203.         final int iMonth,
  204.         final boolean bFromFront,
  205.         final java.lang.String strDescription)
  206.     {
  207.         _setHolidays.add (new Variable (iWeekInMonth, iWeekDay, iMonth, bFromFront, _wkend,
  208.             strDescription));

  209.         return true;
  210.     }

  211.     /**
  212.      * Return the weekend
  213.      *
  214.      * @return Weekend
  215.      */

  216.     public Weekend weekendDays()
  217.     {
  218.         return _wkend;
  219.     }

  220.     /**
  221.      * Return the set of week day holidays
  222.      *
  223.      * @return Set of hoidays
  224.      */

  225.     public java.util.Set<Base> holidays()
  226.     {
  227.         return _setHolidays;
  228.     }
  229. }