Table of Contents
This project is an app that sorts through historical trade data for Bitcoin on two exchanges: Bitstamp and Coinbase. I then apply the three phases of financial analysis to determine if any arbitrage opportunities existed for Bitcoin.
-
You don't need Python. You can install Anaconda and JupyterLab normally just like any other application on your computer. Follow the instructions for Anaconda, ensure that its working, then install JupyterLab.
-
I have placed Comments throughout the code so that you can follow the code and be able to replicate the app on your own. Also, so that you're able to contribute in the future :-)
A text editor such as VS Code or Sublime Text
-
Clone the repo
git clone https://github.com/AnaIitico/bitcoin_arbitrage.git
-
You don't need to install pip - Conda comes with pip and you can also use the command conda install 'package name'
-
Install Conda according to the instructions based on your operating system. For windows users you MUST use the Administrator PowerShell. Users with AMD Processors MUST use the Administrator PowerShell 7 (X64) version
Once installed Conda has an Admin PowerShell version shortcut - look on your Start menu for it. This shortcut will prove very useful at times when you need to install other apps or make adjustments to your installation
Once installed you will see (base) on your terminal
-
Activate Conda Dev environment
conda activate dev
You should now see (dev) on your terminal
-
Install JupyterLabs
pip install jupyterlab
-
Run JupyterLab
jupyter lab
A browser window should open on localhost:8889/lab
This project is an app that sorts through historical trade data for Bitcoin on two exchanges: Bitstamp and Coinbase. I then apply the three phases of financial analysis to determine if any arbitrage opportunities existed for Bitcoin.
Here are some screenshots and code snippets of the working app
you can see the full code (with outputs) in the crypto_arbitrage.ipynb file
This code has been summarized into one block for convenience and there's an analysis at the end
# For the date early in the dataset, measure the arbitrage spread between the two exchanges
# by subtracting the lower-priced exchange from the higher-priced one
arbitrage_spread_early=coinbase['Close'].loc['2018-01-16']-bitstamp['Close'].loc['2018-01-16']
arbitrage_spread_early = arbitrage_spread_early[arbitrage_spread_early>0]
# Use a conditional statement to generate the summary statistics for each arbitrage_spread DataFrame
arbitrage_spread_early.describe()
# For the date early in the dataset, calculate the spread returns by dividing the instances when the
# arbitrage spread is positive (> 0)
# by the price of Bitcoin from the exchange you are buying on (the lower-priced exchange).
spread_return_early=arbitrage_spread_early/bitstamp['Close'].loc['2018-01-16']
# Review the spread return DataFrame
spread_return_early.head()
# For the date early in the dataset, determine the number of times your trades with positive returns
# exceed the 1% minimum threshold (.01) that you need to cover your costs
profitable_trades_early=spread_return_early[spread_return_early>.01]
# Review the first five profitable trades
profitable_trades_early.head()
# For the date early in the dataset, generate the summary statistics for the profitable trades
# or you trades where the spread returns are are greater than 1%
profitable_trades_early.describe()
# For the date early in the dataset, calculate the potential profit per trade in dollars
# Multiply the profitable trades by the cost of the Bitcoin that was purchased
profit_early=profitable_trades_early * bitstamp['Close'].loc['2018-01-16']
# Drop any missing values from the profit DataFrame
profit_per_trade_early=profit_early.dropna()
# View the early profit DataFrame
profit_per_trade_early
# Generate the summary statistics for the early profit per trade DataFrame
profit_per_trade_early.describe()
# Plot the results for the early profit per trade DataFrame
profit_per_trade_early.plot(figsize=(10, 7), title="Profit Per Trade - Jan 16")
# Calculate the sum of the potential profits for the early profit per trade DataFrame
profit_sum_early=profit_per_trade_early.sum()
profit_sum_early
# Use the cumsum function to calculate the cumulative profits over time for the early profit per
# trade DataFrame
cumulative_profit_early=profit_per_trade_early.cumsum()
# Plot the cumulative sum of profits for the early profit per trade DataFrame
cumulative_profit_early.plot(figsize=(10, 7), title="Cumulative Sum - January 16")
#**Answer:** The profit information supports the trend in the narrowing of the spread
#from January to March. As the spread narrows, so does the opportunity for profit,
#as it is evident in the calculated results.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Jose Tollinchi - @josetollinchi - [email protected]
Project Link: https://github.com/AnaIitico/bitcoin_arbitrage