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])
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])
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.