Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Pulling 52 week low

Hi everyone. Please take a look at my code below and tell me where I am going wrong. I am getting a runtime error on the 2nd line.

    low_history = data.history(stock, "price", 252, "1d")  
    low = min(low_history[stock][:252])  
4 responses

Sometimes the stock history includes NaN values. That may be the problem.

Fortunately, the 'data.history' method returns a Pandas Series object so you can use all the nice Pandas methods. You aren't stuck with the basic Python 'min' function. I'd recommend using the '.min' method. This should do the trick.

low = low_history.min()

The '.min' method defaults to excluding any NaNs. It will return a single floating point value if 'stock' is a single security. However, it will return a series of floating point values if 'stock' is a list. Use any of series indexing techniques to get to a particular value if needed in that case.

See if that fixes it.

I am just working with 1 stock. Still getting the same error message using the below..

    low_history = data.history(stock, "price", 252, "1d")  
    low = low_history.min(low_history[stock][:252])  

try exactly like this

low_history = data.history(stock, "price", 252, "1d")  
low = low_history.min()

Thanks!