We can detect promising pairs to assess for trading based on mathematical relationships. In this code package, we use the ByBit Python API to extract price history for a large array of Crypto pairs and assess their mathematical relationship using a statistical tool known as cointegration.
With this knowledge, we can detect pairs that are strongly bound together in the timeframe assessed. Meaning, we can trade the difference between the two pairs, rather than speculating on price. This difference is known as the spread.
What you need to get running
You will need Python 3.7 or higher to work with this code. The code was developed with Python version 3.10.8 and pip version 22.2.2.
Download package
Install Python packages
Change directory into your project folder where the code package is saved:
$(root/)
cd myproject
$(root/myproject)
python3 -m venv venv
$(root/myproject)
source venv/bin/activate
$(root/myproject)
source venv/Scripts/activate
$(venv)(root/myproject)
pip3 install statsmodels==0.13.5
pip3 install numpy==1.24.2
pip3 install pandas==1.5.3
pip3 install matplotlib==3.6.3
pip3 install pybit==2.4.1
Run the code
$(venv)(root/myproject)
python3 main_strategy.py
This code can take quite some time to run and find pairs. So let it run.
The reason is, it is hunting through a vast amount of prices on the exchange and comparing price histories for every single possible combination.
Once the code has run, you will be presented a comparison chart of a selected pair. You can of course change this as shown in the video.
Statistical arbitrage analysis complete
You can now start exploring the code and testing things out. The point is you now have objective code to analyse the markets as taught in the Udemy course. In this course, we even build a bot to trade the signals automatically. Regardless, this code in scanning for opportunities and cointegrated pairs is where the true value is at.