def breaks_cusumolsresid(olsresidual, ddof=0):
 resid = olsresidual.ravel()
 nobs = len(resid)
 nobssigma2 = (resid ** 2).sum()
 if (ddof > 0):
  nobssigma2 = ((nobssigma2 / (nobs - ddof)) * nobs)
 B = (resid.cumsum() / np.sqrt(nobssigma2))
 sup_b = np.abs(B).max()
 crit = [(1, 1.63), (5, 1.36), (10, 1.22)]
 pval = stats.kstwobign.sf(sup_b)
 return (sup_b, pval, crit)

def breaks_cusumolsresid ( olsresidual , ddof = 0 ) : resid = olsresidual . ravel ( ) nobs = len ( resid ) nobssigma2 = ( resid ** 2 ) . sum ( ) if ( ddof > 0 ) : nobssigma2 = ( ( nobssigma2 / ( nobs - ddof ) ) * nobs ) B = ( resid . cumsum ( ) / np . sqrt ( nobssigma2 ) ) sup_b = np . abs ( B ) . max ( ) crit = [ ( 1 , 1.63 ) , ( 5 , 1.36 ) , ( 10 , 1.22 ) ] pval = stats . kstwobign . sf ( sup_b ) return ( sup_b , pval , crit )
cusum test for parameter stability based on ols residuals parameters olsresiduals : ndarray array of residuals from an ols estimation ddof : int number of parameters in the ols estimation .