├── PairsTrading.ipynb ├── README.md └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # Pairs Trading With Python 2 | 3 | This project involves using a combination of statistics along with financial thoery to demonstrate a popular trading strategy used in equity markets: Pairs Trading. 4 | 5 | ![Pairs Trading](https://kidquant.com/post/images/Trading_Signals.png) 6 | 7 | ## Goal 8 | 9 | Our goal involves the following: 10 | 11 | * **Part 1**: Creating a model that test for stationarity. 12 | * **Part 2**: Creating a model that test for cointegration. 13 | * **Part 3**: Assigning a portfolio of assests and testing for a cointegrated pair among the dataset. 14 | * **Part 4**: Establishing features and labels that will allow us to create trading signals for the strategy. 15 | 16 | ## Data 17 | 18 | I used the data from [Yahoo Finance](https://finance.yahoo.com/), which provides historical financial data for free. This data was extracted via the [yFinance](https://pypi.org/project/yfinance/) Python module. 19 | 20 | ## Enviroment and Tools 21 | 22 | The following are the modules we will use in this notebook. However, the program relies on many more dependencies than what is shown here. Please be sure to set up a virtual enviroment and install the [requirements.txt](https://github.com/KidQuant/Pairs-Trading-With-Python/blob/ad5c42fa2aedc1ab30e9028aa816df8e950cc010/requirements.txt) file before running this programming on your own. 23 | 24 | 1. Jupyter NoteBook 25 | 2. Numpy 26 | 3. Pandas 27 | 4. Matplotlib 28 | 5. Seaborn 29 | 6. Statsmodels 30 | 7. Pandas DataReader 31 | 8. DateTime 32 | 9. yFinance (formally known as `Fix Yahoo Finance`) 33 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asttokens==2.0.8 2 | backcall==0.2.0 3 | certifi==2022.9.24 4 | charset-normalizer==2.1.1 5 | colorama==0.4.5 6 | contourpy==1.0.5 7 | cycler==0.11.0 8 | debugpy==1.6.3 9 | decorator==5.1.1 10 | docopt==0.6.2 11 | entrypoints==0.4 12 | executing==1.0.0 13 | fonttools==4.37.3 14 | idna==3.4 15 | ipykernel==6.15.3 16 | ipython==8.5.0 17 | jedi==0.18.1 18 | jupyter-client==7.3.5 19 | jupyter-core==4.11.1 20 | kiwisolver==1.4.4 21 | lxml==4.9.1 22 | matplotlib==3.6.0 23 | matplotlib-inline==0.1.6 24 | multitasking==0.0.11 25 | nest-asyncio==1.5.5 26 | numpy==1.23.3 27 | packaging==21.3 28 | pandas==1.5.0 29 | pandas-datareader==0.10.0 30 | parso==0.8.3 31 | patsy==0.5.2 32 | pickleshare==0.7.5 33 | Pillow==9.2.0 34 | prompt-toolkit==3.0.31 35 | psutil==5.9.2 36 | pure-eval==0.2.2 37 | Pygments==2.13.0 38 | pyparsing==3.0.9 39 | python-dateutil==2.8.2 40 | pytz==2022.2.1 41 | pywin32==304 42 | pyzmq==24.0.1 43 | requests==2.28.1 44 | scipy==1.9.1 45 | seaborn==0.12.0 46 | six==1.16.0 47 | stack-data==0.5.0 48 | statsmodels==0.13.2 49 | tornado==6.2 50 | traitlets==5.4.0 51 | urllib3==1.26.12 52 | wcwidth==0.2.5 53 | yarg==0.1.9 54 | yfinance==0.1.74 55 | --------------------------------------------------------------------------------