A regression table for ten large US stocks that gives each one's beta and alpha, and how sure you can be of both.
Download the monthly Fama/French three factors from Kenneth French's data library, and ten years of monthly prices, adjusted for splits and dividends, for ten large NYSE and Nasdaq stocks.
Turn prices into monthly returns, and subtract the risk-free rate in the French file to get excess returns.
Fit each stock's beta on the market by least squares in NumPy, then check the slope, its standard error and R² against statsmodels.
Put a 95% interval on each beta from the formula and from a bootstrap, and read each residual plot for outliers and changing spread.
Test whether each alpha differs from zero, then apply a Bonferroni correction across the ten stocks and count what survives.
Add the size and value factors, fit on the first eight years, and compare R² for one and three factors on the last two.
How you'll know it worksA table of the ten stocks with beta, both intervals, alpha's p-value before and after Bonferroni, and out-of-sample R² for one and three factors, with your NumPy betas matching statsmodels to six decimal places.
Python with NumPy, pandas and statsmodels. The factors are free from Kenneth French's site; you download the price CSVs yourself from a free source such as Stooq or Yahoo Finance. Uses lessons 01 to 11.
Project: Market betas for ten real stocks
From insideout, Statistics and Regression: A regression table for ten large US stocks that gives each one's beta and alpha, and how sure you can be of both.
Steps:
1. Download the monthly Fama/French three factors from Kenneth French's data library, and ten years of monthly prices, adjusted for splits and dividends, for ten large NYSE and Nasdaq stocks.
2. Turn prices into monthly returns, and subtract the risk-free rate in the French file to get excess returns.
3. Fit each stock's beta on the market by least squares in NumPy, then check the slope, its standard error and R² against statsmodels.
4. Put a 95% interval on each beta from the formula and from a bootstrap, and read each residual plot for outliers and changing spread.
5. Test whether each alpha differs from zero, then apply a Bonferroni correction across the ten stocks and count what survives.
6. Add the size and value factors, fit on the first eight years, and compare R² for one and three factors on the last two.
How you'll know it works: A table of the ten stocks with beta, both intervals, alpha's p-value before and after Bonferroni, and out-of-sample R² for one and three factors, with your NumPy betas matching statsmodels to six decimal places.
Runs on: Python with NumPy, pandas and statsmodels. The factors are free from Kenneth French's site; you download the price CSVs yourself from a free source such as Stooq or Yahoo Finance.
Help me build this on my machine, one step at a time. Ask what I've tried first, give hints before full answers, and check my work against "How you'll know it works".