Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
history function returns NaN even when forward fill is set to true

I am using history(bar_count=41, frequency='1d', field='close_price', ffill=True) to fetch the price history for some ETFs. My algo posts a trade and then it fails because the history method returns a NaN in the next iteration for ETF ADRA.

My assumption was that if forward fill is true then it should not return NaNs. Please let me know what I am doing wrong here?

2 responses

I had the same and in the end I found that this works for me:

prices = history(200, '1d', 'close_price').apply(lambda x: x.fillna(x.mean()),axis=0).apply(lambda x: x.fillna(0),axis=0)  

if fills the NaN with the mean or a zero

Thanks Peter.