Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Stock selection with the mad CAPM and liquidity filtering

Ivan Idris The Capital Asset Pricing Model ( CAPM ) usually uses variance or standard deviation as a risk metric. I invented a slight modification of the model, which I call the mad CAPM ( well OK maybe I did not invent it, but I dont know if anyone else did ). M.A.D here is median absolute deviation not to be confused with mutual assured destruction or the other thing. It should be a more robust statistical measure of risk. The liquidity filter works almost the same way as the CAPM, but instead of trying to maximize expected return, the goal is to maximize liquidity. Liquidity is after all a good thing. So the plan for today is: 1. Screen stocks with the mad CAPM. 2. Screen stocks with the liquidity filter. 3. Profit!

The mad CAPM


The median absolute deviation of a sample is calculated by: 1. 2. 3. 4. Finding the median. Subtracting the median in the previous step from each element. Taking the absolute value of each difference. Determining the median of the absolute values.

The code.
1 def mad( arr ): 2 mdn = median( arr ) 3 4 return median( abs( arr - mdn ) )

and unit test.


1 ... 2 3 4 ... actual = mad( [ 1, 1, 2, 2, 4, 6, 9 ] ) assert actual == 1, 'incorrect mad' + str(actual)

Liquidity filter
The liquidity is estimated by the geometric mean of the daily volumes. So I apply the mad CAPM with this liquidity figure instead of the expected returns.
1 2 3 4 5 6 7 ... ev = geomean( returns[ 0 ] ) evs.append( ev ) madC = mad( returns[ 0 ] ) mads.append( madC )

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29

liq = geomean( v ) liqs.append( liq ) beforeLastReturn = c[ len( c ) - 2 ] / c[ len( c ) - 3 ] - 1 if beforeLastReturn > 0: continue t = file.replace('.csv', ''), ev, madC, liq records.append( t ) ( a,b,residuals ) = fitline( mads, evs ) ( aLiq, bLiq, residuals ) = fitline( mads, liqs ) for t in records: symbol, evC, madC, liq = t if evC > a * madC + b: if liq > aLiq * madC + bLiq:

...

If you liked this post and are interested in NumPy check out NumPy Beginners Guide by yours truly.

You might also like