Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Returning the low price of the day for the current trading minute???

I've been working a while to place an order if the stock price is within 5 minutes of the day's low and can't get anything to work. Quantopian support was helpful, but I'm too amateur to morph their advice into code.

This code I initially made gives me the low price of the day and will return it minutely under handle_data: day_low = data.history(sid(24), 'low', 1, '1d')

My problem is that I am trying to compare current_price to day_low, i.e.: if current_price <= day_low: order_target_percent... or, a series vs. a float, which can't be done.

Here's the advice I got from Quantopian support:
"the problem is that day_low is coming from a data.history call, and data.history() returns a series. current_price is a float. You can't make a logical comparison between a series and a float. What you want to do is to get a specific value out of the series, so I think you want to use day_low[0].

There isn't a native Quantopian API call that will tell you when the day's low price (so far) was set. You're going to need to write some business logic to keep track of it yourself. What I'd do is record the opening price in the first minute (which, of course, is the low so far), and then test every minute if the new price is lower. If it's lower I'd record the lower price and the timestamp. Then, when you are checking whether or not to make an order, you can compare now() to the recorded timestamp."

Can anyone help me out with getting this into code? Thanks.

3 responses

anyone?

I think I figured it out, but I'm kind of surprised if it is this simple, given the lengthy advice from quantopian support. Anyways, I think this does the trick. P.S. quite proud of myself, unless someone comes in and says this ins't accurate. Although, I did a print and it returned the current low of the day every minute:

    day_low = data.history(sid(24), 'low', 1, '1d')  
    recent_low = day_low[-1]  

That should do it. Kudos Michael!