JulianDate.java

  1. package org.drip.analytics.date;

  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>JulianDate</i> provides a comprehensive representation of Julian date and date manipulation
  84.  * functionality. It exports the following functionality:
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li>
  89.  *          Explicit date construction, as well as date construction from several input string formats/today
  90.  *      </li>
  91.  *      <li>
  92.  *          Date Addition/Adjustment/Elapsed/Difference, add/subtract days/weeks/months/years and tenor codes
  93.  *      </li>
  94.  *      <li>
  95.  *          Leap Year Functionality (number of leap days in the given interval, is the given year a leap year
  96.  *              etc.)
  97.  *      </li>
  98.  *      <li>
  99.  *          Generate the subsequent IMM date (CME IMM date, CDS/Credit ISDA IMM date etc)
  100.  *      </li>
  101.  *      <li>
  102.  *          Year/Month/Day in numbers/characters
  103.  *      </li>
  104.  *      <li>
  105.  *          Days Elapsed/Remaining, is EOM
  106.  *      </li>
  107.  *      <li>
  108.  *          Comparison with the Other, equals/hash-code/comparator
  109.  *      </li>
  110.  *      <li>
  111.  *          Export the date to a variety of date formats (Oracle, Julian, Bloomberg)
  112.  *      </li>
  113.  *      <li>
  114.  *          Serialization/De-serialization to and from Byte Arrays
  115.  *      </li>
  116.  *  </ul>
  117.  *
  118.  * <br><br>
  119.  *
  120.  * The References are:
  121.  *  <ul>
  122.  *      <li>
  123.  *          Fliegel, H. F., and T. C. van Flandern (1968): A Machine Algorithm for Processing Calendar Dates
  124.  *              <i>Communications of the ACM</i> <b>11</b> 657
  125.  *      </li>
  126.  *      <li>
  127.  *          Fenton, D. (2001): Julian to Calendar Date Conversion
  128.  *              http://mathforum.org/library/drmath/view/51907.html
  129.  *      </li>
  130.  *  </ul>
  131.  *
  132.  *  <br><br>
  133.  *  <ul>
  134.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  135.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  136.  *      <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>
  137.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/date/README.md">Date and Time Creation, Manipulation, and Usage</a></li>
  138.  *  </ul>
  139.  *
  140.  * @author Lakshmi Krishnamurthy
  141.  */

  142. public class JulianDate implements java.lang.Comparable<JulianDate> {
  143.     private int _iJulian = java.lang.Integer.MIN_VALUE;

  144.     /**
  145.      * Create JulianDate from an Integer Julian Date Instance
  146.      *
  147.      * @param iJulian Julian Date Integer Instance
  148.      */

  149.     public JulianDate (
  150.         final int iJulian)
  151.     {
  152.         _iJulian = iJulian;
  153.     }

  154.     /**
  155.      * Return the Integer Julian Date
  156.      *
  157.      * @return The Integer Julian Date
  158.      */

  159.     public int julian()
  160.     {
  161.         return _iJulian;
  162.     }

  163.     /**
  164.      * Add the given Number of Days and return a JulianDate Instance
  165.      *
  166.      * @param iDays Number of Days to be added
  167.      *
  168.      * @return The new JulianDate
  169.      */

  170.     public JulianDate addDays (
  171.         final int iDays)
  172.     {
  173.         try {
  174.             return new JulianDate (_iJulian + iDays);
  175.         } catch (java.lang.Exception e) {
  176.             e.printStackTrace();
  177.         }

  178.         return null;
  179.     }

  180.     /**
  181.      * Subtract the given Number of Days and return the JulianDate Instance
  182.      *
  183.      * @param iDays Number of days to be subtracted
  184.      *
  185.      * @return The JulianDate Instance
  186.      */

  187.     public JulianDate subtractDays (
  188.         final int iDays)
  189.     {
  190.         try {
  191.             return new JulianDate (_iJulian - iDays);
  192.         } catch (java.lang.Exception e) {
  193.             e.printStackTrace();
  194.         }

  195.         return null;
  196.     }

  197.     /**
  198.      * Add the given Number of Business Days and return a new JulianDate Instance
  199.      *
  200.      * @param iDays Number of Days to be subtracted
  201.      *
  202.      * @param strCalendarSet String representing the Calendar Set containing the Business Days
  203.      *
  204.      * @return The new JulianDate Instance
  205.      */

  206.     public JulianDate addBusDays (
  207.         final int iDays,
  208.         final java.lang.String strCalendarSet)
  209.     {
  210.         int iNumDaysToAdd = iDays;
  211.         int iAdjusted = _iJulian;

  212.         try {
  213.             while (0 < iNumDaysToAdd--) {
  214.                 ++iAdjusted;

  215.                 while (org.drip.analytics.daycount.Convention.IsHoliday (iAdjusted, strCalendarSet))
  216.                     ++iAdjusted;
  217.             }

  218.             while (org.drip.analytics.daycount.Convention.IsHoliday (iAdjusted, strCalendarSet)) ++iAdjusted;

  219.             return new JulianDate (iAdjusted);
  220.         } catch (java.lang.Exception e) {
  221.             e.printStackTrace();
  222.         }

  223.         return null;
  224.     }

  225.     /**
  226.      * Subtract the given Number of Business Days and return a new JulianDate Instance
  227.      *
  228.      * @param iDays Number of Days to be subtracted
  229.      *
  230.      * @param strCalendarSet String representing the Calendar Set containing the Business Days
  231.      *
  232.      * @return The new JulianDate Instance
  233.      */

  234.     public JulianDate subtractBusDays (
  235.         final int iDays,
  236.         final java.lang.String strCalendarSet)
  237.     {
  238.         int iNumDaysToAdd = iDays;
  239.         int iDateAdjusted = _iJulian;

  240.         try {
  241.             while (0 < iNumDaysToAdd--) {
  242.                 --iDateAdjusted;

  243.                 while (org.drip.analytics.daycount.Convention.IsHoliday (iDateAdjusted, strCalendarSet))
  244.                     --iDateAdjusted;
  245.             }

  246.             while (org.drip.analytics.daycount.Convention.IsHoliday (iDateAdjusted, strCalendarSet))
  247.                 --iDateAdjusted;

  248.             return new JulianDate (iDateAdjusted);
  249.         } catch (java.lang.Exception e) {
  250.             e.printStackTrace();
  251.         }

  252.         return null;
  253.     }

  254.     /**
  255.      * Add the given Number of Years and return a new JulianDate Instance
  256.      *
  257.      * @param iNumYears Number of Years to be added
  258.      *  
  259.      * @return The New JulianDate Instance
  260.      */

  261.     public JulianDate addYears (
  262.         final int iNumYears)
  263.     {
  264.         int iP = _iJulian + 68569;
  265.         int iQ = 4 * iP / 146097;
  266.         int iR = iP - (146097 * iQ + 3) / 4;
  267.         int iS = 4000 * (iR + 1) / 1461001;
  268.         int iT = iR - (1461 * iS / 4) + 31;
  269.         int iU = 80 * iT / 2447;
  270.         int iV = iU / 11;
  271.         int iY = 100 * (iQ - 49) + iS + iV;
  272.         int iM = iU + 2 - 12 * iV;
  273.         int iD = iT - (2447 * iU / 80);

  274.         try {
  275.             return org.drip.analytics.date.DateUtil.CreateFromYMD (iY + iNumYears, iM, iD);
  276.         } catch (java.lang.Exception e) {
  277.             e.printStackTrace();
  278.         }

  279.         return null;
  280.     }

  281.     /**
  282.      * Add the given Number of Months and return a New JulianDate Instance
  283.      *
  284.      * @param iNumMonths Number of Months to be added
  285.      *
  286.      * @return The new JulianDate Instance
  287.      */

  288.     public JulianDate addMonths (
  289.         final int iNumMonths)
  290.     {
  291.         int iP = _iJulian + 68569;
  292.         int iQ = 4 * iP / 146097;
  293.         int iR = iP - (146097 * iQ + 3) / 4;
  294.         int iS = 4000 * (iR + 1) / 1461001;
  295.         int iT = iR - (1461 * iS / 4) + 31;
  296.         int iU = 80 * iT / 2447;
  297.         int iV = iU / 11;
  298.         int iYear = 100 * (iQ - 49) + iS + iV;
  299.         int iMonth = iU + 2 - 12 * iV + iNumMonths;
  300.         int iDate = iT - (2447 * iU / 80);

  301.         while (12 < iMonth) {
  302.             ++iYear;
  303.             iMonth -= 12;
  304.         }

  305.         while (0 >= iMonth) {
  306.             --iYear;
  307.             iMonth += 12;
  308.         }

  309.         try {
  310.             int iDaysInMonth = org.drip.analytics.date.DateUtil.DaysInMonth (iMonth, iYear);

  311.             while (iDate > iDaysInMonth)
  312.                 --iDate;

  313.             return org.drip.analytics.date.DateUtil.CreateFromYMD (iYear, iMonth, iDate);
  314.         } catch (java.lang.Exception e) {
  315.             e.printStackTrace();
  316.         }

  317.         return null;
  318.     }

  319.     /**
  320.      * Generate the First Rates Futures IMM Date from this JulianDate
  321.      *
  322.      * @param iNumRollMonths Number of Months to Roll
  323.      *
  324.      * @return The IMM JulianDate Instance
  325.      */

  326.     public JulianDate nextRatesFuturesIMM (
  327.         final int iNumRollMonths)
  328.     {
  329.         int iP = _iJulian + 68569;
  330.         int iQ = 4 * iP / 146097;
  331.         int iR = iP - (146097 * iQ + 3) / 4;
  332.         int iS = 4000 * (iR + 1) / 1461001;
  333.         int iT = iR - (1461 * iS / 4) + 31;
  334.         int iU = 80 * iT / 2447;
  335.         int iV = iU / 11;
  336.         int iYear = 100 * (iQ - 49) + iS + iV;
  337.         int iMonth = iU + 2 - 12 * iV;
  338.         int iDate = iT - (2447 * iU / 80);

  339.         if (15 <= iDate) {
  340.             if (12 < ++iMonth) {
  341.                 ++iYear;
  342.                 iMonth -= 12;
  343.             }
  344.         }

  345.         while (0 != iMonth % iNumRollMonths) ++iMonth;

  346.         try {
  347.             return org.drip.analytics.date.DateUtil.CreateFromYMD (iYear, iMonth, 15);
  348.         } catch (java.lang.Exception e) {
  349.             e.printStackTrace();
  350.         }

  351.         return null;
  352.     }

  353.     /**
  354.      * Generate the First Bond Futures IMM Date from this JulianDate according to the specified Calendar
  355.      *
  356.      * @param iNumRollMonths Number of Months to Roll
  357.      * @param strCalendar Holiday Calendar
  358.      *
  359.      * @return The IMM JulianDate Instance
  360.      */

  361.     public JulianDate nextBondFuturesIMM (
  362.         final int iNumRollMonths,
  363.         final java.lang.String strCalendar)
  364.     {
  365.         int iP = _iJulian + 68569;
  366.         int iQ = 4 * iP / 146097;
  367.         int iR = iP - (146097 * iQ + 3) / 4;
  368.         int iS = 4000 * (iR + 1) / 1461001;
  369.         int iT = iR - (1461 * iS / 4) + 31;
  370.         int iU = 80 * iT / 2447;
  371.         int iV = iU / 11;
  372.         int iYear = 100 * (iQ - 49) + iS + iV;
  373.         int iMonth = iU + 2 - 12 * iV;

  374.         while (0 != iMonth % iNumRollMonths) ++iMonth;

  375.         try {
  376.             return org.drip.analytics.date.DateUtil.CreateFromYMD (iYear, iMonth,
  377.                 org.drip.analytics.date.DateUtil.DaysInMonth (iMonth, iYear));

  378.             /* return org.drip.analytics.date.DateUtil.CreateFromYMD (iYear, iMonth,
  379.                 org.drip.analytics.date.DateUtil.DaysInMonth (iMonth, iYear)).subtractBusDays (8,
  380.                     strCalendar); */
  381.         } catch (java.lang.Exception e) {
  382.             e.printStackTrace();
  383.         }

  384.         return null;
  385.     }

  386.     /**
  387.      * Generate the First Credit IMM roll date from this JulianDate
  388.      *
  389.      * @param iNumRollMonths Number of Months to Roll
  390.      *
  391.      * @return The IMM JulianDate Instance
  392.      */

  393.     public JulianDate nextCreditIMM (
  394.         final int iNumRollMonths)
  395.     {
  396.         int iP = _iJulian + 68569;
  397.         int iQ = 4 * iP / 146097;
  398.         int iR = iP - (146097 * iQ + 3) / 4;
  399.         int iS = 4000 * (iR + 1) / 1461001;
  400.         int iT = iR - (1461 * iS / 4) + 31;
  401.         int iU = 80 * iT / 2447;
  402.         int iV = iU / 11;
  403.         int iYear = 100 * (iQ - 49) + iS + iV;
  404.         int iMonth = iU + 2 - 12 * iV;
  405.         int iDate = iT - (2447 * iU / 80);

  406.         if (20 <= iDate) {
  407.             if (12 < ++iMonth) {
  408.                 ++iYear;
  409.                 iMonth -= 12;
  410.             }
  411.         }

  412.         while (0 != iMonth % iNumRollMonths) ++iMonth;

  413.         try {
  414.             return org.drip.analytics.date.DateUtil.CreateFromYMD (iYear, iMonth, 20);
  415.         } catch (java.lang.Exception e) {
  416.             e.printStackTrace();
  417.         }

  418.         return null;
  419.     }

  420.     /**
  421.      * Add the tenor to the JulianDate to create a new date
  422.      *
  423.      * @param strTenorIn String representing the Input Tenor to add
  424.      *
  425.      * @return The new JulianDate
  426.      */

  427.     public JulianDate addTenor (
  428.         final java.lang.String strTenorIn)
  429.     {
  430.         if (null == strTenorIn || strTenorIn.isEmpty()) return null;

  431.         java.lang.String strTenor = "ON".equalsIgnoreCase (strTenorIn) ? "1D" : strTenorIn;

  432.         int iNumChar = strTenor.length();

  433.         char chTenor = strTenor.charAt (iNumChar - 1);

  434.         int iTimeUnit = -1;

  435.         try {
  436.             iTimeUnit = java.lang.Integer.parseInt (strTenor.substring (0, iNumChar - 1));
  437.         } catch (java.lang.Exception e) {
  438.             System.out.println ("Bad time unit " + iTimeUnit + " in tenor " + strTenor);

  439.             return null;
  440.         }

  441.         if ('d' == chTenor || 'D' == chTenor) return addDays (iTimeUnit);

  442.         if ('w' == chTenor || 'W' == chTenor) return addDays (iTimeUnit * 7);

  443.         if ('l' == chTenor || 'L' == chTenor) return addDays (iTimeUnit * 28);

  444.         if ('m' == chTenor || 'M' == chTenor) return addMonths (iTimeUnit);

  445.         if ('y' == chTenor || 'Y' == chTenor) return addYears (iTimeUnit);

  446.         System.out.println ("Unknown tenor format " + strTenor);

  447.         return null;
  448.     }

  449.     /**
  450.      * Add the Tenor to the JulianDate and Adjust it to create a new Instance
  451.      *
  452.      * @param strTenor The Tenor
  453.      * @param strCalendarSet The Holiday Calendar Set
  454.      *
  455.      * @return The new JulianDate Instance
  456.      */

  457.     public JulianDate addTenorAndAdjust (
  458.         final java.lang.String strTenor,
  459.         final java.lang.String strCalendarSet)
  460.     {
  461.         JulianDate dtNew = addTenor (strTenor);

  462.         if (null == dtNew) return null;

  463.         try {
  464.             return new JulianDate (org.drip.analytics.daycount.Convention.RollDate (dtNew.julian(),
  465.                 org.drip.analytics.daycount.Convention.DATE_ROLL_FOLLOWING, strCalendarSet, 1));
  466.         } catch (java.lang.Exception e) {
  467.             e.printStackTrace();
  468.         }

  469.         return null;
  470.     }

  471.     /**
  472.      * Subtract the tenor to the JulianDate to create a new date
  473.      *
  474.      * @param strTenorIn String representing the tenor to add
  475.      *
  476.      * @return The new JulianDate
  477.      */

  478.     public JulianDate subtractTenor (
  479.         final java.lang.String strTenorIn)
  480.     {
  481.         if (null == strTenorIn || strTenorIn.isEmpty()) return null;

  482.         java.lang.String strTenor = "ON".equalsIgnoreCase (strTenorIn) ? "1D" : strTenorIn;

  483.         int iNumChar = strTenor.length();

  484.         char chTenor = strTenor.charAt (iNumChar - 1);

  485.         int iTimeUnit = -1;

  486.         try {
  487.             iTimeUnit = java.lang.Integer.parseInt (strTenor.substring (0, iNumChar - 1));
  488.         } catch (java.lang.Exception e) {
  489.             System.out.println ("Bad time unit " + iTimeUnit + " in tenor " + strTenor);

  490.             return null;
  491.         }

  492.         if ('d' == chTenor || 'D' == chTenor) return addDays (-iTimeUnit);

  493.         if ('w' == chTenor || 'W' == chTenor) return addDays (-iTimeUnit * 7);

  494.         if ('l' == chTenor || 'L' == chTenor) return addDays (-iTimeUnit * 28);

  495.         if ('m' == chTenor || 'M' == chTenor) return addMonths (-iTimeUnit);

  496.         if ('y' == chTenor || 'Y' == chTenor) return addYears (-iTimeUnit);

  497.         return null;
  498.     }

  499.     /**
  500.      * Subtract the tenor to the JulianDate to create a new business date
  501.      *
  502.      * @param strTenor The Tenor
  503.      * @param strCalendarSet The Holiday Calendar Set
  504.      *
  505.      * @return The new JulianDate
  506.      */

  507.     public JulianDate subtractTenorAndAdjust (
  508.         final java.lang.String strTenor,
  509.         final java.lang.String strCalendarSet)
  510.     {
  511.         JulianDate dtNew = subtractTenor (strTenor);

  512.         if (null == dtNew) return null;

  513.         try {
  514.             return new JulianDate (org.drip.analytics.daycount.Convention.RollDate (dtNew.julian(),
  515.                 org.drip.analytics.daycount.Convention.DATE_ROLL_FOLLOWING, strCalendarSet, 1));
  516.         } catch (java.lang.Exception e) {
  517.             e.printStackTrace();
  518.         }

  519.         return null;
  520.     }

  521.     /**
  522.      * Difference in Days between the Current and the Input Dates
  523.      *
  524.      * @param dt Input Date
  525.      *
  526.      * @return The Difference
  527.      *
  528.      * @throws java.lang.Exception Thrown if Input Date is Invalid
  529.      */

  530.     public int daysDiff (
  531.         final JulianDate dt)
  532.         throws java.lang.Exception
  533.     {
  534.         if (null == dt) throw new java.lang.Exception ("JulianDate::daysDiff => Invalid Input!");

  535.         return _iJulian - dt.julian();
  536.     }

  537.     /**
  538.      * Return a Trigram Representation of the Date
  539.      *
  540.      * @return String representing the Trigram Representation of Date
  541.      */

  542.     public java.lang.String toOracleDate()
  543.     {
  544.         try {
  545.             return DateUtil.Date (_iJulian) + "-" + org.drip.analytics.date.DateUtil.MonthTrigram
  546.                 (org.drip.analytics.date.DateUtil.Month (_iJulian)) + "-" +
  547.                     org.drip.analytics.date.DateUtil.Year (_iJulian);
  548.         } catch (java.lang.Exception e) {
  549.             e.printStackTrace();
  550.         }

  551.         return null;
  552.     }

  553.     /**
  554.      * Return a Representation of Date as YYYYMMDD
  555.      *
  556.      * @param strDelimIn Field Delimiter
  557.      *
  558.      * @return String of the YYYYMMDD Representation of Date
  559.      */

  560.     public java.lang.String toYYYYMMDD (
  561.         final java.lang.String strDelimIn)
  562.     {
  563.         java.lang.String strDelim = null == strDelimIn ? "" : strDelimIn;

  564.         try {
  565.             return org.drip.numerical.common.FormatUtil.FormatDouble (DateUtil.Year (_iJulian), 4, 0, 1.) +
  566.                 strDelim + org.drip.numerical.common.FormatUtil.FormatDouble
  567.                     (org.drip.analytics.date.DateUtil.Month (_iJulian), 2, 0, 1.) + strDelim +
  568.                         org.drip.numerical.common.FormatUtil.FormatDouble (DateUtil.Date (_iJulian), 2, 0, 1.);
  569.         } catch (java.lang.Exception e) {
  570.             e.printStackTrace();
  571.         }

  572.         return null;
  573.     }

  574.     @Override public boolean equals (
  575.         final java.lang.Object o)
  576.     {
  577.         if (!(o instanceof JulianDate)) return false;

  578.         return _iJulian == ((JulianDate) o)._iJulian;
  579.     }

  580.     @Override public int hashCode()
  581.     {
  582.         long lBits = java.lang.Double.doubleToLongBits (_iJulian);

  583.         return (int) (lBits ^ (lBits >>> 32));
  584.     }

  585.     @Override public java.lang.String toString()
  586.     {
  587.         return org.drip.analytics.date.DateUtil.DDMMMYYYY (_iJulian);
  588.     }

  589.     @Override public int compareTo (
  590.         final JulianDate dtOther)
  591.     {
  592.         if (_iJulian > dtOther._iJulian) return 1;

  593.         if (_iJulian < dtOther._iJulian) return -1;

  594.         return 0;
  595.     }
  596. }