Back to Community
A very crude mean reversion attempt

Here is an attempt to capture mean reverting security prices. My algorithm is very crude at the moment and needs major improvements. Just a proof of concept for the time being.

Clone Algorithm
525
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 599ac5c16471175109ffed40
There was a runtime error.
3 responses

An here is the corresponding research notebook that shows mean reverting prices after adjusting for PCA factors.

Loading notebook preview...
Notebook previews are currently unavailable.

@Aqua Rooster It's an old post so you might have already figured out, but the NB is not really showing out of sample data. To compute those mean reverting prices you are regressing the prices against the factors, but the factors are computed using the prices themselves, this is look-ahead bias unfortunately. Any day plotted in blue (out of sample) should be computed with data coming only from previous days, otherwise it doesn't make sense.

As a proof of what I said, take any time period you like, any configuration of PCA you like and you always get a mean reverting output in your NB, but the same settings don't give good results in your algorithm

I believe the idea behind the algorithm is good and the algorithm is fine too. I only wanted to highlight that the NB needs some changes.

@Aqua Rooster, I am curious about this code:

ret = np.diff(lP, axis=0)  
pca = PCA(50, whiten=False)  
factors = pca.fit(ret[:100, :]).transform(lP)  
model = smapi.OLS(lP, smapi.add_constant(factors)).fit()  

The PCA is computed on price diff (why not returns or log returns?) and then you compute the residual on the price (after PCA transformation). This is interesting, could you elaborate on this?

Also, do you have an empirical rule on how many PCA components to use?

Thanks.