Giter Site home page Giter Site logo

pytrendfollow's Introduction

PyTrendFollow - Systematic Futures Trading using Trend Following

Introduction

This program trades futures using a systematic trend following strategy, similar to most managed futures hedge funds. It produces returns of around ~20% per year, based on a volatility of 25%. You can read more about trend following in the /docs folder.

Features

  • Integration with Interactive Brokers for fully automated trading.
  • Automatic downloading of contract data from Quandl & Interactive Brokers.
  • Automatic rolling of futures contracts.
  • Experimental integration with Bitmex for trading cryptocurrency futures.
  • Trading strategies backtesting on historical data
  • Designed to use Jupyter notebook as an R&D environment.

Installation

Data sources

The system supports downloading of price data from

  1. Quandl
  2. Interactive Brokers (IB)
  3. Bitmex (experimental, not discussed in this instruction).

It is recommended (though not required) to have data subscriptions for both Quandl and IB. Quandl has more historical contracts and works well for backtesting, while IB data is usually updated more frequently and is better for live trading.

To use MySQL as the data storage backend (optional, default is HDF5), you'll need a configured server with privileges to create databases and tables.

Trading

For automated trading with Interactive Brokers, install the latest TWS terminal or Gateway. You'll need to enable the API and set it to port 4001.

Code

  1. Python version 3.* is required

  2. Get the code:

    git clone https://github.com/chrism2671/PyTrendFollow.git

    cd PyTrendFollow

  3. Install requirements:

    • install python tkinter (for Linux it's usually present in a distribution repository, e.g. for Ubuntu: apt-get install python3-tk)
    • install Python requirements: ./scripts/install_requirements.sh
  4. cp config/settings.py.template config/settings.py, update the settings file with your API keys, data path, etc. If you don't use one of the data sources (IB or Quandl), comment the corresponding line in data_sources.

  5. cp config/strategy.py.template config/strategy.py, review and update the strategy parameters if necessary

Usage

Before you start, run the IB TWS terminal or Gateway, go to Edit -> Global configuration -> API -> Settings and make sure that Socket port matches the value of ib_port in your local config/settings.py file (default value is 4001).

  • To download contracts data from IB and Quandl:

    python download.py quandl --concurrent

    python download.py ib

    Use the --concurrent flag only if you have the concurrent downloads feature enabled on Quandl, otherwise you'll hit API requests limit.

  • After the download has completed, make sure the data is valid:

    python validate.py

    The output of this script should be a table showing if the data for each instrument in the portfolio is not corrupted, is up to date and some other useful information.

  • To place your market orders now, update positions and quit:

    python scheduler.py --now --quit

  • To schedule portfolio update for a specific time every day:

    python scheduler.py

For more details on how the system works and how to experiment with it, check out the docs/ directory.

Status, Disclaimers etc

This project is dev status. Use at your own risk. We are looking for contributors and bug fixes.

Only tested on Linux for now, but should work on Windows / MacOS.

Acknowledgements

This project is based heavily on the work of Rob Carver & the PySystemTrade project.

pytrendfollow's People

Contributors

chrism2671 avatar ka-petrov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.