Class JulianDate

java.lang.Object
org.drip.analytics.date.JulianDate
All Implemented Interfaces:
java.lang.Comparable<JulianDate>

public class JulianDate
extends java.lang.Object
implements java.lang.Comparable<JulianDate>
JulianDate provides a comprehensive representation of Julian date and date manipulation functionality. It exports the following functionality:

  • Explicit date construction, as well as date construction from several input string formats/today
  • Date Addition/Adjustment/Elapsed/Difference, add/subtract days/weeks/months/years and tenor codes
  • Leap Year Functionality (number of leap days in the given interval, is the given year a leap year etc.)
  • Generate the subsequent IMM date (CME IMM date, CDS/Credit ISDA IMM date etc)
  • Year/Month/Day in numbers/characters
  • Days Elapsed/Remaining, is EOM
  • Comparison with the Other, equals/hash-code/comparator
  • Export the date to a variety of date formats (Oracle, Julian, Bloomberg)
  • Serialization/De-serialization to and from Byte Arrays


The References are:
  • Fliegel, H. F., and T. C. van Flandern (1968): A Machine Algorithm for Processing Calendar Dates Communications of the ACM 11 657
  • Fenton, D. (2001): Julian to Calendar Date Conversion http://mathforum.org/library/drmath/view/51907.html


Author:
Lakshmi Krishnamurthy
  • Constructor Summary

    Constructors
    Constructor Description
    JulianDate​(int iJulian)
    Create JulianDate from an Integer Julian Date Instance
  • Method Summary

    Modifier and Type Method Description
    JulianDate addBusDays​(int iDays, java.lang.String strCalendarSet)
    Add the given Number of Business Days and return a new JulianDate Instance
    JulianDate addDays​(int iDays)
    Add the given Number of Days and return a JulianDate Instance
    JulianDate addMonths​(int iNumMonths)
    Add the given Number of Months and return a New JulianDate Instance
    JulianDate addTenor​(java.lang.String strTenorIn)
    Add the tenor to the JulianDate to create a new date
    JulianDate addTenorAndAdjust​(java.lang.String strTenor, java.lang.String strCalendarSet)
    Add the Tenor to the JulianDate and Adjust it to create a new Instance
    JulianDate addYears​(int iNumYears)
    Add the given Number of Years and return a new JulianDate Instance
    int compareTo​(JulianDate dtOther)  
    int daysDiff​(JulianDate dt)
    Difference in Days between the Current and the Input Dates
    boolean equals​(java.lang.Object o)  
    int hashCode()  
    int julian()
    Return the Integer Julian Date
    JulianDate nextBondFuturesIMM​(int iNumRollMonths, java.lang.String strCalendar)
    Generate the First Bond Futures IMM Date from this JulianDate according to the specified Calendar
    JulianDate nextCreditIMM​(int iNumRollMonths)
    Generate the First Credit IMM roll date from this JulianDate
    JulianDate nextRatesFuturesIMM​(int iNumRollMonths)
    Generate the First Rates Futures IMM Date from this JulianDate
    JulianDate subtractBusDays​(int iDays, java.lang.String strCalendarSet)
    Subtract the given Number of Business Days and return a new JulianDate Instance
    JulianDate subtractDays​(int iDays)
    Subtract the given Number of Days and return the JulianDate Instance
    JulianDate subtractTenor​(java.lang.String strTenorIn)
    Subtract the tenor to the JulianDate to create a new date
    JulianDate subtractTenorAndAdjust​(java.lang.String strTenor, java.lang.String strCalendarSet)
    Subtract the tenor to the JulianDate to create a new business date
    java.lang.String toOracleDate()
    Return a Trigram Representation of the Date
    java.lang.String toString()  
    java.lang.String toYYYYMMDD​(java.lang.String strDelimIn)
    Return a Representation of Date as YYYYMMDD

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JulianDate

      public JulianDate​(int iJulian)
      Create JulianDate from an Integer Julian Date Instance
      Parameters:
      iJulian - Julian Date Integer Instance
  • Method Details

    • julian

      public int julian()
      Return the Integer Julian Date
      Returns:
      The Integer Julian Date
    • addDays

      public JulianDate addDays​(int iDays)
      Add the given Number of Days and return a JulianDate Instance
      Parameters:
      iDays - Number of Days to be added
      Returns:
      The new JulianDate
    • subtractDays

      public JulianDate subtractDays​(int iDays)
      Subtract the given Number of Days and return the JulianDate Instance
      Parameters:
      iDays - Number of days to be subtracted
      Returns:
      The JulianDate Instance
    • addBusDays

      public JulianDate addBusDays​(int iDays, java.lang.String strCalendarSet)
      Add the given Number of Business Days and return a new JulianDate Instance
      Parameters:
      iDays - Number of Days to be subtracted
      strCalendarSet - String representing the Calendar Set containing the Business Days
      Returns:
      The new JulianDate Instance
    • subtractBusDays

      public JulianDate subtractBusDays​(int iDays, java.lang.String strCalendarSet)
      Subtract the given Number of Business Days and return a new JulianDate Instance
      Parameters:
      iDays - Number of Days to be subtracted
      strCalendarSet - String representing the Calendar Set containing the Business Days
      Returns:
      The new JulianDate Instance
    • addYears

      public JulianDate addYears​(int iNumYears)
      Add the given Number of Years and return a new JulianDate Instance
      Parameters:
      iNumYears - Number of Years to be added
      Returns:
      The New JulianDate Instance
    • addMonths

      public JulianDate addMonths​(int iNumMonths)
      Add the given Number of Months and return a New JulianDate Instance
      Parameters:
      iNumMonths - Number of Months to be added
      Returns:
      The new JulianDate Instance
    • nextRatesFuturesIMM

      public JulianDate nextRatesFuturesIMM​(int iNumRollMonths)
      Generate the First Rates Futures IMM Date from this JulianDate
      Parameters:
      iNumRollMonths - Number of Months to Roll
      Returns:
      The IMM JulianDate Instance
    • nextBondFuturesIMM

      public JulianDate nextBondFuturesIMM​(int iNumRollMonths, java.lang.String strCalendar)
      Generate the First Bond Futures IMM Date from this JulianDate according to the specified Calendar
      Parameters:
      iNumRollMonths - Number of Months to Roll
      strCalendar - Holiday Calendar
      Returns:
      The IMM JulianDate Instance
    • nextCreditIMM

      public JulianDate nextCreditIMM​(int iNumRollMonths)
      Generate the First Credit IMM roll date from this JulianDate
      Parameters:
      iNumRollMonths - Number of Months to Roll
      Returns:
      The IMM JulianDate Instance
    • addTenor

      public JulianDate addTenor​(java.lang.String strTenorIn)
      Add the tenor to the JulianDate to create a new date
      Parameters:
      strTenorIn - String representing the Input Tenor to add
      Returns:
      The new JulianDate
    • addTenorAndAdjust

      public JulianDate addTenorAndAdjust​(java.lang.String strTenor, java.lang.String strCalendarSet)
      Add the Tenor to the JulianDate and Adjust it to create a new Instance
      Parameters:
      strTenor - The Tenor
      strCalendarSet - The Holiday Calendar Set
      Returns:
      The new JulianDate Instance
    • subtractTenor

      public JulianDate subtractTenor​(java.lang.String strTenorIn)
      Subtract the tenor to the JulianDate to create a new date
      Parameters:
      strTenorIn - String representing the tenor to add
      Returns:
      The new JulianDate
    • subtractTenorAndAdjust

      public JulianDate subtractTenorAndAdjust​(java.lang.String strTenor, java.lang.String strCalendarSet)
      Subtract the tenor to the JulianDate to create a new business date
      Parameters:
      strTenor - The Tenor
      strCalendarSet - The Holiday Calendar Set
      Returns:
      The new JulianDate
    • daysDiff

      public int daysDiff​(JulianDate dt) throws java.lang.Exception
      Difference in Days between the Current and the Input Dates
      Parameters:
      dt - Input Date
      Returns:
      The Difference
      Throws:
      java.lang.Exception - Thrown if Input Date is Invalid
    • toOracleDate

      public java.lang.String toOracleDate()
      Return a Trigram Representation of the Date
      Returns:
      String representing the Trigram Representation of Date
    • toYYYYMMDD

      public java.lang.String toYYYYMMDD​(java.lang.String strDelimIn)
      Return a Representation of Date as YYYYMMDD
      Parameters:
      strDelimIn - Field Delimiter
      Returns:
      String of the YYYYMMDD Representation of Date
    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • compareTo

      public int compareTo​(JulianDate dtOther)
      Specified by:
      compareTo in interface java.lang.Comparable<JulianDate>