Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
#get_pricing# at a specific time of the day every day?

Hi all,

I would like to fetch the price of the stock every day at the same time of the day.
I have tried:

data = get_pricing('MSFT', start_date='2012-1-5 15:40:00', end_date='2015-6-1 15:40', fields='price', frequency='daily')

But the data I get is only the every day closing price.
Is it possible to get a stock price at a specific time of the day every trading day with get_pricing?

Many thanks in advance,
Philippe

2 responses

Yes, one can get pricing for specific minutes of each day. Start by using the 'get_pricing' method but specify frequency='minute'. That get's minute pricing instead of end of day pricing. Next, change the datetime index from the default UTC to Eastern Time. This accounts for all the daylight saving time changes. Finally, use the '.between_time' method to select only certain times or ranges of times. In the following example, get the price for MSFT at time 15:40 every day.

prices = get_pricing(['MSFT'], start_date="2012-1-5", end_date="2015-6-1", fields='price', frequency='minute')  
prices_et = prices.tz_convert('US/Eastern')  
prices_15_40 = prices_et.between_time('15:40','15:40')

One could also use the basic .loc method but the 'between_time' method is simple.

See attached notebook. Good luck.

Great answer in extremely short time!

Thank you very much Dan!!