Linear Models for Trading
Linear models are fundamental tools in quantitative finance, providing interpretable and computationally efficient methods for return prediction, risk analysis, and factor modeling. This chapter covers the application of linear regression techniques to trading strategies.
Why Linear Models?
Linear models assume that the target variable is a linear combination of input features plus noise:
y = b0 + b1*x1 + b2*x2 + ... + bn*xn + e
Advantages:
- Interpretability: Coefficients directly show feature importance
- Computational efficiency: Fast to train and predict
- Statistical inference: P-values, confidence intervals available
- Well-understood theory: Decades of financial research
Linear models remain the workhorse of quantitative finance. Even when more complex models are used for prediction, linear factor models are essential for risk management and performance attribution.
Key Applications in Trading
- Return Prediction: Forecast future returns from technical indicators and fundamentals
- Factor Analysis: Decompose returns into systematic risk factors
- Direction Classification: Predict up/down movements for directional strategies
- Risk Attribution: Understand sources of portfolio risk
Linear Models Taxonomy
graph TD
A[Linear Models<br>for Trading]
A --> B[Regression<br>Continuous Targets]
A --> C[Classification<br>Discrete Targets]
A --> D[Factor Models<br>Risk Attribution]
B --> E[OLS<br>Ordinary Least Squares]
B --> F[Ridge<br>L2 Regularization]
B --> G[Lasso<br>L1 Regularization]
C --> H[Logistic<br>Regression]
C --> I[Direction<br>Classifier]
D --> J[CAPM<br>Single Factor]
D --> K[FF 3-Factor<br>Mkt + SMB + HML]
D --> L[FF 5-Factor<br>+ RMW + CMA]
D --> M[Fama-MacBeth<br>Cross-Section]
E --> N[Return<br>Prediction]
H --> O[Trade<br>Signals]
K --> P[Portfolio<br>Attribution]
classDef root fill:#1a3a5c,stroke:#0d2137,color:#e8e0d4
classDef regression fill:#2d5016,stroke:#1a3a1a,color:#e8e0d4
classDef classification fill:#6b2d5b,stroke:#4a1a4a,color:#e8e0d4
classDef factor fill:#8b4513,stroke:#5c2d0a,color:#e8e0d4
classDef leaf fill:#3a5c1a,stroke:#2d4a10,color:#e8e0d4
classDef output fill:#4a3a6b,stroke:#2d2244,color:#e8e0d4
class A root
class B,E,F,G regression
class C,H,I classification
class D,J,K,L,M factor
class N,O,P output
linkStyle default stroke:#4a5568,stroke-width:2px
Chapter Outline
| Section | Topics | Key Classes |
|---|---|---|
| OLS, Ridge & Lasso | Regression for return prediction, regularization, model comparison | OLSModel, RidgeModel, LassoModel |
| Logistic Regression | Direction prediction, probability-based trading signals | DirectionClassifier |
| Fama-French Factor Models | CAPM, 3/5-factor models, Fama-MacBeth regression, attribution | FamaFrenchModel, fama_macbeth |
Key Takeaways
- Linear models provide interpretability – Understand which features drive returns
- Regularization prevents overfitting – Use Ridge/Lasso with many features
- Direction prediction differs from return prediction – Logistic regression for classification
- Factor models explain systematic risk – CAPM and Fama-French decompose returns
- Statistical significance matters – Check p-values before trusting results
- Refit models periodically – Market dynamics change over time
- Combine predictions – Use both magnitude and direction for better signals
- Monitor residuals – Ensure model assumptions hold
Next Steps
- Part 9: Time Series Models – ARIMA, GARCH, state-space models
- Part 10: Machine Learning – Non-linear models, ensemble methods
- Part 11: Deep Learning – Neural networks for trading
Notebook: Run the examples interactively in
ml_models.ipynb
Related Chapters
- Part 4: Alpha Factors – Alpha factors serve as input features for linear return-prediction models
- Part 9: Time Series Models – Extends linear regression to autoregressive and volatility models
- Part 11: Tree Ensembles – Non-linear alternative when linear assumptions do not hold
- Part 10: Bayesian ML – Bayesian approach to parameter uncertainty in linear factor models
- Part 7: Backtesting – Evaluate linear model predictions in a realistic backtest environment
References
- Fama, E. F., & French, K. R. (1993). Common risk factors in the returns on stocks and bonds. Journal of Financial Economics.
- Fama, E. F., & MacBeth, J. D. (1973). Risk, return, and equilibrium: Empirical tests. Journal of Political Economy.
- Campbell, J. Y., Lo, A. W., & MacKinlay, A. C. (1997). The Econometrics of Financial Markets. Princeton University Press.
Source Code
Browse the implementation: puffin/models/