<s> from statsmodels . compat . python import range <EOL> import numpy as np <EOL> from . _utils import _maybe_get_pandas_wrapper <EOL> def cffilter ( X , low = <NUM_LIT:6> , high = <NUM_LIT:32> , drift = True ) : <EOL> """<STR_LIT>""" <EOL> if low < <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> _pandas_wrapper = _maybe_get_pandas_wrapper ( X ) <EOL> X = np . asanyarray ( X ) <EOL> if X . ndim == <NUM_LIT:1> : <EOL> X = X [ : , None ] <EOL> nobs , nseries = X . shape <EOL> a = <NUM_LIT:2> * np . pi / high <EOL> b = <NUM_LIT:2> * np . pi / low <EOL> if drift : <EOL> X = X - np . arange ( nobs ) [ : , None ] * ( X [ - <NUM_LIT:1> ] - X [ <NUM_LIT:0> ] ) / ( nobs - <NUM_LIT:1> ) <EOL> J = np . arange ( <NUM_LIT:1> , nobs + <NUM_LIT:1> ) <EOL> Bj = ( np . sin ( b * J ) - np . sin ( a * J ) ) / ( np . pi * J ) <EOL> B0 = ( b - a ) / np . pi <EOL> Bj = np . r_ [ B0 , Bj ] [ : , None ] <EOL> y = np . zeros ( ( nobs , nseries ) ) <EOL> for i in range ( nobs ) : <EOL> B = - <NUM_LIT> * Bj [ <NUM_LIT:0> ] - np . sum ( Bj [ <NUM_LIT:1> : - i - <NUM_LIT:2> ] ) <EOL> A = - Bj [ <NUM_LIT:0> ] - np . sum ( Bj [ <NUM_LIT:1> : - i - <NUM_LIT:2> ] ) - np . sum ( Bj [ <NUM_LIT:1> : i ] ) - B <EOL> y [ i ] = Bj [ <NUM_LIT:0> ] * X [ i ] + np . dot ( Bj [ <NUM_LIT:1> : - i - <NUM_LIT:2> ] . T , X [ i + <NUM_LIT:1> : - <NUM_LIT:1> ] ) + B * X [ - <NUM_LIT:1> ] + np . dot ( Bj [ <NUM_LIT:1> : i ] . T , X [ <NUM_LIT:1> : i ] [ : : - <NUM_LIT:1> ] ) + A * X [ <NUM_LIT:0> ] <EOL> y = y . squeeze ( ) <EOL> cycle , trend = y , X . squeeze ( ) - y <EOL> if _pandas_wrapper is not None : <EOL> return _pandas_wrapper ( cycle ) , _pandas_wrapper ( trend ) <EOL> return cycle , trend <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import statsmodels as sm <EOL> dta = sm . datasets . macrodata . load ( ) . data [ [ '<STR_LIT>' , '<STR_LIT>' ] ] . view ( ( float , <NUM_LIT:2> ) ) [ <NUM_LIT:1> : ] <EOL> cycle , trend = cffilter ( dta , <NUM_LIT:6> , <NUM_LIT:32> , drift = True ) <EOL> dta = sm . datasets . macrodata . load ( ) . data [ '<STR_LIT>' ] [ <NUM_LIT:1> : ] <EOL> cycle2 , trend2 = cffilter ( dta , <NUM_LIT:6> , <NUM_LIT:32> , drift = True ) </s>
