quantlab.runs.backtest_stats.year_freq#

quantlab.runs.backtest_stats.year_freq(bar_interval, trading_days_per_year, session_minutes_per_day)[source]#

Return one year, in vectorbt’s convention, for bars of bar_interval.

year_freq / bar_interval is the number of bars per year. Intraday bars use trading days times session minutes divided by the bar’s minutes (one-minute bars: 252 x 390). A bar of exactly one day is one trading day, giving trading_days_per_year. A longer bar spans calendar time (a weekly bar is one calendar week whatever the holidays), so bars per year is CALENDAR_DAYS_PER_YEAR divided by the bar’s days, capped at trading_days_per_year. The function is continuous at one day and non-increasing in the interval.

Parameters:
bar_interval

Anything pd.Timedelta accepts, such as "1D", "5min" or a numpy.timedelta64.

trading_days_per_yearint

Trading days in a year of the market.

session_minutes_per_dayint

Length of one trading session in minutes.

Returns:
pd.Timedelta

The year length.

Raises:
ValueError

If bar_interval is not positive.

Examples

>>> year_freq("1D", 252, 390) / pd.Timedelta("1D")
252.0
>>> year_freq("1min", 252, 390) / pd.Timedelta("1min")
98280.0
>>> round(year_freq("7D", 252, 390) / pd.Timedelta("7D"), 2)
52.18