Esempio n. 1
0
# 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))
Esempio n. 2
0
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()
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')