0% found this document useful (0 votes)
47 views2 pages

Num Py Jarque Bera

The document discusses using the Jarque-Bera test to select stocks with nearly normal return distributions for analysis using the Capital Asset Pricing Model (CAPM). It provides code to screen stock prices based on their Jarque-Bera p-value and calculate returns. It then estimates expected returns using the geometric mean and fits the Security Market Line to determine undervalued stocks above the line.

Uploaded by

ivan2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views2 pages

Num Py Jarque Bera

The document discusses using the Jarque-Bera test to select stocks with nearly normal return distributions for analysis using the Capital Asset Pricing Model (CAPM). It provides code to screen stock prices based on their Jarque-Bera p-value and calculate returns. It then estimates expected returns using the geometric mean and fits the Security Market Line to determine undervalued stocks above the line.

Uploaded by

ivan2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ivanidris.

net

Jarque Bera, the CAPM and undervalued stocks


The Capital Asset Pricing Model ( CAPM ) links the expected return of assets to their risk. A linear fit of this relationship gives us the so called Security Market Line ( SML ). One of the problems with this model is that it assumes a normal distribution of returns. The python scikits.statsmodels.stattools module provides a Jarque Bera normality test, which allows me to select only the stocks which have nearly normal return distribution.

Jarque Bera test


I check with the Jarque-Bera test for normality. Normality implies predictability. Predictability leads to safety. Safety leads to joy. The code below screens for a certain Jarque Bera test p value of open, high, low and close prices returns.
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 ... def get_returns( arr ): beforeLast = len( arr ) - 2 return diff( arr[ : beforeLast] ) / arr[ : beforeLast - 1] def get_pvals( returns ): pvals = [] for i in range(0, len( returns ) ): (jb, pval, skew, kurtosis) = jarque_bera( returns[ i ] ) pvals.append( pval ) return pvals def check_pvals( pvals ): for i in range(0, len( pvals )): if pvals[ i ] < float( argv[ 1 ] ): return False return True ... returns = [] returns.append( returns.append( returns.append( returns.append( get_returns( get_returns( get_returns( get_returns( c o h l ) ) ) ) ) ) ) )

output = [] pvals = get_pvals( returns ) if check_pvals( pvals ): ev = geomean( returns[ 0 ] )

...

The expected return is estimated by the geometric mean function below. Actually it calls a scipy.stats function with positive values. This requires a bit of cheating in the form of taking the absolute value etcetera.

1 def geomean( arr ): 2 filtered = abs( arr ) 3 indices = flatnonzero( filtered ) 4 filtered = take( filtered, indices ) 5 6 return scipy.stats.gmean( filtered)

CAPM
So we need to have the slope and intercept of the security market line.
1 2 3 4 5 6 7 8 9 10 11 12 13 ... returns = [] returns.append( get_returns( c ) ) ev = geomean( returns[ 0 ] ) evs.append( ev ) stdC = std( returns[ 0 ] ) stds.append( stdC ) A = vstack([stds, ones(len(stds))]).T (p,residuals,rank,s) = linalg.lstsq(A, evs) a,b=p ...

After that its just a question of selecting the points above the SML, which should be undervalued

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

You might also like