DateConverter

The `DateConverter` class provides utility methods for date manipulation, including calculating pre-start dates based on given start dates and lookback periods.

To avoid errors in date calculations, always use specialized tools like Python's datetime or a custom DateConverter. These handle all the tricky parts of dates, like leap years or month lengths, making your calculations accurate and straightforward.

Method Signature

from finter.modeling import DateConverter

DateConverter.get_pre_start(start, lookback_days, trading_day=False)
  • start (int, str, datetime): The start date. Can be an integer in YYYYMMDD format, a string with 'YYYYMMDD' format, or a datetime object.

  • lookback_days (int): The number of days to look back from the start date.

  • trading_day (bool, optional): If True, only considers trading days. Defaults to False.

Return Value

  • Returns an integer in YYYYMMDD format if the input is an integer or string.

  • Returns a datetime object if the input is a datetime object.

Examples

from datetime import datetime
from finter.modeling import DateConverter

# Example 1: Input as integer
print(DateConverter.get_pre_start(20220101, 5))

# Example 2: Input as string
print(DateConverter.get_pre_start('20220101', 5))

# Example 3: Input as datetime object
print(DateConverter.get_pre_start(datetime(2022, 1, 1), 5))

Last updated