/Cointegrating-Stocks-in-S-P-500

Searching for cointegrating stocks and create a trading strategy using them and Analyze their performance.

Primary LanguageR

In this Project, I have created a dashboard that can be used to find stocks that are cointegrated in S&P 500 and analyze the relationship and create trading signals based
the relationship. I do this by testing for regime shits and cointegrating relationship during the stable periods in the stock's price series.

I have then created portfolios based on these trading signals and analyze their performance by backtesting.

Step 1  -> Importing the data
Step 2  -> Finding Structural Breaks in each stock                               - Bai and Perron Test
Step 3  -> Testing for Unit/Explosive roots for each stock                       - Augmented Dickey Fuller Test
Step 4  -> Testing for Cointegrating relationships                               - Johansen Cointegration Test
Step 5  -> Forecasting prices to backtest                                        - VAR model
Step 6  -> Diagnostics for the cointegrated relationships                        - Correlation, Error Correction Term, Granger Causality
Step 7  -> Forecast and Performance Evaluation of individual Trading Strategy    - Weekly return, Volatility, Sharpe, Peak to trough drawdown, Recovery, Hitrate 
Step 8  -> Backtest and Performance Evaluation of individual Trading Strategy    - Weekly return, Volatility, Sharpe, Peak to trough drawdown, Recovery, Hitrate
Step 9  -> Constructing Portfolio using the Pairs                                - Based on weak optimization of either Return, Volatility, Sharpe, Drawdown or Hitrate
Step 10 -> Backtest and Performance Evaluation of the portfolio                  - Weekly return, Volatility, Sharpe, Peak to trough drawdown, Recovery, Hitrate


Step 2 and 3 takes a long time. To make the dashboard faster, you can export the forecasts and the individual pair's performance and import them to make the dashboard lighter.  
Step 8-10 must be improved by rebalancing the pairs every week instead of choosing same pair. (This is also against the theory as all the pairs exhibit cointegrating relationship only during a specific period.)

P.S - I have only tested for relationship between two stocks at a time. If we are to extend this to cointegrated relationship between multiple stocks, that would be a typical statistical arbitrage strategy.