Simple question - what would be the fastest algorithm for calculating retrospective maximum drawdown ?
I've found some interesting talks but I was wondering what people thought of this question here.
|
Simple question - what would be the fastest algorithm for calculating retrospective maximum drawdown ? I've found some interesting talks but I was wondering what people thought of this question here. |
|||||||||||
|
|
Zipline, the opensource python backtester, has a batch and iterative implementation for max drawdown. Here is the batch: https://github.com/quantopian/zipline/blob/master/zipline/finance/risk.py#L284 Here is the iterative: https://github.com/quantopian/zipline/blob/master/zipline/finance/risk.py#L578 disclosure: I'm one of the zipline maintainers |
|||
|
|
|
(After the clarification, this answer is no longer relevant) Expected maximum drawdown is going to be highly sensitive to your choice of SDE, and to your calibration of it. Therefore you should play with a variety of parameterizations to estimate your model error. So far as efficient computation goes, we can regard this as a payoff very similar to a lookback option (much as in the PDF you linked). As with lookback options, the first instinct is to price them using Monte Carlo techniques, but one can actually do so much more quickly using a multi-level PDE solver, at least for sufficiently simple SDEs. The way a 2-level PDE solver works for a payoff like this is that, rather than having a grid of $(S,t)$ values on which you run your difference equations and boundary conditions, you have a grid of $( \{M,S\}, t )$ values, where $M$ represents the maximum achieved so far. Obviously there are some new boundary conditions that go with it, for example that $\frac{\partial M}{\partial S}=1$ at and above the line $S=M$. Differencing and updating on this grid, you ultimately end up with a value $V_{0,0}$ corresponding to today's maximum $M_0$ and stock price $S_0$. See section 5.3.2 of this pdf for how it works with lookbacks. Max drawdowns will be very similar. |
||||
|
|
|
I won't give you the answer delivered on a silver platter but hopefully the following will get your started: a) you need to define exactly over which look-back period you aim to derive the maximum drawdown. b) you need to keep track of the max price while you iterate the look-back window. c) you need to keep track of the min price SUBSEQUENT to any NEW max, thus each time you make a new max you need to reset the max low to zero (relatively speaking as a divergence from the max value) this should get you pretty easily to where you want to get without having to iterate the time series more than once. I disagree that a vectorized approach will solve this problem (@Pat, please provide an answer if you disagree I would be curious how you would approach this in a vectorized manner because the algorithm here is path-dependent). |
|||||||
|