As I understand the PipeLine loops over the entire stocks universe available and allow access to its closes and other columns
What I am trying to do is calculate the Beta Coefficent for each stock, to do so I have to access that last X closes for that stock and the SPY for the same period, here is my implementation so for:
window_length=100
class Beta(CustomFactor):
inputs = [USEquityPricing.close]
def compute(self, today, assets, out, close):
# 8554 is SPY
spy_column = close[:, assets.searchsorted(8554)]
#spy_closes = spy_column[:, None]
stock_returns = np.diff(close[-1:-100:-1])
#print (close[-1:-100:-1])
spy_returns = np.diff(spy_column)
beta = np.cov(spy_returns,stock_returns)/np.var(spy_returns)
out[:] = beta
I got an error : ValueError: all the input array dimensions except for the concatenation axis must match exactly
I even tried to make the diemensions similar by:-
arr2d = np.array([[],spy_column])
spy_returns = np.diff(arr2d[1])
Is there a way to get access to the entire column for that particular stock?