Video length is 3:01

Portfolio Optimization with Target Factor Exposures

This demo shows how to optimize a stock portfolio in MATLAB® using the Fama–French three-factor model and compare two different portfolio construction approaches. The first approach uses tracking error minimization to target factor exposures while allowing some flexibility around those targets. The second approach enforces exact factor exposure matching, requiring the portfolio to meet the target exposures exactly. This comparison highlights an important tradeoff: Allowing flexibility can improve diversification, while exact matching provides more precise control over factors. The workflow begins by loading one year of price data for the 30 stocks in the Dow Jones Industrial Average (DJIA) and converting those prices into returns. It then loads the Fama–French factor data for the same period. Both methods use the same practical portfolio constraints: Each selected stock must have a weight between 5% and 20%, the portfolio can hold at most 10 stocks, and all capital must be fully invested. For the tracking error approach, the demo defines target exposures for the Market, SMB, and HML factors and solves a minimum tracking error problem rather than forcing an exact match. The resulting portfolio is then examined through asset weights, stock-level factor exposures, and weighted factor contributions to show which holdings drive the portfolio’s overall factor profile. For the exact exposure approach, the demo adds equality constraints so that the weighted sum of stock exposures matches the target factor exposures exactly. It then solves for the minimum-risk portfolio subject to those strict exposure requirements and visualizes the resulting allocation. Finally, the two portfolios are compared side by side. You will see that the tracking error formulation often leads to better diversification, while the exact exposure approach guarantees precise factor matching, sometimes at the cost of concentration or feasibility. To learn more about this workflow, visit the documentation link below.

Published: 30 Apr 2026