Back to Community
Statistical arbitrage on returns using PCA

I tried to implement the famous paper https://www.math.nyu.edu/faculty/avellane/AvellanedaLeeStatArb071108.pdf

Can a generous soul cross check the notebook implementation because when I backtest this strategy it is not profitable? The paper is easy to understand.

Best regards,
Beginner

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

And here's a backtest. Loss only. Wonder why?

Clone Algorithm
76
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: 55717155dc3f401168ec3720
There was a runtime error.

I didn't check the whole algo but it seems you are destroyed by transaction costs. It is slightly winning before taking them into account

Clone Algorithm
49
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: 557190004d784910c72e2a02
There was a runtime error.

Hi Beginner!
considering the above strategies, I was wondering if you have checked out the below paper.

http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1404905.

Attilio has published Matlab code with the paper.
The paper does seem more clear to me.
Thoughts....

Regards,
Andrew

Thanks Andrew. I think the paper you mentioned in based on cointegration rather than PCA factors.

ahhh think I am getting a bit confused.

Beginner, the paper 404'd do you have the name of it or a mirror? Thanks.
edit: https://www.math.nyu.edu/faculty/avellane/AvellanedaLeeStatArb071108.pdf

Edited thanks good trader

Hey, thanks for your work. But I am wondering why
"eigport = eigport / np.sum(np.abs(eigport)) * 250000" rather than
"eigport = eigport / np.sum(eigport) * 250000"

Hi, thanks for your algo. I am currently studying this paper and can anyone kindly tell me what is score and hf really? why 2 and why 5? Plus, what is counter? why 5? Thx!!

Can you explain this line?
num = -a * np.sqrt(1-b**2)

Have you identified the issue yet? I can't seem to find the "close position" signal, i.e abs(s) < 0.5, in your code.

Hi John,

I gave up on this approach. There are many other ways to do statistical arbitrage.

Best regards,
Pravin

Just had a second look at your code. You implemented the "close" signals incorrectly, if I'm not mistaken.
Your algo closes ALL open positions if NONE of the stocks in the list yields abs(score) > 2 and hf < 5 and ...
Instead, each stock should be treated individually and if abs(score) < 0.5 only the position related to that stock should be closed.

@Aqua, which strategy on which securities did you find to work better, if any?