inevolin / InteractiveBrokers-backtesting

This repository provides a simple Python3 template for creating and running backtesting algorithms on a historical dataset of a specific security.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InteractiveBrokers Backtesting

This repository provides a simple Python3 template for creating, running and visualizing backtesting algorithms on a traded security.

tsla

Getting started

  1. Download and run the IB Client Portal : ./bin/run.sh root/conf.yaml
  2. Authenticate through the local portal: https://localhost:5000
  3. Once authenticated you can make HTTP requests to obtain historical data: https://localhost:5000/v1/api/iserver/marketdata/history?conid=76792991&period=14d&bar=1h&outsideRth=true (the conid is for TSLA)

Code

In the code example I obtain data for Tesla Inc. and generate buy/sell signals based on a simple heuristic.

  1. Ensure the Client Portal up and authenticated.
  2. Install the required Python libs pip install -r requirements.txt
  3. Run python3 backtest.py (this script acts as a template).
  4. A new browser tab will open with the candlestick chart and buy/sell signals.
  5. The script will output the ROI of the buy/sell signals (excluding transaction fees) ROI: 5.140722 (in %).

Contact

About

This repository provides a simple Python3 template for creating and running backtesting algorithms on a historical dataset of a specific security.

License:MIT License


Languages

Language:Python 100.0%