def getDataMatrixFromData(dataname, partname, symbols, tsstart, tsend): pathpre = os.environ.get('QSDATA') + "/Processed" if dataname == "Norgate": pathsub = "/Norgate/Equities" paths = list() paths.append(pathpre + pathsub + "/US_NASDAQ/") paths.append(pathpre + pathsub + "/US_NYSE/") paths.append(pathpre + pathsub + "/US_NYSE Arca/") paths.append(pathpre + pathsub + "/OTC/") paths.append(pathpre + pathsub + "/US_AMEX/") paths.append(pathpre + pathsub + "/Delisted_US_Recent/") paths.append(pathpre + pathsub + "/US_Delisted/") datastr1 = "/StrategyData" datastr2 = "StrategyData" else: raise Exception("unknown dataname " + str(dataname)) data = da.DataAccess(True, paths, datastr1, datastr2, False, symbols, tsstart, tsend) tss = list(data.getTimestampArray()) start_time = tss[0] end_time = tss[-1] dates = [] for ts in tss: dates.append(tu.epoch2date(ts)) vals = data.getMatrixBetweenTS(symbols, partname, start_time, end_time) syms = list(data.getListOfSymbols()) del data return (pandas.DataMatrix(vals, dates, syms))
def getDataMatrixFromData(dataname,partname,symbols,tsstart,tsend): pathpre = os.environ.get('QSDATA') + "/Processed" if dataname == "Norgate": pathsub = "/Norgate/Equities" paths=list() paths.append(pathpre + pathsub + "/US_NASDAQ/") paths.append(pathpre + pathsub + "/US_NYSE/") paths.append(pathpre + pathsub + "/US_NYSE Arca/") paths.append(pathpre + pathsub + "/OTC/") paths.append(pathpre + pathsub + "/US_AMEX/") paths.append(pathpre + pathsub + "/Delisted_US_Recent/") paths.append(pathpre + pathsub + "/US_Delisted/") datastr1 = "/StrategyData" datastr2 = "StrategyData" else: raise Exception("unknown dataname " + str(dataname)) data = da.DataAccess(True, paths, datastr1, datastr2, False, symbols, tsstart, tsend) tss = list(data.getTimestampArray()) start_time = tss[0] end_time = tss[-1] dates = [] for ts in tss: dates.append(tu.epoch2date(ts)) vals = data.getMatrixBetweenTS(symbols,partname, start_time,end_time) syms = list(data.getListOfSymbols()) del data return(pandas.DataMatrix(vals,dates,syms))
tsend = tu.ymd2epoch(2010,1,1) # Get the data from the data store storename = "Norgate" # get data from our daily prices source fieldname = "adj_close" # adj_open, adj_close, adj_high, adj_low, close, volume adjcloses = ts.getTSFromData(storename,fieldname,symbols,tsstart,tsend) # Print out a bit of the data print "The prices are: " print symbols print adjcloses.values # Convert the timestamps to dates for the plot dates = [] for ts in adjcloses.timestamps: dates.append(tu.epoch2date(ts)) # Normalize the prices normdat = adjcloses.values/adjcloses.values[0,:] # Plot the prices plt.clf() for i in range(0,size(normdat[0,:])): plt.plot(dates,normdat[:,i]) plt.legend(symbols) plt.ylabel('Adjusted Close') plt.xlabel('Date') plt.draw() savefig("fig1.pdf", format='pdf')
# Set start and end boundary times. They must be specified in Unix Epoch start_bound = tu.ymd2epoch(2008,1,1) end_bound = tu.ymd2epoch(2010,1,1) # Create the data object. Once the dates are set, this object can not give you # data from outside this range even though it might be present in the hdf file data= da.DataAccess(True, listOfPaths, "/StrategyData", "StrategyData", False, symbols, start_bound, end_bound) # Find the actual first and last timestamps timestamps = data.getTimestampArray() start_time = timestamps[0] end_time = timestamps[-1] print "first timestamp:" + str(tu.epoch2date(start_bound)) + " mapped to " + str(tu.epoch2date(start_time)) print "last timestamp:" + str(tu.epoch2date(end_bound)) + " mapped to " + str(tu.epoch2date(end_time)) # Now get the matrix of data adj_close = data.getMatrixBetweenTS(symbols, "adj_close", start_time, end_time) print "The adjusted closing prices are: " print adj_close # 1D numpy array with the timestamps. A typecast to list will convert this to a list. timestamps = data.getTimestampArray() dates = [] for ts in timestamps: dates.append(tu.epoch2date(ts)) symbols= data.getListOfSymbols()