insideout Get Pro
Learn
Quant engineering · Module 02

Statistics and Regression

How to learn from noisy data without fooling yourself.

Start here · Lesson 01

Samples and estimates

A sample mean, its standard error, and why more data helps slowly.

Start lesson

LessonsAll lessons

  1. 01 Samples and estimatesA sample mean, its standard error, and why more data helps slowly. Free
  2. 02 Confidence intervalsA range that usually contains the truth, and what usually means. Free
  3. 03 Tests and p-valuesHow surprising your data would be if nothing were going on. Free
  4. 04 Multiple testingTry twenty ideas and one will look significant by luck. Pro
  5. 05 CorrelationMeasuring how two things move together, and how it misleads. Pro
  6. 06 Linear regressionFitting the best line by hand, then by formula. Pro
  7. 07 What regression assumesErrors, outliers and the assumptions that quietly break. Pro
  8. 08 OverfittingTrain on one part, test on another, and watch complexity fail. Pro
  9. 09 RegularisationRidge and lasso: shrinking a model so it generalises. Pro
  10. 10 The bootstrapResampling your data to see how sure you should be. Pro
  11. 11 Beta and factor exposureRegression in finance: how much of a return the market explains. Pro
  12. 12 Principal componentsThe few hidden drivers behind many series that move together. Pro
  13. 13 Cause and effectWhy a correlation isn't a cause, and how to get closer to one. Pro

Build it yourself · on your own machine

Market betas for ten real stocks

A regression table for ten large US stocks that gives each one's beta and alpha, and how sure you can be of both.
  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 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.