Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How to get the day of week for an item returned from history.

I would like to do stuff based on signals I get from days of week from historical data. So I tried;

dailyHistoryOpen = history(context.DaysBackTest, '1d', 'open_price').dropna(axis = 1)  
for indexDays, row in dailyHistoryOpen.iterrows():  
    weekDay = dailyHistoryOpen.keys()[indexDays].datetime.weekday()

Python promptly ralphed on its shoes.

I tried searching the forum, but my search criteria returns 300+ posts, I read a few with no luck. I know the date is in the data, just don't know how to reference it.

1 response

I think I answered my own question, but if there is a better way, let me know;

dailyHistoryOpen = history(context.DaysBackTest, '1d', 'open_price').dropna(axis = 1)  
for indexDays, row in dailyHistoryOpen.iterrows():  
        currentDay = indexDays.to_datetime()  
        weekday = currentDay.weekday()