Datetime¶
VBT loves flexibility, and so it allows us to construct various datetime-related objects from human-readable strings.
Timestamps¶
Timestamps represent a single point in time, similar to a datetime object in Python's datetime module, but with enhanced functionality for data analysis and manipulation.
vbt.timestamp() # (1)!
vbt.utc_timestamp() # (2)!
vbt.local_timestamp() # (3)!
vbt.timestamp(tz="America/New_York") # (4)!
vbt.timestamp("1 Jul 2020") # (5)!
vbt.timestamp("7 days ago") # (6)!
pd.Timestamp.now()(without timezone)pd.Timestamp.now(tz="utc")(UTC timezone)pd.Timestamp.now(tz="tzlocal()")(local timezone)pd.Timestamp.now(tz="New_York/America")(New York timezone)pd.Timestamp("2020-07-01")pd.Timestamp.now() - pd.Timedelta(days=7)
Timezones¶
Timezones can be used in timestamps, making it a powerful tool for global time-based data analysis.
vbt.timezone() # (1)!
vbt.timezone("utc") # (2)!
vbt.timezone("America/New_York") # (3)!
vbt.timezone("+0500") # (4)!
- Local timezone
- UTC timezone
- New York timezone
- UTC+5 timezone
Timedeltas¶
Timedeltas deal with continuous time spans and precise time differences. They are commonly used for adding or subtracting durations from timestamps, or for measuring the difference between two timestamps.
vbt.timedelta() # (1)!
vbt.timedelta("7 days") # (2)!
vbt.timedelta("weekly")
vbt.timedelta("Y", approximate=True) # (3)!
pd.Timedelta(nanoseconds=1)pd.Timedelta(days=7)- Approximation for a year
Date offsets¶
Date offsets handle calendar-specific offsets (e.g., adding a month, skipping weekends with business days). They are commonly used for calendar-aware adjustments and recurring periods.
vbt.offset("Y") # (1)!
vbt.offset("YE") # (2)!
vbt.offset("weekstart") # (3)!
vbt.offset("monday")
vbt.offset("july") # (4)!
pd.offsets.YearBegin()(= every year begin)pd.offsets.YearEnd()(= every year end)pd.offsets.Week(weekday=0)(= every monday)pd.offsets.YearBegin(month=7)(= every July)