Systematic trading

Systematic Trading: I sit on my bum and pontificate whilst these bad boys do all the hard work

I spent 7 years working for AHL, a large systematic hedge fund (earlier in my career I also spent about 18 months trading exotic rate options for an investment bank, Barclays Capital). My first job was to develop and manage a systematic mult-asset global macro trading strategy. Subsequently I managed a multi billion dollar portfolio of fixed income strategies (futures, swaps, bonds and credit derivatives). See the 'about' page for more.

Since leaving the hedge fund industry I have written a live systematic trading system written in python and using the interactive brokers C++ API interfaced through swigiby, which I have traded my own money with since April 2014. The system trades nearly 40 futures markets with an average holding period of several weeks, and has a mainly trend following character.

I currently teach a Masters in Finance elective course on Systematic Trading Strategies at Queen Mary, University of London.

I post regular updates on my trading, answer questions and discuss different aspects of systematic trading, on this thread at elitetrader.

I have written two books on systematic trading:

Systematic Trading, 2015

Leveraged Trading, 2019

You can also get my open source python backtesting and futures trading system from github.

Here is my best attempt at grouping my numerous blog posts on systematic trading. Some posts may be repeated under different categories.


Careers advice

So you want to be a quant trader?

Inexperienced traders

 Seven deadly sins of trading

What is the right way to set stop losses

How much risk should we take?
How fast should we trade?

My own trading system

Trading performance: year one 
Trading performance: Year two
Trading performance: year three
Trading performance: year four
Trading performance: year five
Trading performance: year six
Trading performance: year seven

Writing a simple execution algo
Why I don't like short end german bonds anymore 
Simulating my futures system  
A tale of two positions
Obligatory Brexit Post (Will I be okay?)
Obligatory Brexit ex-Post (Yes)
Building a garden trading office
Adding new instruments: Bitcoin micro futures

Forecast strength and risk

Follow up: A better method for dealing with correlation uncertainty

Trading rules

Portfolio construction

Trading with a small(ish) account


Why you shouldn't employ too many geniuses
Should billionaires and bricklayers have the same investments? Capital correction
Reflections on QuantCon 2017
Obligatory BitCoin post
Vol targeting and trend following
Is trend following dead?
ATR vs standard deviation
Absolute or relative momentum?
The three kinds of overfitting

Python code used in the book "Systematic Trading"

Python code for the trading rules in the book
Python code for optimisation (one period and bootstrapping), and producing different sample periods
Python code for optimising in the presence of costs with pysystemtrade

How to get interactive brokers native python API working

How to get python and interactive brokers API interacting via swigby 101

(Deprecated: I suggest using the native python API instead - see the above series of posts)

Start here
Getting historic, snapshotted prices
Getting real time streaming prices
Placing orders and receiving fills
Getting positions and accounting information

A guide to the nuts and bolts of implementing a systematic futures trading system 

Data capture
Futures rolling
Deciding positions 
Checks and balances

Pysystemtrade - my open source python backtesting engine

Original motivating post

Estimating forecast scalars

Instruments weights, correlations, and diversification multipliers

Optimising in the presence of costs

Developing a new trading rule - breakout

Capital correction

Docker and automated trading systems

Adding new instruments: Bitcoin micro futures


Other articles on systematic trading technology

My technology stack
Things I wish interactive brokers would do with their API software
Writing a simple execution algo
Using sqllite to store data
Using python to calculate your UK tax liability for trading profits
My open source python systemDocker and automated trading systems


  1. hi Rob, are your systems available for purchase , subscription? Thanks, Robin

    1. No, never. There's enough material in my book and on this website to reproduce the trading system I use, for free.

  2. Hi Rob,
    How does your framework handle the inevitable loss of power or internet connection?
    E.g, maybe your framework detects a condition that requires an order to be placed but the power goes out or your internet connection goes down.

    Given the description of the hardware you use to run your system it sounds like the code is NOT hosted in some datacenter but rather executes in an environment (such as your home) where such a situation can (and does) occur.


    1. Hi Robert, Great question. Yes I run my stuff 'at home'.

      There are a number of possible scenarios. In scenario one, I lose my internet connection, but then get it back.

      Some services, eg get account value and get price will fail gracefully (treat what they get the same as a NaN).

      Orders that haven't been submitted will be delayed. Given how slowly I trade, I can live with this.

      More seriously if an order is submitted and I miss a fill then I'll get a break between what I think my position is, and what the broker records say. Right now I lock the position to avoid duplicate trades until I've manually fixed the problem (see

      NOTE - there is room for improvement here. I plan to rewrite this process to periodically check all fills received for the day and update the database; then automatically clear any position locks.

      In an extreme situation if a process fails then the cron job will restart it the next day. The only thing that won't restart is the IB API gateway.

      In scenario two I lose power. The system has to be manually restarted. In the short term this is very similar to a loss of internet.

      In an extreme situation (on holiday) I might lose power for a couple of weeks before being able to restart. When I restart the system will backfill all the daily prices and the required trade will then happen. Given the speed I trade at, I've tested the expected effect of this and I can live with it.

  3. FC wrote this comment, which I accidentally deleted:

    "Hello! I am super excited about your stuff and that you are UK based. Do you have an opinion about these:
    Is the tax advantage worth the development trouble, credit risk and worse bid-ask spread? "

    1. I don't have a problem with spread bets, but it's certainly true that if a future was available on the same terms (same tick size) I'd trade the future.

      Usually that isn't the case. For example you can trade FTSE 100 at £1 a point but the future is £10. So spread bets can be especially useful if you have a smaller account, but the wider spread means you'll need to trade more slowly.

      Fortunately my account is large enough that I can just stick to futures.

      I discuss this problem in my book.

    2. Excellent - I've already ordered your book. Awaiting delivery from publisher.

  4. Hi Rob,I read really great reviews about your book and was adviced by a friend to take a look into it, however, I'm a novice to trading and investing, can you advice me what to read and learn before I start reading your book?

    1. Thats a difficult question as it depends on what level you're at and which direction you want to go in. If you want to trade futures then reading Jack Schwagers books would be a good start.

  5. Hi Rob,
    Great book. I wanted to let you know that we specialize in executing systematic trading strategies for clients in the futures and commodities markets. We support several different platforms including TradeStation, TradingBlox, Mechanica, and provide access to nearly every CFTC approved product around the globe. If you know anyone that needs help with putting their strategies into the market, we can help with execution and reconciliation and do an excellent job (for over 20 years now).

    Please contact me if you would like to learn more about the services we provide.

    Thank you.
    Shane Wisdom

  6. Hi Rob,
    first of all, thanks for writing the book, I found it really detailed and helpful.

    I've noticed a minor bug, in a summary just below Table 37, last item "Trailing stop loss when short" has a bug in math: $30 + (4 * $1.5) = $46


  7. Hi Rob,
    In your book you mention how hard it is to overcome the costs in spread betting. For most EU citizens winnings on spread betting is tax free. Is that part of that calculation? Cheers

    1. No I didn't include tax in the calculation. But spread betting is around 10 times more expensive than say trading futures. Tax would need to be insanely high on futures to make spread betting more competitive.

    2. Ok, yes that is pretty sick. When is the new book coming?

  8. Hi Rob,
    Have you done any covered call writing? It seems like a good fit for a systematic trading system. Cheers

    1. I haven't, but yes short volatility strategies like this are a good thing.

    2. Ok thanks.

  9. Hi Rob,
    I came across your website while looking for someone who uses python for trading. Thankfully I found you. I would like to thank you for the informations you share with us.
    I am totally interested in your book. However, I have a question about the content. Do you explain a strategy that you use to trade futures or strategies that can be employed? Because I never trade futures and I would like to start to trade by learning step by step from guidelines of your book if that is the case. What should I expect from your book?
    Thanks in advance.

    1. Hi. Yes I explain some basic strategies to trade futures (also ETF's and spread bets). But they assume some familiarity with futures already. Read something like (first four chapters)

      Also there isn't any python in the book.

  10. Hi Rob,

    after reading your book, your blog (here) and your journal (Elitetrader) I decided to give it a try to program a system based on the framework you propose in your book. My question is about the update rate you use during live trading? Your book emphasizes to not trade too much due to the involved costs. On the other hand, from your journal I get the impression that your system runs continuously as time stamps are all around the clock. How often do you refresh/recalculate instrument parameters such as volatility, and account parameters such as volatility target? I was thinking myself to calculate account parameters once per day, preferably on a moment when all instruments are not trading (account value relatively stable). And recalculate instrument parameters once per hour (only when they are trading). Should I sample instrument parameters more often?

    1. It depends on your holding period. Currently I probably update too much (hourly), given a holding period of a couple of weeks or more. I could easily update everything daily, and indeed in the next iteration of my code that is what I plan to do.

    2. Thank you. As my trading rules will be slow do I expect similar holding periods. A daily update rate will probably be fast enough. However, with several exchanges in multiple time zones involved does that lead to the question: "what is end of day?" Maybe I'll decide to take action at the end of the trading day of each involved exchange.

  11. Hi Rob, I think I noticed an error in your new Carry calculation worksheet ( Cell G22 has: "=IF(AND(C22<>0,F22<>0,C22-F22),C22-F22,G21)". I think you should delete the third element in the "And" function.

    1. Fixed. Thanks a lot

      Interesting how Excel casts into logical type.

    2. Glad to help, thanks for all your advice in response to all my posts. I have been paper-trading your "Chapter 15" system for a few days now. Could you please confirm the following with regard to your carry strategy: On November 4th, the closing price of Dec 2016 Eurodollar was 99.075, and the closing price of Jan 2017 Eurodollar was 99.070. Therefore the trading signal would be long. So, I should be long the Jan 2017 contract, correct? What if the spread was significantly higher on the Jan 2017 contract. Would it be okay to go long the Dec 2016 contract? Would there be any reason to look at the Jan vs Feb 2017 contract, or should we always be looking at the closest two contracts in determining the forecast? Thanks.

    3. Which contract you should trade I discuss more here: . How to measure carry I discuss more in the appendices of my book.

  12. Hi Rob, in your book you mention that is preferable to measure carry on equity futures by using the spot price. Yet, in your python system, for EUROSTX, you use the further contract (which is not held) versus the nearer contract (which, of necessity, must be held). A second question, if I may: you mention in your book that you target 37.5% annual volatility in your own futures system, but fundseeder reports your annual volatility at about 8%. Do you know why? Thanks.

    1. a) It's preferable to use spot, but I don't personally do it because of the hassle of getting sychronised data.

      b) I can't remember exactly what I said in my book but I target 25%. But the fundseeder figures is lower because I have set a higher notional account value. More here

  13. Hi Rob,
    I've just started live trading your chapter 15 system using you terriffic pysystemtrade code. So far, so good. In the meantime, I was interested in a recent article that described a very profitable yet simple system: If sp500 price is above 200 sma, invest it at 3x leverage; otherwise, invest in Tbills. They got a 27% CAGR, but with a max drawdown of 92%, over a very long backtest. That got me thinking about adding a stoploss feature. So, I have been backtesting a similar system with 4x leverage, but a 4% stoploss that is reset daily. I must be doing something wrong on my backtest, as I am seeing around 50% CAGR with only about a 50% max drawdown. This was backtested on the emini back to its start in 1997. I then bumped up the leverage to 10X, with a 1% stoploss, and I am seeing some crazy returns, with not unreasonable drawdowns. I am assuming a trading cost of $17 per contract. Any idea where a novice like me is going wrong? Thanks.

    1. A few things:

      a) it's not unknown to find relatively simple things that deliver a high SR on a single market. You don't know if the original authors found that by luck (this was the first thing they tested) or by testing lots of variations first. In eithier case it's dangerous to assume this SR is reproducible
      b) your backtest now contains futher 'implicit' fitting (trying different stoploss variations) which probably means your sharpe ratio is overstated due to overfitting
      c) as a long only system your returns are overstated because past equity returns and t-bill returns are likely to much lower in future (mainly due to lower inflation)
      d) because the realisable SR is probably a lot less than you think, running it with high leverage is extremely dangerous
      e) these kinds of systems (stocks or T-bills) are toxic with leverage because they have low average risk, but high peak risk. A market shock when you are 100% in equities and 10 times leverage will kill you before you can get out of your position.
      f) With a 1% stoploss you're going to be trading almost every day with a very short holding period. You need intraday data and you need to test the effect of delaying your fills for an hour... up to a day or even several days (think October 87 or September 2001). You also need to make sure your trading costs are spot on. What % of your account are you paying in costs annually?

      A pure test of this would be to run it on lots of markets, testing different SMA variations, testing different stoplosses, and allocating amongst these variations out of sample using price history that has realistic, and being conservative with fill times. You'd get a much lower SR.

      The basic idea of your system probably isn't crazy, but running it at 10x leverage IS crazy. Have another read of my book because there are many mistakes you're potentially making which I talk about at length in the book.

    2. Thanks for your comprehensive reply, Rob. I guess my main mistake was in assuming that my stoplosses would get filled fairly quickly with an acceptable amount of slippage. I didn't realize that they could be delayed several hours or days.

      Let's go back to the less outrageous system which is 4x leveraged. Let's assume another October 1987. Would my 4% stoploss be filled at close to 4%, or is that a naive assumption?

    3. It's safest to assume you'd have been filled at the low for the day - down around 22%.

  14. Robert, thank you for the invaluable information you collected and spent the time to share.
    While looking at your method to retrieve account and positions info from IB, one of your two "Getting positions and accounting information" links showed as broken.
    The goal was to check how your code returns from a failure/crash (Python, system...) and attempt to restore the position prior to the crash. E.g. does the code saves in a database position and account after each trade for future disaster recovery and reporting?


    1. Can you tell me which page the link is on, and the address it is trying to link to.

      To answer your question though, yes the current state is stored in databases.

  15. Robert,
    In trading I see that intraday price volatility is more than expected by standard deviation of daily returns. I think it's because only day close prices are used. What if I get daily volatility in different way, based on returns, which are maximum price move from previous close? I.e. I use High, Low of current day and Close of previous day and I compare abs(High/Close - 1) vs abs(Low/Close - 1) to get bigger, but store its value with sign, not abs. Then EMA smoothing as usual. I've tested the method and for my instruments it shows volatility about 30% more than original method. It enables to avoid big capital moves intraday, but, I cannot understand, it decreases profits or doesn't decrease, because capital used to get positions becomes smaller...

    What do you think?

    Sincerely, Julia

    1. You shouldn't expect this to increase or decrease your profits but it is true to say that adding more information (eg intra-day price movements) should give you a better forecast of volatility; so if you measure expected versus realised vol it will probably come out slightly better

      Having said that you aren't comparing apples with apples; your measure will indeed be biased compared to a daily standard deviation of returns, so you should adjust your risk target to compensate for this

  16. Hi Rob,

    Working through the books as multiple members in my circle recommended. Would you have thoughts on a way to incorporate MAR or CALMAR instead of Sharpe? From what I’ve seen, you get penalized for upside volatility from sharpe (that is sudden portfolio size increases will hurt your sharpe). Would love to hear your ideas if you have any.


    1. Depends what you mean by 'incorporate'. I can think of two places where I use Sharpe Ratios in calibrating trading systems. (i) As a performance measure when deciding what the forecast or instrument weights should be and (ii) in deciding how much leverage to use. For (ii) the Sharpe ratio is only a weak input since we're normally running with much less leverage than the Sharpe would suggest under full Kelly criteria. For (i) in principal you could use other performance measures.

      I don't personally like MAR because maximum drawdown isn't a very robust statistic (drawn off just one observation) and also it's interpretation isn't very intuitive (it depends on the amount of time the strategy has been trading). CALMAR makes even less sense, since apparently it only uses the last 3 years of history.

  17. Hi Rob,
    Pysystemtrade calculates instrument correlations based on the past N days of returns. Might it make more sense to base the correlations on the most recent high volatility day (eg., early Feb 2018), since it's at those points in time that diversification really matters? Also, it's at those times when every instrument seems to have a correlation of close to either +1 or -1 to each other. Thanks.

    1. You could do that but it wouldn't be correlation, it would be you are measuring.

      Personally I prefer to measure correlation, and then I impose a risk overlay which measures risk assuming all correlations go to 1,-1 (I'll be blogging about it soon)

  18. Hi Rob,
    In playing with pysystemtrade, I wanted to see what happened if I removed the possibility of any short positions. I have heard that long positions usually are more effective than short positions when it comes to trend following. So, I basically added a line to your forecasting file that brought the forecast to 0 if it was negative. The result was a huge bump in sharp from .82 to .95. Do you think this is a reasonable tweak to be made to the system?

    1. Well it completely changes what you're doing - it won't be as diversifying to a long only portfolio. Plus that isn't a statistically significant Sharpe increase.

  19. Hi Rob,
    Thanks for your help on my last two questions. I was looking at the carry forecast recently between LIVECOW and SOYBEAN, and I noticed that the price pattern between the two was the same, with the nearer contract being consistently greater than the further contract. This would indicate that the further contract (which I am holding) would go up in price over time. But the capped carry forecast from pysystemtrade for SOYBEAN is +20 and for LIVECOW it is -20. Do you know what could cause this? Thanks, again.

  20. Hi Rob, I have technical question:

    Would it be possible to develop an Algo code in C, that it could connect to IB-Api? I'm aware IB-Api comes in several languages but C, the nearest is C++ which is not C.

    I'd appreciate your opinion in this tricky matter.


    1. Sorry for the delay in responding.

      In theory yes, but I'm not a C or C++ programmer. Try asking here

  21. I was looking for some trading tips then i have visited your blog and found very useful tips. Please suggest some stock tips in future.

  22. Hi, Where can I purchase this one? Is this could be help about trading? I will try this guide with FxLeaders soon!

  23. Hi Rob, would it be possible for you to post the ewmac formula here, as a working example with a few days data. I have copied your formula from Appendix B, but would like to check I have it correctly. I will be using in excel and Aspen Graphics. Looking at real numbers would be a great help. Regards

    1. From here

      Spreadsheet: EWMAC calculation example

  24. Hi Rob,
    I need your advice on setting up risk controls. I trade fx spot (20 times leverage for HK accounts) and just one symbol GBPJPY; fx futures and future options (CME provided leverage) for trading EUR to make most of Span margin system. Trading and risk managing manually. Returns r too good to be true 10% a month (9 pc drawdown). since fundseeder has captured it so I have to believe it.
    I want to make an auto trader for Interactive Brokers for GBPJPY with lots, risk and margin management rules. How do I go about it. Manually, I estimate duration of trend and post limit orders hoping to catch climax of exhaustion. No impulsive trading. I start always with 1 standard lot and then average it if climax estimated by me does not materialises. Maximum lots used by me to average have been 5. But when retracement happens returns are quick n substantial. For auto trader I want to design lot management and stopout level and link it with drawdown or equity level. What kind of filters should I use to control drawdown and equity.
    Thank you.

  25. Hi Rob,
    I need your advice on setting up lot and risk controls. I trade fx spot (20 times leverage for HK accounts) and just one symbol GBPJPY; fx futures and future options (CME provided leverage) for trading EUR to make most of Span margin system. Trading and risk managing manually. Returns are too good to be true 10% a month (9 pc drawdown). since fundseeder has captured it so I have to believe it.
    I want to make an auto trader for Interactive Brokers for GBPJPY with lots, risk and margin management rules. How do I go about it. Manually, I estimate duration of trend and post limit orders hoping to catch climax of trend exhaustion taking into account the probability of daily pullbacks and daily average pips as a measuring scale . No impulsive trading. I start always with 1 standard lot and then average it if climax estimated by me does not materialises. Maximum lots used by me to average have been 5. But when retracement happens returns are quick n substantial. For an fx spot auto trader I want to design lot management and stopout level and link it with drawdown or equity level. What kind of filters should I use to control drawdown and equity.
    Thank you.

    1. Apologies for the slow response to your comment. 99% of the comments I get are spam, so inevitably when deleting them a few real comments get overlooked.

      That's an absolutely huge question you've asked (in fact really it's lots of questions), and all I can do is point you to the advice elsewhere in this blog and in my books "Leveraged Trading" and "Systematic Trading".

  26. Hi Rob,

    A bit embarrassed to ask this question.

    I have been using Amibroker for designing systematic trading strategies since afl is quite easy to learn (as I belong from a commerce/management background).

    Question is ...
    Would your book still be helpful as you have been designing all your strategis on Python (no experience whatsoever on Python)?

    Secondly - How difficult would it be for a commerce guy to get hold of python?

    1. You can implement the strategies in the book on a spreadsheet. I have an ex-colleague who implemented them in Amibroker.

      By 'commerce' I guess you mean non programmer, and by 'get hold of' I assume you mean learn. It's hard for me to say as I have been programming for a very long time, but python is easier to learn than say C++ or Java.

  27. Hi Rob,
    In the MA crossover rule from the starter system, should we do the calculation on :
    - BID prices
    - ASK prices
    - the average of BID/ASK for each given day of the serie

    I was planning to start with AUDUSD as a spot CFD. Thanks to your books, I have reviewed the costing section from my broker (IG) T&Cs and they will apply funding charge based on tom-next rate + an admin charge they say would be small but is not disclosed in details. Would you have any way on elaborating on this tom-next concept and how to calculate it ?

    They also explain this would not happen on the corresponding CFD based on the future AUDUSD as this is included in a wider spread. So I might look at this option with a 2000Eur equity.

    Looking forward to read you.

    Kind Regards,

    PS: thank you for your books - I was dreaming of an ichimoku automated scalping system (without calculating the risks) and I am now convinced the starter system is the one to follow (with a bit of JAVA)

    1. It doesn't matter so much, but average of bid/ask is probably best.

      The 'tom-next' rate will be based on the difference in interest rates between AUD and USD two days forward, as that is when the trade settles. Problem is a 'small' admin charge has a habit of adding up over a year. I'd personally trade the CFD based on a future ('undated' in my terminology) if you have the capital.

  28. Hi Robert,

    How to understand TURNOVER usage? I am reading book "Systematic Trading". On page 306, for stauch systems trader, there would be tradings almost every day, the TURNOVER for the system should be around 260, but on page 298, for different EWMAC rule, the TURNOVER is very small.

    It is confusing me that in real trading, the TURNOVER is around 260, why do we can use specific TURNOVER for different EWMACs.


    1. You need to read carefully again what the definition of turnover is. It is irrelevant whether you trade every day or not. Imagine you have an average position of 256 lots. Every day you buy or sell 1 lot. But your turnover would be once a year.

  29. Hello Rob,

    Thank you for your books. I have two questions regarding your system:
    1. What time during the day you recommend to run the program to rebalance the positions if you trade forex (EUR/USD) using your rules? Should it be early in the morning at, say, 8.30 am, London time? And,
    2. When closing positions, shall older positions be closed first or newer positions first meaning shall it be FIFO or LIFO?
    If you wrote about these issues previously somewhere, would you point at them as I wasn't able to find them.

    Thanks in advance,
    Much appreciated,

    1. 1. When the markets are liquid

      2. This question makes no sense to a futures trader

  30. wow rob, i just notice you have a new setup! great one!

  31. Hello Rob. Quick question on Systematic Trading.

    You quite often refer to the expected risk of the portfolio (blog, ET), and for me its a bit confusing.
    Is it as simple as the total of "I" (Instrument Value Volatility) in numerous tables throughout ST?

    If not, are you able to refer me to a blog post / writing that talks about how you calculate Expected Risk of Portfolio?


    1. Just the standard formula with covariance matrix and weights.


Comments are moderated. So there will be a delay before they are published. Don't bother with spam, it wastes your time and mine.