Skip to main content

fast / extensible library for backtesting quantitative strategies

Project description

Documentation Status

Introduction

The pyqstrat package is designed for backtesting quantitative strategies. It was originally built for my own use as a quant trader / researcher, after I could not find a python based framework that was fast, extensible and transparent enough for use in my work.

This framework is designed for capable programmers who are comfortable with numpy and reasonably advanced Python techniques.

The goals are:

  • Speed - Performance sensitive components are written at the numpy level which can lead to performance improvement of several orders of magnitude over python code. Where possible, we parrallelize work so you can take advantage of all the cores available on your machine.

  • Transparency - If you are going to commit money to a strategy, you want to know exactly what assumptions you are making. The code is written and documented so these are as clear as possible.

  • Extensibility - It would be impossible to think of all requirements for backtesting strategies that traders could come up with. In addition, traders will want to measure different metrics depending on the strategy being traded.

Using this framework, you can:

  • Construct a portfolio containing multiple strategies that run concurrently

  • Construct arbitrary indicators, trading signals and trading rules and add them to a strategy

  • Add multiple symbols representing real or “virtual” instruments to a strategy

  • Reuse existing market simulation or build your own to simulate how and when orders are filled

  • Measure well known return metrics such as sharpe, calmar and also add your own metrics.

  • Resample market data bars into lower frequencies

  • Simulate futures rolling using “roll trades”

  • Plot trades, market data, indicators and add custom subplots to give you insight into your strategy’s operation.

  • Optimize your strategy’s parameters using all the CPU cores on your machine.

** NOTE: This is beta software and the API will change **

Installation

I would strongly recommend installing anaconda and creating an anaconda environment. See installation instructions at https://docs.anaconda.com/anaconda/install/

pyqstrat relies on numpy, scipy, matplotlib and pandas which in turn use Fortran and C code that needs to be compiled. Depending on your environment, using pip may not result in a smooth install of these packages

pip3 install -U pyqstrat

Requirements:

  • Python version 3.6 or higher;

Documentation

The best way to get started is to go through this Jupyter notebook: Building Strategies

Jupyter Notebooks

API docs

Discussion

The pyqstrat user group is the group used for pyqstrat discussions.

Acknowledgements

Before building this, I looked at the following. Although I ended up not using them, I got some great ideas for them.

R quantstrat library

Python backtrader project

Some of the ideas I use in this framework come from the following books

Trading Systems: A New Approach to System Development and Portfolio Optimisation - Tomasini, Emilio and Jaekle, Urban

Machine Trading - Chan, Ernie

Algorithmic Trading: Winning Strategies and Their Rationale - Chan, Ernie

Disclaimer

The software is provided on the conditions of the simplified BSD license.

v0.1.0, 2018-07-31 – Initial release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqstrat-0.1.1.tar.gz (41.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqstrat-0.1.1-py3-none-any.whl (54.4 kB view details)

Uploaded Python 3

File details

Details for the file pyqstrat-0.1.1.tar.gz.

File metadata

  • Download URL: pyqstrat-0.1.1.tar.gz
  • Upload date:
  • Size: 41.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for pyqstrat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b6ede585b3c400b932912bf304bd49db266945cfa1f26804ca49350279ed3700
MD5 b9b843b141fc5a93eacff40262b09659
BLAKE2b-256 94bba81fc81733a3c4081482e39d57a4cdc3be646ac110892edea4fa4947868b

See more details on using hashes here.

File details

Details for the file pyqstrat-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyqstrat-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 54.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for pyqstrat-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4438f12bf35cd42e5ba9dd5fd2df46ecda15c29931d7b70b9f0318fd4ca49dc2
MD5 3588a48ee4097e9d9b563abed5dc6c45
BLAKE2b-256 7118046d782f4d22b20e8acaef558bcd3388d2563b2abf1c34f213df6b196d89

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page