OLS on Market Data: Reading Betas and Testing Added Features
Machine LearningModel answerLast updated
Fit an OLS model on financial panel data, interpret each coefficient in economic terms, and test whether each extra feature adds explanatory power.
Context
You are handed a tidy dataset: one row per observation (say, per trading day or per asset-day), a column named target representing the dependent quantity (for example, next-period returns in basis points), and several predictor columns such as market return, trailing momentum, log trading volume, and a valuation score.
Task
- Fit an ordinary least squares model predicting
targetfrom all remaining columns (including an intercept). - Report the estimated coefficients (betas) and explain what each one means economically, in the units of the data.
- Describe how you would test, one at a time, whether each additional predictor genuinely contributes explanatory power beyond the others.
What a strong answer covers
- Correct model setup and how you read the fitted summary (coefficients, standard errors, t-statistics, p-values, R², adjusted R², overall F-test).
- Ceteris paribus interpretation with correct unit bookkeeping for transformed variables (logs, standardized scores).
- The right tool for testing marginal contribution — nested model comparison — and the difference between sequential and partial tests.
- Caveats specific to financial data: autocorrelated and heteroskedastic errors, multicollinearity, non-stationarity, and the gap between in-sample significance and out-of-sample value.
Hints
Hint 1
Fit with an OLS routine, add the intercept explicitly, and read coefficients together with their standard errors rather than in isolation.
Hint 2
Interpret each coefficient as the change in the target per one-unit change in that predictor, holding everything else fixed — and restate it in the predictor's real units.
Hint 3
To test marginal contribution, compare a model without the feature to one with it via an F-test (or a robust Wald test); order of entry matters for sequential sums of squares.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
Three skills are on display: fitting and reading OLS correctly, translating coefficients into statements about the economics with proper units, and knowing how to test whether a feature adds anything. Interviewers expect the mechanics to be quick and most of the time to go into interpretation and inference discipline.
Step 1 — Specify and fit
For n observations and k predictors:
y = β₀ + β₁x₁ + … + β_k x_k + ε, with β̂ = (XᵀX)⁻¹Xᵀy.
In practice:
import pandas as pd, statsmodels.api as sm
from statsmodels.stats.outliers_influence import variance_inflation_factor
from statsmodels.stats.anova import anova_lm
df = df.dropna()
y = df["target"]
X = sm.add_constant(df.drop(columns="target"))
base = sm.OLS(y, X).fit()
robust = sm.OLS(y, X).fit(cov_type="HAC", cov_kwds={"maxlags": 5}) # Newey–West
print(robust.summary())
vif = pd.Series([variance_inflation_factor(X.values, i) for i in range(X.shape[1])],
index=X.columns).drop("const")
print(vif)
From the summary, read: coef and std err; t = β̂/SE with its p-value (tests βⱼ = 0 given the other predictors are in the model); R² and adjusted R² (adjusted penalizes extra regressors via 1 − (1−R²)(n−1)/(n−k−1)); the overall F (all slopes jointly zero); Durbin–Watson (far from 2 → autocorrelated residuals); Jarque–Bera and the condition number (large → ill-conditioned/collinear design). Pairwise VIFs above roughly 5–10 flag collinearity.
Step 2 — Interpret each beta
Template: "Holding all other predictors fixed, a one-unit increase in xⱼ corresponds to a βⱼ-unit change in the target." Then attach units. Suppose the target is next-day return in basis points:
| Predictor | β̂ | Reading |
|---|---|---|
| const | 1.2 | Mean target when all predictors are zero — meaninful only if zero is a sensible value; center predictors to make it useful |
| market_return (bps) | 0.95 | Roughly unit market beta: a 100 bp market move pairs with ~95 bp in the target |
| momentum_12m (%) | 0.30 | A 10 pp higher trailing return pairs with ~3 bp higher next-day target (continuation) |
| log_volume | −2.1 | Level–log: a 1% rise in volume ↔ −0.021 bp, i.e. β/100 per 1% |
| value_score (z) | 4.0 | One standard deviation higher ↔ +4 bp |
Points to state explicitly:
- Transform bookkeeping. Level–level: β is Δy per unit Δx. Log–log: β is an elasticity. Level–log: β/100 is Δy per 1% Δx. Log–level: 100β is %Δy per unit Δx.
- Comparability. Raw betas are not comparable across predictors on different scales; standardize inputs or report β·σₓ to rank magnitudes.
- Statistical vs economic significance. At n = 10⁶ a 0.01 bp effect can show t = 5 and still be worthless after costs; conversely a large effect can carry a wide confidence interval.
- Association, not causation. β̂ⱼ absorbs the influence of omitted variables correlated with xⱼ. Say this out loud.
- Collinearity. When two predictors are near-duplicates, individual betas become unstable and can flip sign even though their joint effect is well estimated — interpret them as a block.
Step 3 — Testing marginal contribution
Nested F-test is the core tool. Compare restricted model R (without the feature/block) to unrestricted U (with it), for q added parameters:
F = [(RSS_R − RSS_U)/q] / [RSS_U/(n − k_U − 1)] ~ F(q, n − k_U − 1).
For one feature, F equals the squared t-statistic it already has in the full model.
Sequential (Type I) decomposition — add features one at a time in an order chosen on principle (theory first, or most established/cheapest first) and test each increment:
feats = ["market_return", "momentum_12m", "log_volume", "value_score"]
models, cols = [], []
for f in feats:
cols.append(f)
models.append(sm.OLS(y, sm.add_constant(df[cols])).fit())
print(anova_lm(*models)) # Type I: ΔRSS per added feature
print(anova_lm(models[-1], typ=2)) # partial tests = full-model t-tests
Explain the contrast: Type I credits the first feature with variance it shares with later ones and depends on entry order; Type II/III measure each feature's contribution given all the others. A large gap between the two is itself a collinearity diagnostic.
Robust versions. Classical F-tests assume homoskedastic, serially uncorrelated errors — usually false for returns (volatility clustering, overlapping horizons). Use wald_test/f_test on a HAC-fitted model for joint tests, and above all check incremental out-of-sample R² via walk-forward or purged time-series cross-validation, comparing restricted vs unrestricted forecasts with a Diebold–Mariano or Clark–West test. For financial deployment this matters far more than an in-sample F-test.
Stepwise selection caveats. Forward/backward selection by p-value, AIC, or BIC is fine for exploration, but post-selection p-values are biased low, false discoveries multiply, and results are unstable with correlated predictors. Prefer theory-driven ordering, multiple-testing control (Bonferroni or Benjamini–Hochberg), or regularized models (ridge/lasso) with time-series CV.
Step 4 — Diagnostics worth naming
- Residual-vs-fitted plots for nonlinearity; Breusch–Pagan for heteroskedasticity.
- Durbin–Watson or Ljung–Box on residuals → switch to HAC errors if autocorrelated.
- Cook's distance for influential points; returns are fat-tailed, so consider winsorizing or robust regression.
- Stationarity: regressing one non-stationary series on another yields spurious fits with inflated R² — model returns/differences, not price levels.
- Look-ahead bias: every predictor must be observable at time t when forecasting t+1.
- Coefficient stability: compare rolling or split-sample betas; unstable betas are a red flag for deployment.
Common mistakes
Interpreting betas across differently scaled features as if comparable; quoting R² without adjusted R² or out-of-sample checks; treating sequential sums of squares as if order-independent; ignoring serial correlation when reading t-stats; and calling a significant beta a causal effect.