Monday, 1 March 2021

Does X work, some brief thoughts and choose your adventure

When I was a spotty teenager I was a walking nerd cliche. I liked computers; both for programming and games. I was terrified of girls. I was rubbish at nearly all sports*.  And I played D&D (and Tunnels and Trolls, and Runequest).

* Nearly all: Not, I'm not talking about the 'sport' of Chess: I was also rubbish at Chess and still am. But due to some weird anomaly I was a dinghy sailing champion at school, and later world champion.

I also remember reading the Fighting Fantasy books written by Games Workshop founders Steve Jackson and Ian Livingstone. 

Copyright image used without permission, but if you click here you can buy this book so that seems fair


These books were 'choose your adventure' style. So you'd read page 1 and it would say something like 'You are outside a mysterious castle... long dull description of castle follows.... Do you (a) climb the castle wall (p.34), (b) dress up as a washerwoman and try and enter the castle through the front gate (p.172) or (c) attack the sentries head on' (p.91). And after making your choice you'd turn to page 34, or 172, or 91; and you'd find out what the consequences of your actions were, and there would be a new set of options unless you'd already died (hint: option (c) is a poor choice).

As well as playing the book properly you could do 'fun' stuff like reverse engineering the network graph for the pages and working out the optimal shortest route through the book.

Now anyone under the age of 35 will be open mouthed at how archaic this sounds, but yes, this is what we had to do for entertainment in the 1980's. And that was partly because even then parents were worred about screen time, and if you were curled up in a corner with an actual book they would be happier than it you were sat in front of your ZX spectrum playing Jet Set Willy (kids: google it). Of course now I spend entire days in front of a screen, and my idea of relaxation is to read books, so go figure.

You may be wondering what this has to do with anything, but bear with me for a bit as I'm now going to radically change the subject. 


Quite a few of the queries I get asked run along the lines of 'Does X make sense?'. Here are a few recent examples:

  • Does changing your moving average speed make sense in different periods of volatility?
  • Does it make sense to use a different system on the long or the short side?
  • Does it make sense to use a different system in bull or bear markets?
  • Should I use different parameters for different instruments?
These 'does it make sense' questions, are interesting. For starters, they all seem to make intuitive sense. It seems crazy that the market would behave in exactly the same way in periods of high and low vol. It's obvious the market doesn't go up and down in the same way. And naturally, trading Eurodollar is completely different from trading VIX. 

These 'does it make sense' questions are also dangerous. Every single one of them is an invitation to make your system more complex and less intuitive. Every single one is replete with the opportunity to overfit. They introduce a new set of parameters, to define market state; and then multiply the existing set of parameters by allowing different values for different states.

These questions are also complicated, and involve answer several different questions. They involve modifying or changing your system according to some kind of exogenous input, but exactly what that input should be isn't always obvious. It isn't always clear how we should make the change. And they also bring up some interesting questions about how we should evaluate the relevant changes.

Take the first question as an example. First of all we need to define what a different level of volatility looks like, how it should be measured, how many states there should be, and so on. There is room for a lot of implicit fitting there, so we should probably keep things simple and try and stick to some predefined measure; maybe 2 to 4 states of volatility using quartile measures based on the full history of the relevant instrument.

We then need to work out how to change our moving average speed (which for once is a very tightly defined 'how'). For me that at least is relatively straightforward: I'd change the forecast weights that determine how my forecasts are linearly combined. That at least can be done with explicit fitting to avoid exploding the number of parameters we have to consider. 

As for evaluation, well that isn't so bad, we can just compare a system before and after. Of course we need to decide if we're just going to look at Sharpe Ratio, or do we also care about skew. Also, are we happy with any improvement no matter how small? Or should we seek a higher threshold given we're making our system more complicated? Or is this a change that makes sense in it's own right, and we should be happy to do it even if it performs slightly worse (although not worse in a statistically significant sense).

What about the long and short system? Defining long and short is easy enough, but what parameters should we change? Something like the response function to the forecast (this kind of plot) perhaps. That might mean that we take on smaller positions when short in certain markets, which I suppose is what people would like and expect to see. 

However, should we evaluate such a change based on pure Sharpe Ratio? If we did this, then we'd end up never going short markets which have barely gone down in the past, and basically increase our long bias to eg bonds (we can make things worse, incidentally, by not forcing the response function to go through zero). That would only make sense for someone who is only investing in this trading strategy, and doesn't also have something like a 60:40 portfolio already. 

So a better evaluation would be something like 'alpha', where we are looking for improved returns versus the market rather than outright improvements (of course how we define 'the market' is another moot point).

Bull and bear markets is a related question. The first question, once again, is how to define bull and bear in a non forward looking way. Something like the risk adjusted 200 day EWMA seems reasonable without being tempted down the path of overfitting. I used changes in US interest rates in this post as a proxy (something that's relevant after the wild changes in rates products over the last few days.

How should we implement the change? I'd be most tempted to allow my forecast weights to change; rather than modifying the behaviour of any individual rule. And again, evaluation should rightly consider 'alpha' not just outright Sharpe Ratio. And consistency of performance should probably come into it; higher SR isn't as good as seeing better performance in bear markets as that 'insurance' payoff is part of what people like to buy CTA type strategies for.

Different parameters for different markets is another massive can of worms. The same issues of how to change things and how to evaluate them is relevant. Again, I'd be most tempted to fit different forecast weights, which I do a bit anyway because different instruments have different cost levels and I take those into account. 

But there is surely some value in pooling data from other markets as well? Shouldn't we fit based on some blend of an instruments own data, plus data from other markets (where the blend would be different depending on how much data the relevant instrument as). Should we also give higher weight to markets that are more similar? (same asset class, same country, in some kind of correlation cluster....?)

Also, what if we do this and one or more of the other changes? Should we trade long/short markets differently for US 10 year bonds as we do for VIX? 

Phew!

As you can see, these 'does X work' questions can quickly become very complicated. So you can see why I'm wary of doing them.

But I've decided to one of these investigations this month, and you get to choose which one!

Yes, just for this month, I'm going to make this a 'choose your adventure' blog where you get to decide the ending. These are the options:
  • Does changing your moving average speed make sense in different periods of volatility?
  • Does it make sense to use a different system on the long or the short side?
  • Does it make sense to use a different system in bull or bear markets?
I haven't included 'fitting for instruments' since that is a significant project rather than something I can do in a few days, although I will probably look at it in the future.

Let me know which of the ideas above you'd like me to investigate, and I'll write a longer blog post about the one that is the most popular. The poll is here on twitter and on quiz-maker....


UPDATE 3rd March 11:47 GMT: VOTING CLOSED

The votes are in! The votes are (in traditional reverse order):

  • Does it make sense to use a different system in bull or bear markets? 23.8%
  • .... to use a different system on the long or the short side? 32.9% 
  • ... to change your moving average speed make sense in different periods of volatility? 43.3 votes is the winner
 The vote breakdown is here, including Twitter (TWTR), quiz-maker (QM) and below the line (BTL) comments:

        TWTR BTL QM Total
Vol & speed 44 18 62
Long & Short 33 3 11 47
Bull & Bear 28 6 34

So at some point in the very near future I'll be posting on "Does changing your moving average speed make sense in different periods of volatility?"


UPDATE 4th March

Monday, 1 February 2021

So you want to be a quant/systematic trader?

 One of the upsides of having a (very, very minor) public profile is that you get a lot of people asking you for advice, which is flattering (and if you say otherwise, you need to consider just how first world that particular 'problem' is). The only downside of this is you get asked the same sort of question a number of different times. At some point it becomes worth writing a blog article about the subject, which saves time, but also means the person asking will get a much better answer.

(Also, cynically, posts like this get more clicks than ones about obscure corners of portfolio optimisation)

The generic question this article seeks to answer is "How do I become like you, Rob?" And by 'like you', they don't mean "How do I become a bald middled aged bloke with three kids, a mortgage, and an awesome shed?" They want to know how to become a systematic / quantitative trader.

Now there is a trite answer to this which is 'read all my books and stop bothering me you peasant', but of course even the most arrogant and prolific author cannot really believe that their canon alone is sufficient reading material to prepare someone for their future career.

This post is divided into three parts; firstly I define what I mean precisely by the end goal of becoming a systematic/quantitative trader. Secondly I discuss routes to market, how you can actually end up in this lofty position. Finally I talk about the resources I would recommend to help you.



Where you want to end up?

The phrase 'quant / systematic trader' I began this post with this deliberately vague; it's not clear exactly what this means. And the reason for that is that I don't want this post to be limited only to someone who wants to end up exactly like me, trading futures with a holding period averaging a few weeks with a fully automated system lovingly coded in python, using mostly momentum and carry type signals.

For starters there are a whole bunch of different trading styles and assets that are ripe for trading in a systematic or quantitative way; options, ETFs, equities, cash bonds, swaps and CDS; and you can trade those from high frequency up to buy and HODL forever; using valuation factors, relative value basis, or by providing liquidity, or in a thousand different ways.

And of course you can trade purely systematically, or in a purely discretionary way but guided by numbers (so still a quant), or in some mixture of the two; with or without a fully automated system.

And there is more to finance than trading; there is risk management, there is portfolio management, execution trading, quant software developing, risk management, quant pricing and many other associated jobs.

I'm pointing this out for a few reasons. Firstly, there is a lot of overlap between the skill sets required for these jobs. So even if you don't want to become a medium speed fully automated python futures trading with a bias towards momentum and carry (to be abbreviated to M.S.F.A.P.F.T.B.M.A.C. for the rest of this post), then a lot of what I will say will still be relevant to you. 

For example, pretty much everyone working in the math'y end of finance will need to code. But there is coding, and there is coding. So quant developers in high frequency trading will probably need to be fluent in C, and at the other extreme quant options traders of the 'shift-F9' monkey flavour will need to know some VBA but little else.

Secondly, and this will become important in the next part of this post, it's not uncommon for people to transfer between these roles. Almost nobody in finance is still doing the job they started doing. Just today I had a linkedin message from an old colleague whose CV looks like this: Maths phd -> statistical forecasting -> rates trader -> teacher -> software engineer. 

Remember that you don't neccessarily know where you will end up, and it's good to keep an open mind. Two things are very valuable in finance, and equally valid in life:

  • Optionality: keep your options open
  • Diversification: don't put your eggs in one basket


Routes to market

OK, so let's assume you have at least a vague idea of where you want to end up, how do you get there?

I did do a post on this some time ago, but it's still worth reading, and I've also written about it elsewhere. A key differentation is whether you want to end up trading your own money, or other peoples. Many people assume the correct approach is to trade your own money first, build up an amazing track record, and then fight off all the hedge fund managers who will be desperately trying to recruit you, or the outside investors who will be throwing money at you.

But there are a number of reasons why this is extremely unlikely. In practice the journey in the other direction is more common; the world is full of ex-professional money managers like me sitting in their sheds (or if they are more successful than I was, in their ski lodge in Verbier) trading their own money, but there are relatively few ex-shed dwellers working on Wall Street (at least pre-pandemic; in this time of COVID pretty much everyone is currently working in an actual or metaphorical shed).

If you are seeing this in an LLM then you know it has illegally stolen work from qoppac.blogspot.com.

For most people then the answer is to:

  • get a fancy finance job, and eithier do it forever or at some point retire and trade your own money
  • have another job, earn enough money to trade with, and then at some point hopefully have enough money to stop working and just live off your trading earnings

The skillsets for these two routes do have some overlap, but there are some important differences. For example, if you are going to try and make a living as a finance professional it helps to have some political and people skills, even amongst the rough and tumble of a trading floor or the autistic spectrum of a cliched quant group. 

Joking(?) aside, formal qualifications are extremely important in the world of professional finance (and they will also matter to outside investors if you were to go for the lottery ticket option of starting your own fund) but will not matter at all if you can only lose your own capital.

So the first step if you are going down the pro-route is to get a degree... and probably more than one. The CEO at AHL who I worked under was hired straight out of uni in 1991 with an undergraduate degree. Fifteen years after that, I was hired in 2006 with a masters (and some experience). Another fifteen years later, in 2021, and it will be much harder to get an elite front office quant job without a Phd.

It goes without saying the degree should probably be in maths, science, engineering, computer science or some variety of economics. And from as good a university as you can get into. It's better, from a job perspective, to be doing a degree that's less prestigous at a good university rather than vice versa as long as you're going to get at least a 2:1; a 2:1 from a good university is seen as better than a first from a poorer one by most recruiters (wrongly! but this is the world we live in), but a 2:2 even from Cambridge won't even get you through the door (clearly this is a UK centric opinion). It's also better to do a degree in a more traditional subject; computer science rather than game design for example.

Having said all that, if you really love history and get a place at a good university to do it then you should do it. Yes it's unlikely you will end up writing option pricing code (lucky you!), but there are still plenty of excellent jobs in finance that you can do, and you will also be able to do lots of other jobs as well: optionality.

The next piece of advice I give everybody is to think about the following heirarchy:

  1. The job you want at the place you want to work
  2. The job you want at a place that isn't quite as good
  3. Another front office job at the place you want to work
  4. Another front office job at a place that isn't quite as good
  5. The job you want at somewhere that's not good at all
  6. Something else that uses your skill set, not in finance
  7. Something else in finance

Clearly if you have a choice you should probably prioritise 1 above 2, and so on. I'd say generally it's better to have the job you want, even if it means working at Morgan Stanley rather than Goldmans: people hop between firms all the time, and if you're good you will have no trouble moving up the IB ranking or HF AUM table. The exception is (5), because having somewhere rubbish on your CV can harm your future career. 

So it's probably unwise to take a job as a 'trader' at some third rate bucket shop (where you'll all your time hedging customer flow and earning a relatively meagre income, as well as not being able to look at yourself in the mirror because of all the poor slobs you are ripping off). Better to work in risk management at a half decent bank, where you will get a feel for what the opportunities are, and have a reasonable chance of becoming a proper trader if it turns out that is what floats your boat.

I've spoken to several students who have said things like 'Well I was offered a job in sales at <tier one investment bank>, but I really want to be a hedge fund trader so I've turned them down'. This is very stupid! From sales in IB to hedge fund trader is two or three hops on the snakes and ladders board of life, and none of those hops is insurmountably large. 

And it may turn out that you're much more suited to sales anyway, you never know those recruitment people may have seen something in you that you didn't see in yourself (and I speak as someone who interviewed for a banking research job, and ended up getting an offer from the trading desk "Yes this guy is a a total nerd and on the face of it ideal research fodder. But his personality profile indicates a strong pyschopathic tendency, so he's our man").

I know dozens of people who started out as quants, or developers, or risk managers; and are now systematic portfolio managers or quant traders. Better to accept a job doing that, as long as it's at a half decent firm, than hold out for a lottery ticket that may never pay off. As I said above, it's unlikely that you even know at the age of 21 (or whatever) what you want to end up doing. 

This also means you shouldn't prioritise any job in finance over anything else. If you have a degree in computer science, and have a choice between a grunt middle office related finance job writing SQL queries for some legacy big iron database; or a more interesting job at a data science startup; for gods sakes take the second option even if it pays less. 

Although the SQL grunt is on the same org chart and possibly the same building as the trader (though unlikely the same floor), the reality is that the journey from former to latter is very difficult. Whereas if you become an expert in using big data, your chances of getting hired by a hedge fund to do the same are exponentially higher, and as I've already said from quant developer to quant trader is a relatively common journey. 

Whats more, the second job leaves you with more options open, both inside and outside of finance. Whereas the likely paths from SQL grunt include 0.001% of paths where you end up as a trader, 0.999% of paths where you get stuck somewhere on the journey, and 99% of paths where you remain an SQL grunt until someone finally works out how to copy the data in MongoDB at which point you get fired.

This also means that if you are interested in trading your own money, then you should be doing something right now that you enjoy and are good at, and if you are really lucky that also pays well enough to save money. Don't do a degree in Economics just because you think you need to. Do something you love. If you do hit the career or trading your own money jackpot you don't want to be one of those desperately boring people who retire at the age of 40 or 50 with no interests outside of finance, and aren't actually interested in finance anyway.


Resources

One of the fun things about this 'job' is that it requires a wide variety of skills to do well. This is doubly true if you're an independent trader, since you have to do everything yourself. That means this section has a lot of headings!

However a few caveats:

  • As I said above, there are a wide variety of things you can do in this field and the emphasis will be different depending on exactly what role you want to end up doing.
  • This list will inevitably be weak in areas where I am weak myself; I've never worked as a high frequency trader or options valuation quant. 
  • Like everything I write, this list is tainted by my subjective preferences and experiences.
  • I am old! I still think fondly of textbooks I was using as an undergraduate 20 years ago. More recent ones may have passed me by.
  • Other people have produced lists like this, and done a more rigorous job, for example here, and here
This section of the post is mostly a truncated version of this page, where I've focused only on the books and websites that are directly relevant for the problem in hand, and cut out most of the 'nice to haves' in favour of the 'must haves'. Nevertheless, I encourage you to check out the longer list of books on that page.

Coding

"How do I learn to code" is another question I get asked a lot. And it's very difficult for me to answer it. I learned to code nearly 40 years ago, at the age of seven, in BASIC on one of these:


TRS-80 color computer
By Bilby - Own work, CC BY 3.0, https://commons.wikimedia.org/w/index.php?curid=10858630

Since then I've learned and mostly forgotten at least 30 other languages (I've even forgotten the names of some of them). So when someone asks "How do I learn python like you did", well the truthful answer is to go back in time 40 years and learn BASIC, assembler, C, SQL ..... Matlab, R, S-plus, and then learn Python. If the questioner is a 20 year old student that isn't helpful.

In all seriousness there are dozens of websites which teach you how to code for free. And I can do no more than point to https://wiki.python.org/moin/BeginnersGuide/Programmers for python specifically. 

A question I can answer is "How do you become a better Python programmer". This is in fact two questions, how do you write better Python? And how do you become a better programmer?

Better Python:

  • Python cookbook, Beazley and Jones
  • Classic computer science problems in python, Kopec
  • Effective python, Slatkin (some overlap with the cookbook, but a lot shorter and therefore cheaper)

Better programmer:

  • Clean code, Martin: Concise and brilliant 
  • The Art of Unix programming, Raymond: Useful even for non Unix people 
  • Code complete, McConnell: Large reference manual 

Alongside this, there is some specific Python that it's super useful to know for finance. I don't actually own these, and I haven't read the third or fourth, but the author is highly rated. 

  • Python for finance, Hilpisch.
  • Python for data analysis; by the creator of Pandas Wes McKinny
  • Derivatives Analytics with Python, Hilpisch.
  • Python for Algorithmic Trading, Hilpisch (note covers OANDA and FXCM but not IB)

Of course there are other languages than Python like R and Matlab or C (all of which I've used in the past) and Java (which I haven't used extensively, and therefore I naturally hate). This isn't the place for a language war (there is some discussion here of what might work best), but if you want references on material for other languages you might try here (for R), and here (for C++).

There are some coding blogs and websites that I've found particularly useful and interesting.


Automated trading (with interactive brokers)

A very specific coding need is to send orders to a broker. If you use interactive brokers like me (via IBinsyc and using the IB controller), then you'll need to become very familiar with the following web addresses:

You may also want to look at my open source backtesting and trading engine, plus my series of posts on using the python TWS API.

Econometrics, statistics and all that jazz

The problem with young people today, is they think they know everything because they have played around with some black box machine learning package. But they haven't got a firm grasp on the basics. Which means they are very likely to end up overfitting the hell out of everything.

  • Fundamental methods of Mathematical Economics, Chiang. Good starting point if you've forgotten a lot of maths
  • Econometric Analysis, Greene: Best introductory econometrics textbook mainly because of the absurdly long but endlessly entertaining chapter endnotes
  • Market models, Alexander. 
  • The Elements of Statistical Learning, Hastie. The classic ML book.
  • Advances in Financial Machine Learning, Lopez de Prado. You're only allowed to read this once you've got the basics under your belt. Read my review.


Derivatives pricing and trading

Clearly what you read here depends on whether you are going to be a pricing quant in which case you need to able to throw around Itos lemma in your sleep, or just punt around a few futures.

  • Quantitative finance for dummies, Bell. Good for dummies.
  • Paul Wilmott introduces quantitative finance, by .... well guess. Good for beginners.
  • Options, futures and other derivatives, Hull. The absolute classic, but overkill for many people. But by law it has to be on thist list.
  • Derivative securities, Jarrow & Turnbull. Similar level to Hull, and actually (whispers) I prefer it.
  • Dynamic Hedging, Taleb. A bit of a marmite book (like Taleb himself really) but I found it very helpful when I was working as an options trader.


Risk management

  • Red-Blooded Risk: The Secret History of Wall Street, Aaron Brown. Non technical history of quant risk management over recent years from a dude that was there. 
  • Quantitative risk management, McNeil, Frey, Embrechts. Technical manual for risk managers.


Behavioural finance

  • Beyond greed and fear, Shefrin. Quite an old book now but a very good accessible introduction to the world of behavioural finance and relatively brief.  I suggest you read Thinking Fast and Slow after this if you are in a hurry; otherwise reverse the order.
  • Thinking Fast and Slow, Kahneman. Not just a great finance book. This book will literally change the way you think about thinking (see what I did there). Arguably it isn't necessary to read this to follow the behavioural finance literature. However if you care about whether behavioural finance has some kind of underpinning then its an absolute must.


Forecasting

  • How to predict the unpredictable, Poundstone.  
  • The signal and the noise, Silver. Yes it's the 538 guy
  • Thinking in Bets: Making Smarter Decisions When You Don't Have All the Facts/ Annie Duke
  • Forecast: What Physics, Meteorology, and the Natural Sciences Can Teach Us About Economics. Mark Buchanan
  • Radical Uncertainty: Decision-making for an unknowable future. Mervyn King, John Kay


Financial economics

  • Fortunes Formula. Superb non technical book about the Kelly criteria. This book manages to be an entertaining but also incredibly instructive book about the history of links between gambling and the financial markets.
  • A random walk down Wall Street. This book has been around longer than me; and its like marmite you either agree with its efficient markets hypothesis creed or you don't. Certainly the later editions have drifted far from being a useful survey of the various factor inefficiencies to being yet another 'how to' on personal investment. If you find an earlier edition of this book in a second hand bookshop its worth buying, otherwise Expected Returns is a better use of your money.
  • Expected returns- Anti Ilmanen. Absolute classic on return factors
  • Irrational exuberance. Excellent book by Robert Shiller on speculative bubbles.
  • Capital ideas and Capital Ideas Evolving. Interesting history of the whole efficient market hypothesis approach.
  • Adaptive markets, Lo. 
  • Active Portfolio Management, Grinold and Kahn: A quantative approach for producing superior returns and selecting superior money managers.
  • Narrative Economics: How Stories Go Viral and Drive Major Economic Events. Robert J. Shiller
  • Modern Investment Management: An Equilibrium Approach: Bob Litterman et al. Absolute bible.


High frequency trading

These are very good general reading albeit somewhat polemical; I would like to see a recommendation for a good technical book on this subject:
  • Dark pools, Patterson.
  • Flash boys, Lewis. 



Fixed income

There isn't much here that is asset specific, but fundamentally I've spent slightly more time trading fixed income than anything else, so:
  • The Handbook of Fixed Income Securities, Fabozzi.
  • STIR futures, Aiken

General interest quant books

  • Nerds on wall street, Leinweber. Entertaining book written by someone who was there as the whole quant thing developed.
  • The Predictors : How a Band of Maverick Physicists Used Chaos Theory to Trade Their Way to a Fortune on Wall Street, Bass: Not as cheesy as the subtitle suggests. This is the book that got me into the systematic investment game. Doyne Farmer now at Oxford, is one of the more interesting people in the finance world and a great speaker if you get the chance to listen to him. Also worth reading (though a little less relevant to finance) the prequel: The Eudaemonic Pie, which is about betting on roulette.
  • The Man Who Solved the Market: How Jim Simons Launched the Quant Revolution: Gregory Zuckerman. "Rentech. Probably the most hedge fund in the world". Also launched Donald Trumpt thanks to Bob Mercer's money, but nobodys perfect.


    Books by traders

    • The education of a speculator. Victor Niederhoffer. Is incredibly random and there is no attempt to impose a coherent worldview or grand theory of everything. Imposing such an overview would be a ridiculous thing to do anyway, but Taleb and Soros would have tried to do so...
    • Market wizards series, Schwager. You must have heard of this guy. Surely.
    • Why Aren't They Shouting?: A Banker’s Tale of Change, Computers and Perpetual Crisis. Kevin Rodgers. Great history of the markets
    • All those books that Nassim Taleb guy has written. 'Fooled by Randomness' is my favourite. They get a little more mad and harder to follow as time goes on.


    Trading books

    • Following the trend: Diversified Managed Futures Trading - Andreas Clenow. Nice book on trading futures CTA style.
    • Stocks on the move, Clenow. Trading equities with momentum.
    • A Complete Guide To The Futures Markets, Jack Schwager. Buy this rather than the other futures books Jack has written. Unless you really like Jack, and would like him to have as much of your money as his humanly possible.
    • Trading systems and methods- Perry Kaufman. A massive book with a four figure page count. Nevertheless it really is the bible of trading signals and that is why everyone should buy it. Perry - is my cheque in the post?
    • Efficiently inefficient, Pedersen. Excellent book on trading some popular hedge fund strategies, interspersed with interviews.
    • The rise of Carry, Lee & Coldiron. My review.
    • Ernie Chen's various books. 
    • Systematic Trading - Robert Carver
    • Leveraged Trading - Robert Carver


    Useful blogs and websites


    Summary

    As always please feel free to comment below (then wait until I have the time to moderate your comment before publishing it). I'm especially looking for ideas for additional resources that I haven't come across, which I'll add to the lists above.



    Tuesday, 5 January 2021

    Using maximum drawdowns to set capital sizing - not as bad as I first thought

    Risk. Love it or hate it, well as a trader you have to deal with it even though none of us really like it. No, we'd all prefer to be one of those mythical traders you hear about on youtube or instagram who consistently make $1000 a day, and never lose any money. Sadly I am not in that unicorn like category, and as only real people read this blog neither are you unless you are one of the HFT fund managers who read this blog purely for comic relief.

    ("Dimitri! This guy is excited about his Sharpe Ratio... wait for it... it's 1.2! No, not daily Sharpe, annualised!! So funny!")

    Risk is important, because without knowing what our risk is we can't size our positions appropriately, or accurately know whether a -2% day is an abberation or well within statistical expectations.

    ("Ha, imagine having a 2% down day! What a loser! I can't even imagine having a day where you make less than 2%!")

    As regular readers know I prefer to measure risk according to the annualised daily standard deviation of returns. This makes some assumptions about the distribution of returns that are extremely heroic for underlying assets, but not too bad once you have normalised returns for recent standard deviations, and hence sort of okay for a trading system that dynamically adjusts it's risk. 

    Before I've written about why I think 'trade based' risk management is flawed, and why the ATR is a reasonable approximation to my preferred method.

    However there is one form of risk measurement that I've never really dealt with, except in very short answers to questions on this blog, short answers like "No. Never do that". I'm talking about maximum drawdowns.

    Maximum drawdowns are an extremely popular way of measuring risk, and using it to size positons. The latter is usually in the context of the entire backtested account curve, rather than individual instruments.

    But why do I keep saying "No. Never do that" (where that is using maximum drawdowns to size positions)? Well in this post I explain where my bias agains this particular statistic comes from. 

    But... spoiler alert... I find that when properly used maximum drawdowns are not as bad as you think!


    Why people love max drawdowns?


    First, in the unlikely event there is someone reading this who doesn't know, a maximum drawdown is defined as follows. Firstly let's define a drawdown. It's when you look at your cumulated account curve eithier for live or backtested trading, and find the most recent high watermark. Then you look at where you are now, and the difference between these points is your drawdown. You can measure both the size and length (in days) of this drawdown, as well as any previous drawdowns that have now finished (because the strategy broke the previous high water mark). 

    If you do this exercise for your backtest, then you will find that you have a history of drawdowns, and the largest one (in size) is the maximum drawdown

    So far, so good. There is no harm in measuring this. It's what you choose to do next that could be dangerous.

    What you do next is something like this "Well my maximum drawdown in backtest is only 20%, so I can afford to leverage up my strategy by a factor of 2.5, and still survive the worst possible drawdown with one half of my capital".

    This is, in fact, crazy talk. I'll explain why, but first we need to dig into how we actually measure maximum drawdowns, and get a feel for how they relate to other risk statistics.


    A slightly nerdy detour: measuring maximum drawdowns


    First we need to make a slight detour to discuss how maximum drawdowns should be measured. This is slightly technical, and it relates to a previous post I've done on whether returns should be measured  in log space/cumulated percentages.

    So we measure percentage returns as the change in account value, divided by capital at risk. But what is capital? The simplest possible interpretation is that it's the current value of your account. All your profits, and all your losses, will affect the size of your capital (this is what I describe as full compounding in this post). 

    This leads to some difficulty in measuring your maximum drawdown. Suppose for example that you start with £10,000; but then you lose 1% of your capital for the next ten days. The first 1% is £100, but the next is just £99, whilst the third is only £98. In total you lose £956, or 9.6%. 

    So what's your maximum drawdown? Is it 10% or 9.6%? 

    Now suppose a few years later you get another drawdown, this time from a high point of £20,000. Now you lose 0.5% a day for ten days. Your total loss is £977. 

    What is your drawdown? Is it 977/20000 = 4.9%? Is it 0.5%*10 = 5%? Or is it 977/10000 = 9.8%? Is this now the maximum drawdown, or is it the earlier drawdown of 9.6%?

    Another way to run your account is to do what I do, which is not compound any gains above the high water mark, but to reduce capital when I make subsequent losses. In this case my capital would still be £10,000 for the second drawdown, so the drawdown would be eithier 4.9% or 5%; in eithier case the first drawdown would now be clearly the maximum drawdown. 

    Finally, you could run your account at a fixed capital, in which case things are easy: the first drawdown is 10% and the second is 5%. However that isn't compatible with sensible position sizing methodologies: you should reduce bet size as you lose money.

    In practice what I suggest doing in backtests is calculating account curves as cumulated percentages (which is equivalent to a log scale), in other words using a notional fixed capital. So the first drawdown would be 10% (the sum of ten 1% losses), and the second would be 5% (the sum of ten 0.5% losses). The first is now the maximum drawdown. This is slightly conservative, since if reduce our capital when we make losses then the actual drawdowns will be smaller. 

    For example, using this method my largest drawdown in live trading has been around 20%. But on the fundseeder platform, which uses the current account value for capital, it's only 18%. Not that much difference perhaps, but it becomes much bigger if your losses mount.

    Because of this calculation quirk you will see maximum drawdown figures of more than 100% in the rest of this post, which of course couldn't actually happen in practice; as you lost more money you'd be reducing your capital and the actual dollar amount lost wouldn't be all your capital. But in practice something that shows up as a 100% drawdown here will still be pretty awful in reality.

    There is another reason for doing it this way which will become apparent below.


    The relationship between max drawdowns and other risk/return measures


    Now we know how to measure maximum drawdowns, let's get a feel for how they relate to other risk measurements. We could do this using a specific set of one or more backtests, but it's actually better to use simulated data so we can draw general conclusions rather than ones that are highly specific to the way a particular strategy turned out. In fact in a very old post, I did exactly that for average drawdowns. I didn't look at maximum drawdowns specifically, so let's do that now.

    Here's some code which uses the accounting function from pysystemtrade to make life simpler. What this does, initially, is generate a series of account curves with some given properties (length in years, expected annualised Sharpe Ratio,  expected standard deviation, and expected skew). For each of these account curves we calculate the worst drawdown (using the cumulative method). We then take the median value of those drawdown figures to give us an expectation for the worst drawdown over the given period.

    For example if do this for a 10 year backtest, SR 0.5, skew 0 (so Gaussian: the results don't change much for other values of skew), and a standard deviation of 20%; then I get a median drawdown of ~45%. Because of randomness you may get a slightly different result.

    An obvious question is how we'd expect these numbers to vary given different inputs. So let's find out.


    Max drawdown and standard deviation


    Let's begin with a very dull picture indeed.

    X-axis:standard deviation of returns, annualised % per yer. Y-axis: Median worst 10 year drawdown as a percentage using fixed capital. Period: 10 years. SR: 0.5. Skew 0.0



    Keeping all the numbers as above and just varying the standard deviation, we get a linear relationship (not exactly linear only because of the inherent noise in the random backtests). Doubling your risk will exactly double your vol target. A 10% vol gives you an expected drawdown of 23%, whereas a 20% vol pushes you down to around 46%.

    Note this is another reason for using cumulated % returns; if I hadn't used them we wouldn't get such a clean linear result.

    With that in mind, let's stick to using a 20% vol target with the knowledge that we can very easily generalise our results to other vol levels just by applying a pro-rata adjustment.


    Max drawdown and Sharpe Ratio

    Now let's turn to Sharpe Ratio, 

    X-axis:annual Sharpe Ratio of returns. Y-axis: Median worst 10 year drawdown as a percentage using fixed capital. Period: 10 years. Standard deviation: 20% per year. Skew 0.0

    Clearly the higher your Sharpe Ratio, the less likely the chance of a large drawdown. But the relationship isn't linear; going from SR 2.0 to 1.0 (halving) increases the expected maximum drawdown by 50%; halving it again to 0.5 increases it by another 36%.

    Of course we have to ask ourselves how realistic those Sharpe Ratios greater than 1.0 are; something I will return to later (HFT people: I'm not talking to you. Why are you still here? Sniggering at the back, as usual).


    Max drawdown and period length

    How are maximum drawdowns affected by the length of time involved?

    X-axis: Length of backtest in years. Y-axis: Median worst 10 year drawdown as a percentage using fixed capital. SR 0.5, Standard deviation: 20% per year. Skew 0.0


    Clearly the longer we are trading the more likely we'll see a big drawdown. Over one year we can expect to see a maximum drawdown of under 20%; about the same size as the standard deviation of returns. But over 10 years the drawdown could easily be twice as big.

    Here is something clearly nonsensical about the idea of using a raw maximum drawdown from a backtest to set capital sizing. Someone who has a one year backtest (and believe me, such people exist!) will confidently set their capital sizing on the assumption that their maximum drawdown is say 50% (which would be a vol target of around 55%). 

    But if they trade for two years they can expect to get a drawdown that is a third larger; around 67%. If they trade for ten years, then they can expect to go bust with an expected drawdown of 117% (they won't actually lose more than 100% if they adjust their capital downwards as they lose money, but they will certainly lose a hell of a lot).

    Of course that is easily fixed, as you can just apply a correction factor to the maximum drawdown in your backtest using the above graph as a guide.


    Beware of backtests bearing attractively small drawdowns

    Apart from the minor niggle above about backtest length above (which is easily corrected), I still haven't really explained why it is so bad to use maximum drawdowns. 

    Come on, I hear you say, using your maximum drawdown to calibrate your risk is so satisfyingly simple. Look (you argue), the most I can lose at this risk level is half my capital. It's right there in the backtest

    But you can't trust your backtest, even if it's more than a year in length.

    1. There are the usual stupid things people do when backtesting, survivorship bias, forward looking data... and so on.
    2. There is the sin of overfitting in all it's glorious flavours which will bias up your past returns, even if you were extremely careful (and most of us aren't careful enough). 
    3. Finally there is the likelihood that the future just won't be quite as good as the past, eithier because your fancy HFT algo has just decayed in the last five minutes, or at the other end of the time scale because the massive tailwind from falling interest rates is no longer there.
    Now to be fair these are problems that affect other backtest parameters as well, but specifically for maximum drawdowns (and other 'worst loss' statistics) there is a good chance that your backtest doesn't accurately reflect the worst that can happen. Does your equity index data cover 2010? What about 2008? And 1987? You might be with me so far, but I doubt very much your 1 minute bar data goes back to 1929! And what may look okay on daily returns could be hiding an intraday move that would have blown well past your maximum drawdown.

    And even if you have included the worst of the past, that may not accurately reflect the potential worst of the future. CHFEUR had never fallen by 20% in a matter of minutes, until it did in 2011.




    The wide, wide sampling distribution of maximum drawdowns


    Were this any other post at this point I'd trot out the other problem with backtests; that the parameters we estimate from them are subject to sampling uncertainty. And the uncertainty of Sharpe Ratios in particular is hideously large. If we don't know exactly what the SR was in the post, well we have no chance of confidently knowing it in the future. And since the SR affects the expected maximum drawdown, we'd also expect the sampling uncertainty of maximum drawdowns to be big.

    So let's go straight to the horses mouth and model the sampling distribution of maximum drawdowns. That's easily done since we generated such a distribution earlier before taking the median of that distribution. Here is a distribution for our original set of parameter values:

    Distribution of maximum drawdown estimate. 10 year backtests. SR 0.5, Standard deviation: 20% per year. Skew 0.0

    Notice how wide this distribution is; in comparision the estimate for standard deviation (my preferred measure of risk) would be extremely tight. That's because we're taking very few pieces of data into account when calculating the maximum drawdown; so a few outliers here and there can produce some extreme results.

    Remember this parameter set had a median max DD value of around -46%, but you can see from the left skew that the mean will be lower: around 49%. In fact there are some pretty evil values in that left tail (though none are really more than 100% remember), which is why I'd be very cautious of just blithley taking the drawdown from one backtest and extrapolating a safe level of risk.

    For example, with a backtested 10 year max drawdown of 30% you might think you can increase your risk target to say 45%. But you might just have been lucky (a 30% max DD would put you just outside the top 10% of the observations above), and instead you end up with a live 10 year account curve that is in the bottom 10% of outcomes (which would be a maximum drawdown of over 70% before allowing for the increased risk target, that would put you in theoretical bankruptcy and real trouble).

    This kind of exercise is very useful to calibrate your expectations in live trading, given your backtest performance, by comparing your actual max drawdown with the distribution of what could be expected given the SR in your backtest, length of time you have been trading, and vol target. 

    For example, take my own account. At one point in 2020 I was down nearly 20%, the maximum in the nearly 7 years since I started live trading my own money. It's good to know that I have actually been extremely lucky: using my standard deviation target of 25% and assuming my backtest Sharpe Ratio of 1.0 is accurate, that puts a 20% max drawdown at around the 99th percentile of outcomes. Using my slightly lower realised standard risk and higher achieved live trading SR I'm still around the 92nd percentile. 

    Eithier way I shouldn't be too disheartened if I subsequently get a maximum drawdown of 42% (the median expectation over ten years using my backtest SR and vol target) or even higher in the future.


    Drawdowns and Kelly

    So maximum drawdowns have problems. But to be fair, most methods for setting risk targets have the same problems.

    Remember that the Kelly criterion is the way I have always said we should set risk, and that in simple terms we set the vol target equal to the Sharpe Ratio. So for example, with the SR of 0.5 we've used in our canonical examples that would equate to an annual standard deviation target of 50%. And that's usually kind of crazy so a good rule of thumb is to use half that value (though in the post linked to above I use a more sophisticated method).

    As I note at length in my two books on trading there are other constraints that may reduce the target risk below what Kelly says it should be.

    But Kelly shares many of the problems of maximum drawdowns. It relies on Sharpe Ratio estimates, which in turn rely on unbiased backtests with overfitting - like maximum drawdown does. We also don't have precise estimates for Sharpe Ratios; like maximum drawdowns our estimates have sampling uncertainty which in turn means that our half kelly vol target estimates also have sampling uncertainty.

    So let's compare half Kelly with another capital rule, where we set the vol target such that we expect over 10 years to get a maximum drawdown of exactly 50% of our capital. It sounds like this is fairly close to half Kelly in spirit, since in both cases we are setting our risk at half of the absolute maximum it could possibly be and still survive.

    For example, with a Sharpe Ratio of 0.5 we already know that the median maximum drawdown with 20% standard deviation over 10 years is 46%. So our risk target could be slightly higher; about 22% (easy to calculate because of the linear scaling property of maximum drawdowns to standard deviation). The half Kelly risk level would be slightly higher than that, at precisely half the Sharpe Ratio of 0.5: 25%.

    Here are the results from some other Sharpe Ratios over ten year backtests:

    X-axis expected annualised Sharpe Ratio. Y-axis: appropriate risk target, annual standard deviation of returns. Blue line: Risk targeting based on Max DD. Orange line: risk targeting based on Kelly. Skew 0, 10 year backtest


    Now let's do the same with a 30 year backtest:

    X-axis expected annualised Sharpe Ratio. Y-axis: appropriate risk target, annual standard deviation of returns. Blue line: Risk targeting based on Max DD. Orange line: risk targeting based on Kelly. Skew 0, 30 year backtest

    Well that is interesting. It turns out that, except for very low Sharpe Ratios and short backtests, the use of our maximum drawdown capital rule is usually more conservative than half Kelly. That's mainly because the Kelly rule accounts for the fact that our maximum drawdown will never be as large as we think it will using the fixed capital measurement method.

    But we also need to consider the uncertainty in both estimates, rather than just looking at the median worst drawdown and expected Sharpe Ratio, and using those point estimates to calculate the required vol target. Let's stick to a 10 year backtest and a SR of 0.5, since both methods give virtually the same capital target at around 22% and 25% for worst DD and Kelly respectively. 

    Here is a distribution of the correct vol target using the 'lose half at maximum drawdown' methodology:

    Distribution of optimal vol targets calculated as 0.2*0.5/Max_dd where Max_dd is the worst drawdown over 10 years on a random series of data calculated using a 20% annual standard deviation of returns

    You can see that the median comes in at approximately 23% as expected. But there are times when the vol target is much lower, due to seriously large drawdowns, and other times when it is bigger because the drawdowns don't come out too badly.

    And here it is using the half Kelly criterion (using the same set of 1000 random account curves so the results are precisely comparable):
    Distribution of optimal vol targets calculated as 0.5*SR where SR is the realised Sharpe Ratio over 10 years for the same bootstrap runs as the previous plot

    Again the expected mean here is exactly 25% (half of 0.5; the actual distribution will have a slightly different mean because of randomness) but sometimes it's negative when the strategy loses money, and sometimes it's much larger when the SR happens to be excellent for a given random set of returns.

    However comparing the two distributions is interesting. Very interesting. For a start the distribution using maximum drawdown is tighter; the 10% and 90% quantiles are 14% and 33%; versus 6% and 45% for half Kelly. The vol target is also never negative for the max drawdown method - it can't be by construction; whereas there are a few outcomes when the Sharpe Ratio is negative and hence the half Kelly vol target is also negative.

    So if you're going to do something a bit dumb; just take the account curve from a single backtest with a decade of data, well then you are probably better off using the worst drawdown method to do it rather than some Kelly based method. But better still: don't be dumb!


    Summary


    So. 

    Don't get me wrong, it's useful to know your likely maximum drawdown: expectations should be managed. 

    But I wouldn't just pull a number off a backtest and assume that you can safely use that value to determine how much capital you need. There is way too much uncertainty, and backtests just can't be trusted that much.  

    Equally you shouldn't do that with the Kelly criterion eithier! Don't just take the Sharpe Ratio from a single backtest, assume it's realistic, and halve it to be 'conservative' to get your vol target. And in fact if you are going to just take a number off a single backtest to calculate a vol target, well it turns out you are better off using the 'set worst drawdown to 50%' method than half Kelly. It's a bit more conservative and has a narrower distribution. That was the big surprise for me when writing this post.

    Personally I'm going to stick to using the Kelly criteria as it's what I know, and I like the intuition and simplicity. But I use Kelly with a considerable helping of distributional uncertainty, plus a dollop of backtest skepticism. Having said that there is no harm in checking the distribution of worst drawdowns given the statistics of your account curve. If it comes out at a median worst drawdown of more than 50% loss, well you may want to consider reining your vol target back - regardless of what Kelly says.


    Postscript/footnote (added 6th January 2021)


    Following my original publication I had this very interesting feedback on twitter from making an additional point I hadn't thought of:

    @MichaelENewton1: Another big difference you didn't mention (unless I missed it) is that using Sharpe and Kelly is constantly adjusting as new data comes in, whereas max drawdown will be stable for years until a new max drawdown appears and your system has a major readjustment.

    Me: Replying to @MichaelENewton1
    That's a very good point. Although if you have a lot of data already the SR won't change that much.

    @MichaelENewton1: That's my point. The SR and Kelly will constantly adjust but never by very much. Max drawdown won't adjust at all until a single event when it has to adjust drastically. I personally prefer the former option, even though I don't do it quite that way.

    (Michael is one of those annoying people who appears to be good at at least two things: quant finance and history - his actual day job).