quantopian / alphalens

Performance analysis of predictive (alpha) stock factors
http://quantopian.github.io/alphalens
Apache License 2.0
3.2k stars 1.12k forks source link

function of utils.infer_trading_calendar #333

Closed wuyunhua closed 5 years ago

wuyunhua commented 5 years ago

Problem Description

In utils.infer_trading_calendar function, the variable days_of_the_week seems incorrect? days_of_the_week = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] if 'Sat' and 'Sun' are included, then the weekend will be list in the trade days。

Please provide a minimal, self-contained, and reproducible example:

index_1 = pd.date_range('2019-01-01',periods=15)
index_2 = pd.date_range('2019-01-01', periods=30)
custom_bus_day = infer_trading_calendar(index_1, index_2)
custom_bus_day.calendar.weekmask # array([ True,  True,  True,  True,  True,  True,  True])
custom_bus_day.calendar.holidays # array([], dtype='datetime64[D]')

Versions

luca-s commented 5 years ago

Thanks for reporting this @wuyunhua but the function is working as expected: it infers the calendars based on the dates you passed. Since the dates contain the weekends, then the inferred calendar has weekends too