How to optimize maximum drawdowns of stock returns Maximum drawdown is defined as the maximum decline from a historical peak. Obviously, this is a measure of risk as well. So some optimization is needed. Also I try to shoot below the open price with a new method.

Maximum drawdown optimization I attempt to optimize the maximum drawdown CAPM style in relation to the Volume Weighted Average Return, skewness of the returns and liquidity. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

... def maxDrawdown(arr): top = arr[0] maxDD = 0 for i in range(1, len(arr)): if arr[i] > top: top = arr[i] drawdown = (top - arr[i]) / arr[i] if drawdown > maxDD: maxDD = drawdown return maxDD

...

ev = average(returns, weights=v[:len(returns) ]) maxDD = maxDrawdown( c ) evs.append( ev ) maxDDs.append( maxDD ) S = stats.skew( returns skews.append( S )

)

vol = log( geomean( v ) ) vols.append( vol ) if returns[-2] > -1 * float(argv[1]): continue t = file.replace('.csv', ''), ev, maxDD, S, vol records.append( t ) ( a,b,residuals ) = fitline( maxDDs, evs ) ( aSkew, bSkew, residuals ) = fitline( maxDDs, skews ) ( aVol, bVol, residuals ) = fitline( maxDDs, vols ) for t in records: symbol, evC, maxDD, S, vol = t if evC > a * maxDD + b: if S > 0 and S > aSkew * maxDD + bSkew:

44 45 ...

if vol > aVol * maxDD + bVol:

Blind shooting I try to shoot below the open price with a new method. Starting with the close price of a day, I try extrapolating a low price for the next day. The steps of the extrapolation are: 1. Calculate relative daily spreads of the close and next day low price. 2. Estimate the per percentile probability that the projected value will fall within the open â&#x20AC;&#x201C; low range. 3. Use the optimal probability for the actual projection. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

... tomorL = roll(l,1) r = (c[:-3] - tomorL[1 :-2])/tomorL[1:-2] N += 1 for i in range(1,100): score = stats.scoreatpercentile(r, float(i) ) p = c[-3]/(1 + score) if not isnan(score): means[i] += score if p >= l[-2] and p < o[-2]: ratios[i] += 1 ratios = ratios / N ... maxr = max(ratios) indices = where( ratios >= maxr ) ...

Here are some plots based on the data in my historical prices database.

If you liked this post and are interested in NumPy check out NumPy Beginnerâ&#x20AC;&#x2122;s Guide by yours truly.

NumPyMaximumDrawdown

for i in range(1, len(arr)): if arr[i] &gt; top: top = arr[i] Maximum drawdown is defined as the maximum decline from a historical peak. Obv...

NumPyMaximumDrawdown

for i in range(1, len(arr)): if arr[i] &gt; top: top = arr[i] Maximum drawdown is defined as the maximum decline from a historical peak. Obv...