iNick

Mohammad Nikbakht

Data Scientist

iNick

Mohammad Nikbakht

Data Scientist

Blog Post

First Article

November 22, 2024 Blog
Average Excess Returns: Calculate the time-series mean excess return for each portfolio and perform a 𝑡𝑡-test of the null hypothesis that the average excess return is equal to zero. The 𝑡𝑡- statistic from your 𝑡𝑡-test should be adjusted following Newey and West (1987) using 12 lags.

def newey_west_ttest(excess_returns, lags=12):
    excess_returns = excess_returns[~np.isnan(excess_returns)]
    if len(excess_returns) > 0:
        model = sm.OLS(excess_returns, np.ones(len(excess_returns)))
        results = model.fit(cov_type='HAC', cov_kwds={'maxlags': lags})
        return results.params[0], results.tvalues[0]
    else:
        return None, None
Write a comment