Hi,
I attempted to rank stocks based on their auto correlation of returns and it times out. Any advise if I could do some pre-filtering to reduce the universe before I use pipeline?
Hi,
I attempted to rank stocks based on their auto correlation of returns and it times out. Any advise if I could do some pre-filtering to reduce the universe before I use pipeline?
I did something like that to only calculate an expensive factor on my market cap universe which I was ultimately going to screen the universe on. See MomentumTopN (vs Momentum).
https://www.quantopian.com/posts/stocks-on-the-move-by-andreas-clenow
I notice now that I am calculating my own market cap in there, which is no longer allowed for live trading, so you might want to switch the the real market cap.
I notice now that I am calculating my own market cap in there, which is no longer allowed for live trading, so you might want to switch the the real market cap.
This is kinda cryptic to me. What do you mean? Are you saying that this code won't run
class MarketCap(CustomFactor):
inputs = [USEquityPricing.close, morningstar.valuation.shares_outstanding]
window_length = 1
def compute(self, today, assets, out, close, shares):
out[:] = close[-1] * shares[-1]
@ Pravin,
I ran your code and confirmed the time-out:
TimeoutException: Call to before_trading_start timed out
There was a runtime error on line 31.
I'm guessing your autocorrelation function is the problem. There's a discussion on https://en.wikipedia.org/wiki/Autocorrelation of the efficiency of the computation. You might have a look at:
http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.fftconvolve.html
It provides an autocorrelation example.
[EDIT] I just took a closer look and it seems you are calculating the 1-day lag correlation coefficient in returns. It appears you are computing the entire correlation matrix, but only selecting one element. Perhaps try computing only the element you need?
Looked at it a bit more. You might try writing a fully vectorized version of:
class AutoCorr(CustomFactor):
inputs = [USEquityPricing.close]
window_length = 30
def compute(self, today, assets, out, close):
for i in range(0, np.shape(close)[1]):
R = pd.Series(close[:, i])
R = R.pct_change().dropna().values
out[i] = np.corrcoef(R[1:], R[:-1])[0,1]
The loop is probably unnecessary.