How do you retrieve a day's intraday minute by minute data for a specific stock? I was planning on using this to study outliers.
Thank you.
How do you retrieve a day's intraday minute by minute data for a specific stock? I was planning on using this to study outliers.
Thank you.
https://www.quantopian.com/help#ide-history
Examples would be found using a search like https://www.google.com/search?q="data.history"+site:quantopian.com
Fields are open, high, low, close, volume, and also price. I think there is a subtle difference between close and price. To clarify, when using '1m', close would be the close for each minute.
Basically, making use of the info ...
Last five minutes of prices with a single stock, returns a Series:
prices = data.history(stock, 'price', 5, '1m')
The second price would be prices[1].
Someone might do something like:
prices = data.history(stock, 'price', 5, '1m')
if prices[-3] > prices[-2] > prices[-1] * 1.05: # price drop
order_target(stock, 0) # sell
More commonly the input is a list of stocks rather than a single stock.
Instead of a Series, a list for input returns a Dataframe so index into it using the stock.
prices = data.history(context.portfolio.positions.keys(), 'price', 5, '1m')
for stock in context.portfolio.positions:
price = prices[stock][-2] # price before the current minute, or ...
if prices[stock][-3] > prices[stock][-2] > prices[stock][-1] * 1.05: # price drop
order_target(stock, 0) # sell
If the original were in a list by itself, that would also return a Dataframe instead of a Series. That's useful if starting out with one stock and planning to expand to a list later.
prices = data.history([stock], 'price', 5, '1m')
If the fields are more than just price, as a list, like ['price', 'volume'], then volume for example would be retrieved like this, and also an example for price ...
history_info = data.history(context.portfolio.positions.keys, ['price', 'volume'], 5, '1m')
for stock in context.portfolio.positions:
volumes_series = history_info.volume[stock]
second_latest_volume_value_for_this_stock = volumes_series[-2] # or ...
second_latest_price_value_for_this_stock = history_info.price[stock][-2]
The quick route is to start with some code, click in the margin on a line number to set a breakpoint, run, and try some things at the prompt that appears.
Hello Blue, I tried this code you posted, but data is actually showing all NaN if I am doing it for today. Does it mean that Quantopian does not supply current quotes?