src/luck_v_skill.py
def HAC_BSE(y,x,b,maxLag=mLag):
    '''Calculates Heteroskedasticity and Autocorrelation (HAC) Newey-West
    standard errors. Default lag procedure is below:

        maxLags = np.floor((4*no_obs/100)**(2/9)).astype(int)

    If you want a different lag procedure, pass in a new
    function under mLag=func, and make sure that the function
    only takes 'n_obs', an int for number of observations,
    as an input.

    INPUT
    -----
    y: n x 1 ndarray
        - dependent variable array
    x: n x k ndarray
        - independent variables array (include constant in x)
    b: k x 1 ndarray
        - OLS regression coefficients

    OUTPUT
    ------
    hac_bse: k x 1 ndarray
        - HAC coefficient standard errors


    For more info on HAC Newey-West check out this link:

    https://www.stata.com/manuals13/tsnewey.pdf
    '''
    n,k = x.shape
    m = mLag(n)
    r = (y - x.dot(b)).reshape(n,)
    XXI = np.linalg.inv(x.T.dot(x))
    w = np.diag(r**2)
    XWX = x.T.dot(w).dot(x)
    for l in range(1,m+1):
        w = np.diag(r[l:]*r[:-l])
        XWX_l  = np.zeros((k,k))
        XWX_l += x[:-l,:].T.dot(w).dot(x[l:,:])
        XWX_l += x[l:,:].T.dot(w).dot(x[:-l,:])
        XWX_l *= (1-l/(m+1))
        XWX += XWX_l
    XWX *= n/(n-k)
    var_B = XXI.dot(XWX).dot(XXI)
    return np.sqrt(abs(np.diag(var_B)))
Calculates Heteroskedasticity and Autocorrelation (HAC) Newey-West
    standard errors. Default lag procedure is below:

        maxLags = np.floor((4*no_obs/100)**(2/9)).astype(int)

    If you want a different lag procedure, pass in a new
    function under mLag=func, and make sure that the function
    only takes 'n_obs', an int for number of observations,
    as an input.

    INPUT
    -----
    y: n x 1 ndarray
        - dependent variable array
    x: n x k ndarray
        - independent variables array (include constant in x)
    b: k x 1 ndarray
        - OLS regression coefficients

    OUTPUT
    ------
    hac_bse: k x 1 ndarray
        - HAC coefficient standard errors


    For more info on HAC Newey-West check out this link:

    https://www.stata.com/manuals13/tsnewey.pdf
    
Calculates Heteroskedasticity and Autocorrelation (HAC) Newey-West
standard errors. Default lag procedure is below.



If you want a different lag procedure, pass in a new
function under mLag=func, and make sure that the function
only takes 'n_obs', an int for number of observations,
as an input.

INPUT

n x 1 ndarray
dependent variable array
x: n x k ndarray
independent variables array (include constant in x)
b: k x 1 ndarray
OLS regression coefficients

OUTPUT

k x 1 ndarray
HAC coefficient standard errors

For more info on HAC Newey-West check out this link.


Calculates Heteroskedasticity and Autocorrelation ( HAC ) Newey - West standard errors . Default lag procedure is below . If you want a different lag procedure pass in a new function under mLag = func and make sure that the function only takes ' n_obs ' an int for number of observations as an input . INPUT n x 1 ndarray dependent variable array x : n x k ndarray independent variables array ( include constant in x ) b : k x 1 ndarray OLS regression coefficients OUTPUT k x 1 ndarray HAC coefficient standard errors For more info on HAC Newey - West check out this link .
def HAC_BSE(y,x,b,maxLag=mLag):
    n,k = x.shape
    m = mLag(n)
    r = (y - x.dot(b)).reshape(n,)
    XXI = np.linalg.inv(x.T.dot(x))
    w = np.diag(r**2)
    XWX = x.T.dot(w).dot(x)
    for l in range(1,m+1):
        w = np.diag(r[l:]*r[:-l])
        XWX_l  = np.zeros((k,k))
        XWX_l += x[:-l,:].T.dot(w).dot(x[l:,:])
        XWX_l += x[l:,:].T.dot(w).dot(x[:-l,:])
        XWX_l *= (1-l/(m+1))
        XWX += XWX_l
    XWX *= n/(n-k)
    var_B = XXI.dot(XWX).dot(XXI)
    return np.sqrt(abs(np.diag(var_B)))
def HAC_BSE ( y , x , b , maxLag = mLag ) : n , k = x . shape m = mLag ( n ) r = ( y - x . dot ( b ) ) . reshape ( n , ) XXI = np . linalg . inv ( x . T . dot ( x ) ) w = np . diag ( r ** 2 ) XWX = x . T . dot ( w ) . dot ( x ) for l in range ( 1 , m + 1 ) : w = np . diag ( r [ l : ] * r [ : - l ] ) XWX_l = np . zeros ( ( k , k ) ) XWX_l += x [ : - l , : ] . T . dot ( w ) . dot ( x [ l : , : ] ) XWX_l += x [ l : , : ] . T . dot ( w ) . dot ( x [ : - l , : ] ) XWX_l *= ( 1 - l / ( m + 1 ) ) XWX += XWX_l XWX *= n / ( n - k ) var_B = XXI . dot ( XWX ) . dot ( XXI ) return np . sqrt ( abs ( np . diag ( var_B ) ) )
Calculates Heteroskedasticity and Autocorrelation (HAC) Newey-West
standard errors.
Calculates Heteroskedasticity and Autocorrelation ( HAC ) Newey - West standard errors .
'''Calculates Heteroskedasticity and Autocorrelation (HAC) Newey-West
    standard errors. Default lag procedure is below:

        maxLags = np.floor((4*no_obs/100)**(2/9)).astype(int)

    If you want a different lag procedure, pass in a new
    function under mLag=func, and make sure that the function
    only takes 'n_obs', an int for number of observations,
    as an input.

    INPUT
    -----
    y: n x 1 ndarray
        - dependent variable array
    x: n x k ndarray
        - independent variables array (include constant in x)
    b: k x 1 ndarray
        - OLS regression coefficients

    OUTPUT
    ------
    hac_bse: k x 1 ndarray
        - HAC coefficient standard errors


    For more info on HAC Newey-West check out this link:

    https://www.stata.com/manuals13/tsnewey.pdf
    '''
y
x
b
maxLag