Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Calling the kalman filter function with data from history function

Hi,

I'm trying to smooth the data from the history function, using the kalman filter. But the kalmanfilter function only takes an array (I think), but the data from the history function is a dataframe.

I thought I would loop over all the sids and call the filter, but I'm not sure how to implement it. Anyone know how to implement this=?

prices = np.log(history(context.lookback, '1d', 'price').dropna(axis=1))

# Construct a Kalman filter  
kf = KalmanFilter(transition_matrices = [1],  
              observation_matrices = [1],  
              initial_state_mean = 0,  
              initial_state_covariance = 1,  
              observation_covariance=1,  
              transition_covariance=.01)

for column in prices.T:
mean_prices, _ = kf.filter(column)