Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
percent change of the SPY in a graph (need help)

hey guys,
i need your help. i want to show the daily returns of the SPY in 2 graphs. the first should only show the positive returns with time on the x axis. the other one only the negative ones also with time on the x axis.
i want the graph to show only data in the timeframe from market opening till 12AM.
thanks for your help.
here some extract of my code: (i know there are some problems with my syntax)

pct_change = data['SPY'].pct_change() #need a number for pct_change
def markettype(pct_change):
for num in pct_change:
if pct_change >= 0:
print pct_change #here should be the plotting command
elif pct_change < 0:
print pct_change #here should be the plotting command

return pct_change

3 responses

hey guys,
found a way to deal with this but still want want to have one single line for every day of trade..can you help me here?

daily change in percent of SPY

pct_change = data['SPY'].pct_change().dropna() #.iloc[[0, -1]]
pct_change_positive = pct_change[pct_change >= 0]
pct_change_negative = pct_change[pct_change < 0]
print pct_change_positive
plt.plot(pct_change_positive)
plt.ylabel('Change in Percent')
print pct_change_negative
plt.plot(pct_change_negative)
plt.ylabel('Change in Percent')

Wasn't exactly sure what the goal was but here's a stab at it. See attached notebook.

hey wow this looks good. thanks for your help.
you still got me a little wrong. I glad to extract minute data from 9:30 to 12 every day now. can you help me to show this data for ervery day per minute from 9:30 to 12:00 in an own line but in the same graph?
i know this will be very much information in one plot but is need this information

thanks :)

added:
so i need the data from 9:30 to 12:00 from your notebook before you cut it with the this command plotted in a graph for every day:
prices = prices.loc[(prices.index.time==time_9_31) | (prices.index.time==time_12_00)]

is there a "from this time to this time command" instead of the " | "?(just taking the first and last)