Code

There are four python packages hosted on github which you may find useful.


pysystemtrade


python 3.4

Git hub repo

More information on the dedicated page, here.

pysystem trade is the open source version of my own backtesting engine that implements systems according to the framework outlined in my book "Systematic Trading".

Eventually pysystemtrade will include the following:
  • Backtesting enviroment that will work out of the box for the three examples in "Systematic Trading"
  • Implement all the optimisation and system design principles in the book.
  • Complete implementation of a fully automated system for futures trading (for interactive brokers only), including regularly updated data
  • Code to run the present, and future, examples on my blog (i.e. it will replace systematictradingexamples.



ibswigsystematicexamples


python 2.7

Git hub repo



This  code shows how we can use swigibpy (https://github.com/Komnomnomnom/swigibpy) to access the C++ API for interactive brokers using python for a series of simple examples:

Start here

Getting historic, snapshotted prices

Getting real time streaming prices

Placing orders and receiving fills

Getting positions and accounting information 

Using sqllite to store data

 

python-uk-trading-tax-calculator


Git hub repo

This is the package I use to calculate the UK tax liability for my interactive brokers trading. More in this blog post:

Using python to calculate your UK tax liability for trading profits


systematictradingexamples


python 2.7

Git hub repo

This is a collection of random code used to demonstrate some of the principles in my book. See these blog posts for more:


Python code for the trading rules in the book

Python code for optimisation (one period and bootstrapping), and producing different sample periods

Introducing random data

Random data: Trading the equity curve

Random data: Optimising portfolio weights the right way (TBC)


I intend to deprecate this repo, and replace it with examples built using pysystemtrade.



9 comments:

  1. Dear Sir,

    I am using Python 2.7 and would like to reproduce the results from your codes. Upon executing your code "Introducing random data", on line 6, which reads
    "from common import arbitrary_timeseries"
    I always get the following error message:
    "ImportError: cannot import name arbitrary_timeseries"

    Have you got any solution to this problem?

    I am thankful for any help.

    Sincerely,
    Benjamin

    ReplyDelete
  2. You need to add the directory where the common module is to your python path
    http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7
    https://scipher.wordpress.com/2010/05/10/setting-your-pythonpath-environment-variable-linuxunixosx/

    ReplyDelete
  3. Hi Robert,
    Not sure where best to post this question.

    Regarding the example data in pyststemtrade I pragmatically assume that this is actually a dump from the data you use yourself, I guess if thats the case then the data that you use, for example Eurodollar, will follow your preferences for trading 50 months out as you state in your excellent post about price stitching?

    Thanks

    Chris

    ReplyDelete
    Replies
    1. Yes, as far back as I can go it's around 50 months out; when data isn't available in the distant past I use nearer stuff.

      Delete
  4. Hi Rob,

    Any reason you prefer to use doctest instead of unittest?

    ReplyDelete
  5. Hi Rob,

    I was wondering what changes you would make from using pysystemtrade for backtesting purposes to using it for live trading?

    The approach I was thinking of was getting the rounded positions for each instrument and executing these, but then I get back to the problem of variable capital you posted about (in that my starting capital in 1960 isn't my current capital)

    So with that in mind I guess the best approach is to grab the forecasts for each instrument and then following the daily process steps from your book (chap 15)?

    Thanks Chris

    ReplyDelete
    Replies
    1. You could have something that reads you current capital in, changes the appropriate config parameter https://github.com/robcarver17/pysystemtrade/blob/master/docs/userguide.md#capital-scaling-parameters. That is pretty much what I would do in production.

      Delete