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.
You can get it from the Git hub repo

Relevant blog posts

Original motivating post
Estimating forecast scalars
Instruments weights, correlations, and diversification multipliers
Optimising in the presence of costs
The breakout trading rule
Capital correction

Docker and automated trading systems

A note on support

This is an open source project, designed for people who are already comfortable using and writing python code, are capable of installing the dependencies, and who want a head start on implementing a system of their own. I do not have the time to provide support. Of course I am very happy if you get in touch with me on any of the following topics:

  • Confusing error messages
  • Missing or misleading documentation
  • Suggestions for extra features

However I can't guarantee that I will reply immediately, or at all. If you need that level of support then you are better off with another project. The most efficient way of doing this is by opening an issue on github.

I'll try and incorporate any feedback into the code, but this is a part time venture for me, and it will be competing with my other interests (writing books, blogging and research). But if you occasionally check github you will hopefully find it gradually improving. Offers to contribute will of course be gratefully accepted.

A very quick demo

There is a long demo, and an even longer user guide, in the repo so I don't need to repeat them here. Instead here is how you'd simulate the system in chapter 15 of my book, in three lines:

from systems.provided.futures_chapter15.basesystem import futures_system
from matplotlib.pyplot import show

system = futures_system()


The account curve for the system in chapter 15 of my book. Sharpe Ratio 0.48



  1. Bought the book from

    Is there a forum for the user/adopter of the accompany tools?

    God blesses!!!

    Best regards,

    1. I guess this is the forum :-)

      You can also post on any of the threads I started on ET, like

  2. Hello Robert,

    I've been working through your book (slowly, I might add, at weekends and so on) and actually came along to your recent talk to the MTA held at CMC Markets in Aldgate.

    Thank you for a great text!

    BTW I bought the book on ... do I need to register or anything to use the website?

    1. Thanks for the kind words. No registration is needed.

  3. Hi Robert,
    Great book! Forgive my ignorance, but what does the y axis of your equity curve represent? Does it mean that if I had 100k in 1983, I would have 600k in profits in 2016? Thanks.

    1. Thanks glad you liked it.

      Yes, if you didn't compound your profits. See

  4. If I had put 100k in an sp500 index fund from 1982 till now, and just left it alone, I would have made about 10% per year. If I had instead put that money in your system, as plotted by your equity curve in this post, what would my average annualized return have been? Thanks.

    1. There's a simple answer to this and a complicated answer.

      The simple answer is: about 16.7% a year

      The complicated answer is:

      - the equity curve shown is non compounding (equivalent to a log scale). My average return can be compared directly with the s&p but if you plotted them on top of each other mine would look worse.

      - the vol on the s&p 500 was lower; around 15% a year compared to the 25% a year targeted here (and the 30% realised). You ought to chop my return in half to reflect it's higher risk: so call it 8.3%

      - trading futures you can put most of your money in the bank because you only need <10% for margin. So really you should add on LIBOR to all my performance figures, or deduct them from the S&P 500. That's probably about 4% a year on average, so my comparable return is really around 12.3%

      - no investor would hold a trend following system as their only investment (or the equivalent as a share of a CTA like hedge fund). They'd own equities, and bonds, as well. The main benefit of a trend following system is that it adds diversification to traditional portfolios.

  5. Thanks for the thorough answer. Might I be better off investing in a strategy such as the one on page 52 of this paper?

    It shows an average return of 19% over a very long backtest, with 15% volatility. Plus it only requires a monthly (rather than daily) rebalance. What do you think?

    1. Firstly I think I should state clearly that my 'raison d'etre' isn't to push one particular trading strategy over another. It's to provide people with the tools to intelligently evaluate and construct their own strategies.

      Having said that there are several points I'd make (in the spirit of teaching you how to evaluate)

      [I can't work out exactly what the other backtest is doing, so these comments are based on my impressions rather than a detailed analysis]

      - like the S&P 500 the other backtest also includes return on invested cash.

      - I think it is a 'long only' strategy, so it will have more beta exposure. To evaluate the two strategies properly you'd need to account for this.

      - you could rebalance my system monthly and it wouldn't affect the performance much

      - it looks like they're using a single moving average. Using a blend of three like in mine is more robust on an out of sample basis

      - it looks like the system is binary, going from fully long to flat with nothing in between. My system is continous. They don't include trading costs which will be higher in a binary system

      - VERY IMPORTANT POINT: backtested performance is subject to a large amount of statistical uncertainty. You should NEVER pick a system purely because it has a higher backtest than another because of the dangers of overfitting. I could have very easily presented a system which made 50% a year on 15% volatility (but it's not one I'd advise you trading!)

      These are just a few brief comments that you might want to consider when decididing what is the right strategy for you.

      Having said all that as I said above I'm not here to push one strategy over another.

      If the way the other system works suits you, and you think it's robust, then by all means trade it. Almost any trading system is better than none. This system doesn't seem to commit many of the crimes I mention in my book: in particular as it doesn't use leverage it's probably not too toxic.

      And if anything I'd rather you read my book (naturally!) and perhaps used it to build something that combined the elements of systems you like together.

  6. Great points, thanks. Indeed, the system I referenced has performed quite unimpressively the past few years, calling into question whether it is overfitted to past data. However, it does simply use a 12 month look-back for all instruments. Also, don't you think there's something to be said for such a long backtest. Sure, a five year backtest may be meaningless, but a 30 year backtest (like your own) is very convincing to me.

    1. A 30 year backtest is better than a 5 year but still no panacea.

  7. I'm surprised when you say you think that if you only rebalanced your system monthly, it wouldn't make much difference. I thought that one of the main benefits of rebalancing your system daily is that you'll quickly catch any dangerous dips before they become too large. Given that you don't use stop losses, I would think a daily rebalance would be quite important.

    1. Not really; because the underlying trading rules aren't super quick they aren't massively affected by less frequency rebalancing.

  8. Good to know, thanks. I'm considering running the 8 instrument system with thresholding, using excel and placing orders manually, and only checking in on it once a month. In this scenario, do you think there's a benefit in incorporating stop losses?

    1. What trading rules are you using? If mainly trend following then you probably don't need seperate stop losses.

  9. I was going to use the rules you use for your system in chapter 15: carry along with the three slower exponential moving averages.

    1. Then personally I don't think you need seperate stop losses.

  10. Thanks for all your guidance, Robert. I'm finding that my broker doesn't offer the instruments in your list that are traded in euros. Given that fact, would it make sense for me to just replace them with the next three instruments on your list: 2yr notes, Lean hogs, and GBP?

  11. Yes, they don't seem to offer european volatility, eurostoxx, or Korean 3 year bonds. It's TDAmeritrade. Have you ever heard of such a limitation?

  12. It appears they only offer about 50 futures contracts. I would switch brokers, but there are few that allow futures trading in a US retirement account (IRA). Interactive brokers does, but they grossly inflate the maintenance margin required for futures in retirement accounts. Given this limitation, and my desire to diversify your system across about 8 instruments, should I replace the 3 unavailable instruments with the next 3 available ones on your recommended list? Thanks.

    1. So from here for eight instruments I have KR3, V2X, Eurodollar, MXP, Corn, Eurostoxx, US Gas, Platinum

      You can't trade KR3, V2X and Eurostoxx. So you should replace them with a bond (US 2 year), a vol (VIX) and an equity (Nasdaq).

  13. I see, makes good sense, thanks. I hope I am not cluttering your comments section with my very specific questions, but with that risk in mind, here's another question: I noticed this quote from your chapter 15: "With this relatively high volatility target [of 20% annually] you’ll be checking your account value, and adjusting your risk, every day." I am intending to run at 20% volatility, but am planning to adjust risk (or rebalance) only once a month. Granted, I will be diversified across 8 instruments rather than 6, but am I taking on too much risk in this case?

    1. With a vol target of 20% a year a one month one standard deviation move will be 5.7%. So if you have a 3 std dev move over one month that's 17% of your position you'd need to cut. Quite a big cut in your position to delay. Personally I'd run at a lower vol or rebalance weekly or daily.

  14. Hi Rob,

    Quick question: in get_positions_from_forecasts in, the "multiplier" formula is divided by 10; is this because your average_absolute_forecast is 10? That would mean we need to change that value if we're using a different average absolute value I believe. Thank you!

    1. Yes - but you don't need to change that value - in that part of the code it's just an arbitrary number. The p&l for forecasts doesn't know about the real trading system, and just produces a figure for an arbitrary risk target.

      If you want to change 10 where it matters in

      average_absolute_forecast: 10