def RawData(self): asset = self.Asset() base = self.Base() horizon = self.Horizon() period = str(self.Period()) flag = self.Flag() cacheRetrieved = False commondates = [] if (horizon > maxHist): raise ValueError('horizon too large') if (horizon<maxHist): #print 'Trying to create from internal cache...' #logx.Write('Trying to create series from internal cache...') maxTS = acTechSeries(asset,base,maxHist,period, flag) securityO = TimeSeries(dates = maxTS.securityO().Dates()[-horizon:], values = maxTS.securityO().Values()[-horizon:]) securityH = TimeSeries(dates = maxTS.securityH().Dates()[-horizon:], values = maxTS.securityH().Values()[-horizon:]) securityL = TimeSeries(dates = maxTS.securityL().Dates()[-horizon:], values = maxTS.securityL().Values()[-horizon:]) securityC = TimeSeries(dates = maxTS.securityC().Dates()[-horizon:], values = maxTS.securityC().Values()[-horizon:]) cacheRetrieved = True else: if (period == 'W'): # At this point, maxHist for 'W' period is not there #print 'Creating daily series from internal cache to generate weekly series...' maxTS = acTechSeries(asset,base,maxHist,'D',flag) #This MUST be loaded up in the startup securityC = maxTS.securityC() securityH = maxTS.securityH() securityL = maxTS.securityL() securityO = maxTS.securityO() else: #print 'Creating daily series from spotTS instead of dicoTS' #logx.Write('Creating from scratch ; '+str(horizon)+','+str(maxHist)) # Retrieving any data for the very first time below fileReader = Filereader() if (self.Flag()) == 'True': securityO, securityH, securityL, securityC = fileReader.createTStxt(asset=asset,base=base,priceflag='All') elif self.Flag() == 'Pickle': securityO, securityH, securityL, securityC = fileReader.createTSpickle(asset=asset,base=base) #print 'received timeserie', datetime.datetime.today() else: if (base != ''): #Assuming an FX security from fxstdtimeserie import spotTS securityC, securityH, securityL, securityO = spotTS(asset, base, horizon, ['dqpp_close','dqpp_high','dqpp_low','dqpp_open']) else: #non FX security securityC, securityH, securityL, securityO = acTS(asset, horizon) #Filter dates to include only rows that have all -- O,H,L and C if (len(commondates) == 0): #If no filtering was done, get from what is existing commondates =[ConvertDate(date) for date in securityC.Dates()] if ((period == 'W') and not(cacheRetrieved)): #Convert daily data to weekly data mdates = [] cvalues = [] ovalues = [] hvalues = [] lvalues = [] #Find the first monday for nextDate in commondates: if (days.DayOfWeek(nextDate) == 'monday'): break while nextDate <= commondates[-1]: # MZ : if thing it is possible for this to have a week from monday to monday because of the way the last day is rolled back startDate = nextDate indStart = '' indEnd = '' for k in range(5):#(0,7): try: indStart = commondates.index(nextDate) break except: nextDate = days.NextWeekDay(nextDate) #nextDate+datetime.timedelta(1) endDate = startDate+datetime.timedelta(5) nextDate = startDate+datetime.timedelta(7) if (indStart == ''): continue for k in range(0,7): try: indEnd = commondates.index(endDate) break except: endDate = endDate-datetime.timedelta(1) # MZ : see comment above if (indEnd == ''): continue mdates.append(endDate) ovalues.append(securityO.Values()[indStart]) minVal = min(securityL.Values()[indStart:(indEnd+1)]) lvalues.append(minVal) maxVal = max(securityH.Values()[indStart:(indEnd+1)]) hvalues.append(maxVal) cvalues.append(securityC.Values()[indEnd]) securityO = TimeSeries(dates = mdates, values = ovalues) securityH = TimeSeries(dates =mdates, values = hvalues) securityL = TimeSeries(dates =mdates, values = lvalues) securityC = TimeSeries(dates = mdates, values = cvalues) return [securityO, securityH, securityL, securityC]