def getLowsFromHistFile(histfile): # Must return Array instance wr = csv.reader(open(histfile,"r"),quotechar='|',quoting=csv.QUOTE_MINIMAL) outArr = SortedArray(0) count = 0 for row in wr : if count > 0 : cur_time = calendar.timegm(time.strptime(row[0],"%Y-%m-%d")) outArr.addRow([cur_time, row[4]]); else : count = count + 1 return outArr
raise MergeOverWriteException() else : highs[ticker].arraydict[key] = recent_prices[ticker][key] start_date = datetime.datetime(2012,10,16,0,0,0,0,UTC()) end_date = datetime.datetime(2012,10,17,0,0,0,0,UTC()) for i in open(TICKERFILE).readlines() : ticker = i.strip() lows[ticker].save("/tmp/"+ticker+"_lows.data"); highs[ticker].save("/tmp/"+ticker+"_highs.data"); print "=========TICKER=",ticker,"=============" ranges = SortedArray(0) mins = SortedArray(0) for cur_days in range(0,2) : #print "cur_days=",cur_days cur_start_time = calendar.timegm((start_date-datetime.timedelta(days=cur_days)).timetuple()) cur_end_time = calendar.timegm((end_date-datetime.timedelta(days=cur_days)).timetuple()) #print "cur_start_time="+str(time.gmtime(cur_start_time))+" cur_end_time="+str(time.gmtime(cur_end_time)) wop_min = window.WindowOperator(lows[ticker]) wop_max = window.WindowOperator(highs[ticker]) cur_price = ( float(wop_min[wop_min.closest_time(cur_end_time)][0]) + float(wop_max[wop_max.closest_time(cur_end_time)][0]) ) / 2 wmin = wop_min.window_min([cur_start_time,cur_end_time]) wmax = wop_max.window_max([cur_start_time,cur_end_time]) #print "Wmin(",cur_start_time,")=",wmin #print "Wmax(",cur_end_time,")=",wmax ranges.addRow([cur_end_time, (wmax - wmin)/cur_price]) mins.addRow([cur_end_time, wmin/cur_price])