Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
how to get daily high and minute the high occurred in?

Hi Everyone
I looked through the posts for daily high and lows and could not find one that logged the daily high along with the minute in which that high occurred.
Has anyone written the code for this already? If yes and you can share it that would be awesome.
I am testing intraday bracket orders and need to know in what minute the high occurred.
Much appreciate and a pleasant evening
Savio

6 responses

Here is one approach when working in a notebook. It works similarly in an algo. First get the highs then use the 'idxmax' method to return a series of datetimes representing the first occurance of the high (there could be more than one time with this value).

highs = get_pricing(['SPY', 'IBM'], start_date="2016-01-05", end_date="2016-01-05", fields='high', frequency='minute')  
high_times = highs.tz_convert('US/Eastern').idxmax()

Use the 'tz_convert method to make sure all the times are normalized for daylight saving time.

See notebook.

Dan, thank you for your help, and for taking the time to do so, time and again.
Much appreciate and a pleasant evening
Savio

@Savio

Always glad to help if I can. This may not be exactly the solution you asked for (but it's straightforward). If you really want the minutes or want all the highs or the last high that can probably be done too.

Hello Dan
Thank you. You are right - it is straightforward and works for spot checking what I am testing.
Thanks again and a pleasant day
Savio

This got me thinking about when stocks reach their daily highs. Attached is a notebook with a histogram of 100 random stocks on a random day. Not a real scientific sample but it looks like most stocks reach their high in the first and last 15 minutes of the day.

Hello Dan to your point about the close I have found (in my universe of about 120 US stocks and since 1996) that if a stock takes a beating during the day it generally picks up at the close so, if a losing stock needs to be dumped, the best time to do so is at the close, in those cases where it has not fallen straight through the stop loss and liquidity has dried up. Interesting that there is a pick up at the open as well - my theory was that the HFT guys beat the crap out of the market in the first few minutes of trading - so much for that theory. Thanks for sharing these interesting insights. Have a nice evening Savio