Hey all,

I'm just seeking some guidance on how to do this better. I was just doing some basic research to compare Monday's opening and low. The code code returns two lists, one with the returns (Monday's close - open/Monday's open) and a list that's just 1's and 0's to reflect if the return was positive or negate. 

Please take a look as I'm sure there's a better way to do it in pandas but I just don't know how.

#Monday only m_list = [] #results list h_list = [] #hit list (close-low > 0) n=0 #counter variable for t in history.index: if datetime.datetime.weekday(t[1]) == 1: #t[1] is the timestamp in multi index (if timestemp is a Monday) x = history.ix[n]['open']-history.ix[n]['low'] m_list.append((history.ix[n]['open']-history.ix[n]['low'])/history.ix[n]['open']) if x > 0: h_list.append(1) else: h_list.append(0) n += 1 #add to index counter else: n += 1 #add to index counter print("Mean: ", mean(m_list), "Max: ", max(m_list),"Min: ", min(m_list), "Hit Rate: ", sum(h_list)/len(h_list))

 

Author