This project was motivated by the correlation of price movement between ETH and BTC. We experimentally analyse the linear relationship between prices of ETH and BTC (in pairs-trading what is known as co-integration). We further backtest on past data and also run the strategy in a live-trading environment. Data for this project was downloaded from binance's website https://www.binance.com/en/landing/data. We had experimented with candlestick data with multiple time-granularities - ranging from 1 minute to 1 day.
- We experimentally analyse the price relationship between ETH and BTC by (1) plotting the moving averages between ETH and BTC, (2) plotting the linear regression line between ETH and BTC. The code is present in
pairAnalysis.py
. - Our first methodology involved using a single Regression coefficient throught the pairs trading strategy. We backtest this in
pairBacktestingRegression.py
. - On realizing the dynamic linear relationship between ETH and BTC prices, we perform continual training of linear regression coefficients. We backtest this in
pairBacktestingContinualRegression.py
. - Finally, we also devise a Kalman Filter strategy wherein we update the filter parameters after new price information arrives. This strategy performs the best amongst the ones tried. We backtest this in
pairBacktestingKalman.py
. - Based on our backtesting, we create a live trading environment using Binance's APIs. Shorting of a coin is done using its Margin Trading API which required a collateral-leverage analysis. A coin is bought long using its Spot Trading APIs. The binance API functions are written in
binance_api_functions.py
and it's ad-hoc testing was done intest_binance_api.py
. Finally, the main live trading logic and code is implemented intrading_main.py
. The logic is implemented by taking inspiration from reactJS's state saving mechanism - where we save and load trading/position states at regular intervals.