/quant-trading

An ML approach to analyzing the crypto markets based on Stephan Jansen's book - ML for Algorithmic Trading

Primary LanguagePythonMIT LicenseMIT

quant-trading

This repository is a corpus of quantitative analysis of the crypto markets using the Binance API based on Stephan Jansen's book -- Machine Learning for Algorithmic Trading: Predictive models to extract signals from market and alternative data for systematic trading strategies with Python, 2nd Edition.

ML for Algorithmic Trading

1. Market Data

Order book analysis: After slightly modifying and refactoring the Binance Public Data script, I was able to download the list of daily aggregate trades (buy and sell data) for any asset on the exchange for a specified period. I chose to analyze aggregate trades over normal trades. If you want to read about the difference, you can do so here. I was also able to download the Futures orderbook data from Binance (API whitelisting needed).

An orderbook is categorized into the buy orders, sell orders, size and price. Analyzing these four attributes for a particular asset informs us about the order imbalances that give insight into an asset's direction over the short term. For example, a large number of buy orders around a specific level might indicate a level of support for the asset.

The MarketData folder is divided into the data collection segment where I download order book data and the data analysis segment where I compare the real-time order flows between the bid and ask prices of an asset i.e. BTCSUSD Futures. The data_collection folder contains the scripts to download (futures) order book and (spot) trade print data.

The futures order book spreadsheet is categorized into:

  • symbol
  • side (buy order or sell order)
  • timestamp
  • price
  • quantity

The spreadsheet for the spot and futures trades is categorized into:

  • Aggregate tradeId

  • Price

  • Quantity

  • First tradeId

  • Last tradeId

  • Timestamp

  • Was the buyer the maker

  • Was the trade the best price match.

    Recent Trades screenshot

The Binance Individual and Aggregrate Trades can be downloaded here.

# Get realtime Order Book API endpoint
curl -X GET https://fapi.binance.com/fapi/v1/depth?symbol=BTCUSDT

Order Book Histogram