Day of the week
Best Answers
-
ptunney Posts: 246
from cloudquant.interfaces import Strategy from datetime import datetime from cloudquant.util import dt_from_muts #0 = Monday #4 = Friday class Day_Of_Week(Strategy): @classmethod def is_symbol_qualified(cls, symbol, md, service, account): if symbol=="SPY": day = dt_from_muts(service.system_time).weekday() print day return False
-
ptunney Posts: 246
from cloudquant.interfaces import Strategy import datetime import calendar from cloudquant.util import dt_from_muts class Day_Of_Week(Strategy): @classmethod def is_symbol_qualified(cls, symbol, md, service, account): if symbol=="SPY": bar_yest = md.bar.daily(start=-5).timestamp[-1] my_day = dt_from_muts(bar_yest).weekday() print my_day year = int(service.time_to_string(bar_yest,format='%Y')) month = int(service.time_to_string(bar_yest,format='%m')) day = int(service.time_to_string(bar_yest,format='%d')) print year,month,day yest_day_num = calendar.weekday(year,month,day) # 0 = Monday print "Yesterday was day number ",yest_day_num my_day = calendar.day_name[yest_day_num] print "Yesterday was a",my_day my_weekday = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"] my_day = my_weekday[yest_day_num] print "Yesterday was a",my_day return False