Giter Site home page Giter Site logo

ymandcl / pyqstrat Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abbass2/pyqstrat

0.0 1.0 0.0 20.54 MB

A fast, extensible, transparent python library for backtesting quantitative strategies.

License: BSD 3-Clause "New" or "Revised" License

Shell 0.01% Python 4.58% C++ 8.26% C 0.02% Jupyter Notebook 87.13%

pyqstrat's Introduction

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, or in C++, which can lead to performance improvement of several orders of magnitude over regular 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
  • Create indicators, trading signals, trading rules and market simulators 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 returns, drawdowns, common return metrics such as sharpe, calmar and also add your own metrics.
  • Explore historical market data to understand its characteristics and check for errors before using it in backtesting.
  • Simulate futures rolling.
  • Plot trades, market data, indicators and add custom subplots to give you insight into your strategy's behavior.
  • Optimize your strategy's parameters using all the CPU cores on your machine.
  • Process large market data files into quote and trade bars 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. It uses apache arrow as its market data file format and boost C++ libaries

conda install boost-cpp arrow-cpp -c conda-forge

pip install pyqstrat

Requirements:

  • Python version 3.7 or higher;

Known Install issues:

  • arrow-cpp 0.11.1 should not be used, please move to 0.12.1 or later. If the above generic conda command tries to install 0.11.1, please say 'n', and then use this command:
conda install arrow-cpp=0.12.* -c conda-forge
conda install pyarrow=0.12.* -c conda-forge
pip install pyqstrat

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, they are definitely worth looking at.

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.

pyqstrat's People

Contributors

abbass2 avatar stnatter avatar davidbuzz avatar

Watchers

James Cloos 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.