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 inYYYYMMDD
format, a string with 'YYYYMMDD' format, or adatetime
object.lookback_days
(int): The number of days to look back from the start date.trading_day
(bool, optional): IfTrue
, only considers trading days. Defaults toFalse
.
Return Value
Returns an integer in
YYYYMMDD
format if the input is an integer or string.Returns a
datetime
object if the input is adatetime
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
Was this helpful?