// PORTFOLIO · MODULE 08/12

Portfolio construction: from Markowitz to LLM-generated views

Efficient frontier, Black-Litterman with LLM views, and optimizer sensitivity.

Level intermediate-advancedEdition jul 2026Leer en español


Module 7 built the measurement of risk: variance, covariance and Euler decomposition. This module answers the next question: given expected returns and a covariance matrix, what weights should the portfolio hold? The theoretical answer is seventy years old and forms a single genealogical tree —Markowitz (1952) → Tobin (1958) → Sharpe (1964) → Fama-French/Carhart → Black-Litterman (1992) → risk-only methods (ERC, MDP, HRP)—, not a recipe book of rival methods. Onto that tree the course grafts its modern contribution: an LLM that reads news and issues views that the Black-Litterman model weighs in a Bayesian manner before a deterministic optimizer computes the weights and a human vetoes them. It is the natural bridge to Module 9 (signals) and the pipeline that the Module 12 capstone will implement end to end.

8.1 Theory with exact formulas

Notation: w∈Rn\mathbf{w} \in \mathbb{R}^n weight vector; μ∈Rn\boldsymbol{\mu} \in \mathbb{R}^n expected returns; Σ∈Rn×n\boldsymbol{\Sigma} \in \mathbb{R}^{n \times n} covariance matrix; 1\mathbf{1} vector of ones; rfr_f risk-free rate; δ\delta (or λ\lambda) risk aversion.

8.1.1 Markowitz mean-variance and its descendants

The optimization program. Markowitz (1952) formulated portfolio selection as a quadratic program: minimize variance subject to a target return (databento.com):

min⁡ww⊤Σws.t.w⊤μ=μˉ,w⊤1=1\min_{\mathbf{w}} \quad \mathbf{w}^\top \boldsymbol{\Sigma} \mathbf{w} \quad \text{s.t.} \quad \mathbf{w}^\top \boldsymbol{\mu} = \bar{\mu}, \quad \mathbf{w}^\top \mathbf{1} = 1

The dual form with risk aversion λ\lambda —the one most used in code— has a closed-form solution without constraints:

w∗=arg⁡max⁡w{w⊤μ−λ2w⊤Σw}⟹w∗=1λΣ−1μ\mathbf{w}^{*} = \arg\max_{\mathbf{w}} \left\{ \mathbf{w}^\top \boldsymbol{\mu} - \frac{\lambda}{2} \mathbf{w}^\top \boldsymbol{\Sigma} \mathbf{w} \right\} \quad \Longrightarrow \quad \mathbf{w}^{*} = \frac{1}{\lambda} \boldsymbol{\Sigma}^{-1} \boldsymbol{\mu}

Note the factor Σ−1\boldsymbol{\Sigma}^{-1}: it is the source of all the fragility that section 8.2 will quantify, because inverting a nearly singular covariance matrix amplifies the errors of μ^\hat{\boldsymbol{\mu}} (B2BITS).

The efficient frontier as a hyperbola. Defining the scalars

A=1⊤Σ−1μ,B=μ⊤Σ−1μ,C=1⊤Σ−11,D=BC−A2A = \mathbf{1}^\top \boldsymbol{\Sigma}^{-1} \boldsymbol{\mu}, \qquad B = \boldsymbol{\mu}^\top \boldsymbol{\Sigma}^{-1} \boldsymbol{\mu}, \qquad C = \mathbf{1}^\top \boldsymbol{\Sigma}^{-1} \mathbf{1}, \qquad D = BC - A^2

the minimum-variance frontier in (σ2,μ)(\sigma^2, \mu) space is the hyperbola:

σp2(μˉ)=Cμˉ2−2Aμˉ+BD\sigma_p^2(\bar{\mu}) = \frac{C \bar{\mu}^2 - 2A\bar{\mu} + B}{D}

Global minimum-variance portfolio (GMV). The leftmost point of the frontier does not depend on μ\boldsymbol{\mu} —the property that makes it the most robust estimator of the family— (Github):

wGMV=Σ−111⊤Σ−11σGMV2=1C,μGMV=AC\mathbf{w}_{\text{GMV}} = \frac{\boldsymbol{\Sigma}^{-1} \mathbf{1}}{\mathbf{1}^\top \boldsymbol{\Sigma}^{-1} \mathbf{1}} \qquad \sigma_{\text{GMV}}^2 = \frac{1}{C}, \qquad \mu_{\text{GMV}} = \frac{A}{C}

Tangency portfolio (maximum Sharpe) and CML. With a risk-free asset rfr_f, the risky-asset portfolio with the maximum Sharpe ratio is:

wtan⁡=Σ−1(μ−rf1)1⊤Σ−1(μ−rf1)SRtan⁡=(μ−rf1)⊤Σ−1(μ−rf1)\mathbf{w}_{\tan} = \frac{\boldsymbol{\Sigma}^{-1} (\boldsymbol{\mu} - r_f \mathbf{1})}{\mathbf{1}^\top \boldsymbol{\Sigma}^{-1} (\boldsymbol{\mu} - r_f \mathbf{1})} \qquad SR_{\tan} = \sqrt{(\boldsymbol{\mu} - r_f\mathbf{1})^\top \boldsymbol{\Sigma}^{-1} (\boldsymbol{\mu} - r_f\mathbf{1})}

and every combination of rfr_f and the tangency portfolio forms the Capital Market Line:

E[Rp]=rf+σp⋅E[Rtan⁡]−rfσtan⁡E[R_p] = r_f + \sigma_p \cdot \frac{E[R_{\tan}] - r_f}{\sigma_{\tan}}

The following figure illustrates these objects with four synthetic assets (the resulting GMV weights are 74.6%, 15.0%, 6.7% and 3.7%; the tangency weights, 44.8%, 20.8%, 15.1% and 19.3%):

Efficient frontier with GMV and tangency portfolioEfficient frontier (4 assets): 12 → 4.80, 9.11 → 7.30, 12 → 9.80, 18 → 12, 25 → 15, 33 → 17, 36 → 19. CML (rf + tangency): 0 → 3, 38 → 24. : 10 → 6, 16 → 9, 22 → 12, 28 → 15. : 0 → 3, 9.10 → 7.15, 11 → 9.30Efficient frontier (4 assets)CML (rf + tangency)05101520250510152025303540Annual volatility (%)Expected annual return (%)Asset 1Asset 2Asset 3Asset 4rfGMVTangency (max Sharpe)
Figure 8.1. Markowitz efficient frontier with four synthetic assets: global minimum-variance portfolio (GMV) and tangency portfolio on the Capital Market Line. Own elaboration with synthetic data, Jul 2026.
GMV and tangency portfolio weightsAsset 1: 74.6 % / 44.8 %; Asset 2: 15.0 % / 20.8 %; Asset 3: 6.7 % / 15.1 %; Asset 4: 3.7 % / 19.3 %GMV (global minimum variance)Tangency (maximum Sharpe)0 %20 %40 %60 %80 %Portfolio weight74.6 %44.8 %Asset 115.0 %20.8 %Asset 26.7 %15.1 %Asset 33.7 %19.3 %Asset 4
Figure 8.1b. The weights of the two portfolios in figure 8.1: GMV puts 74.6 % in the least volatile asset; the tangency portfolio spreads toward the higher expected returns. Figures from the text.

Tobin's two-fund separation. Tobin (1958) showed that the choice of which risky portfolio to hold is independent of risk aversion: only how much is invested in it versus the safe asset changes (arXiv.org). Every optimal portfolio is:

woˊptima=y⋅wtan⁡+(1−y)⋅rf,y∈R\mathbf{w}_{\text{óptima}} = y \cdot \mathbf{w}_{\tan} + (1-y) \cdot r_f, \quad y \in \mathbb{R}

with y>1y > 1 implying leverage. The conservative and the aggressive investor hold the same risky portfolio; they differ only in the leverage applied to it (稀土掘金).

CAPM. In equilibrium, the tangency portfolio is the market portfolio and every asset prices on the Security Market Line (Sharpe 1964; Lintner 1965; Mossin 1966) (mer.vin):

E[Ri]=rf+βi(E[Rm]−rf)βi=Cov⁡(Ri,Rm)σm2E[R_i] = r_f + \beta_i \big(E[R_m] - r_f\big) \qquad \beta_i = \frac{\operatorname{Cov}(R_i, R_m)}{\sigma_m^2}

Factor models. The single-factor CAPM generalizes into the factor decomposition of returns. Fama-French 3 factors (1993) adds size and value, explaining roughly 90% of the variation of diversified portfolios versus the CAPM's ~70% (Github):

Ri,t−rf,t=αi+βi,M(RM,t−rf,t)+βi,SMBSMBt+βi,HMLHMLt+εi,tR_{i,t} - r_{f,t} = \alpha_i + \beta_{i,M}(R_{M,t} - r_{f,t}) + \beta_{i,SMB} SMB_t + \beta_{i,HML} HML_t + \varepsilon_{i,t}

Carhart (1997) adds momentum WMLWML (Winners Minus Losers, winners 12–1 months minus losers) (Github):

Ri,t−rf,t=αi+βi,MMKTt+βi,SMBSMBt+βi,HMLHMLt+βi,WMLWMLt+εi,tR_{i,t} - r_{f,t} = \alpha_i + \beta_{i,M} MKT_t + \beta_{i,SMB} SMB_t + \beta_{i,HML} HML_t + \beta_{i,WML} WML_t + \varepsilon_{i,t}

and Fama-French 5 factors (2015) incorporates operating profitability (RMWRMW, Robust Minus Weak) and conservative investment (CMACMA, Conservative Minus Aggressive) (Github):

Ri,t−rf,t=αi+βi,MMKTt+βi,SMBSMBt+βi,HMLHMLt+βi,RMWRMWt+βi,CMACMAt+εi,tR_{i,t} - r_{f,t} = \alpha_i + \beta_{i,M} MKT_t + \beta_{i,SMB} SMB_t + \beta_{i,HML} HML_t + \beta_{i,RMW} RMW_t + \beta_{i,CMA} CMA_t + \varepsilon_{i,t}

These models matter here for two reasons: (i) they define the factor risk budgets that are imposed as linear constraints in the optimizer (∑iwiβi,k≤bk\sum_i w_i \beta_{i,k} \leq b_k), and (ii) they are the benchmark that any "alpha" generated by an LLM must beat net of costs —section 8.4 will show that LLM styles are usually undeclared FF/Carhart factor exposures (Github). Factor data are downloaded from the Ken French Data Library (Github).

8.1.2 Black-Litterman, Kelly and the μ\boldsymbol{\mu}-free methods

Full Black-Litterman. Black and Litterman (1992) solved the absurd-inputs problem of MVO by reversing the direction of the calculation: instead of estimating μ\boldsymbol{\mu} and optimizing, they start from CAPM equilibrium and let the investor tilt the prior only where they have conviction (Github). The procedure has four steps.

Step 1 — Implied equilibrium returns (reverse optimization on the market-cap weights wm\mathbf{w}_m, with δ\delta typically between 2.5 and 3.5) (Github):

π=δ Σ wm\boldsymbol{\pi} = \delta \, \boldsymbol{\Sigma} \, \mathbf{w}_{m}

Step 2 — Investor views: kk views q=Pμ+ε\mathbf{q} = P\boldsymbol{\mu} + \boldsymbol{\varepsilon}, with ε∼N(0,Ω)\boldsymbol{\varepsilon} \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Omega}), P∈Rk×nP \in \mathbb{R}^{k \times n} "picking" matrix and Ω\boldsymbol{\Omega} the uncertainty diagonal.

Step 3 — Bayesian posterior, in its two equivalent exact forms (Github):

μBL=[(τΣ)−1+P⊤Ω−1P]−1[(τΣ)−1π+P⊤Ω−1q]\boldsymbol{\mu}_{BL} = \left[(\tau\boldsymbol{\Sigma})^{-1} + P^\top \boldsymbol{\Omega}^{-1} P\right]^{-1} \left[(\tau\boldsymbol{\Sigma})^{-1} \boldsymbol{\pi} + P^\top \boldsymbol{\Omega}^{-1} \mathbf{q}\right] μBL=π+τΣP⊤(PτΣP⊤+Ω)−1(q−Pπ)\boldsymbol{\mu}_{BL} = \boldsymbol{\pi} + \tau \boldsymbol{\Sigma} P^\top \left(P \tau \boldsymbol{\Sigma} P^\top + \Omega\right)^{-1} \left(\mathbf{q} - P\boldsymbol{\pi}\right)

with posterior covariance ΣBL=Σ+M\boldsymbol{\Sigma}_{BL} = \boldsymbol{\Sigma} + M, where M=[(τΣ)−1+P⊤Ω−1P]−1M = \left[(\tau\boldsymbol{\Sigma})^{-1} + P^\top \boldsymbol{\Omega}^{-1} P\right]^{-1}. The scalar τ\tau measures the uncertainty of the prior; institutional practice sets it in [0,01,0,05][0{,}01, 0{,}05] or as τ=1/T\tau = 1/T (Github). Idzorek's (2005) calibration of Ω\boldsymbol{\Omega} sets each diagonal element from the variance of the view's asset combination (Github):

ωk=τ pk Σ pk⊤\omega_k = \tau \, \mathbf{p}_k \, \boldsymbol{\Sigma} \, \mathbf{p}_k^\top

Step 4 — Weights: μBL\boldsymbol{\mu}_{BL} and ΣBL\boldsymbol{\Sigma}_{BL} are fed to the MV optimizer: w∗=1δΣBL−1μBL\mathbf{w}^* = \frac{1}{\delta}\boldsymbol{\Sigma}_{BL}^{-1}\boldsymbol{\mu}_{BL} (unconstrained). The economic reading is the pedagogical key: BL is a Bayesian shrinkage toward equilibrium —a view with high Ω\Omega barely moves π\boldsymbol{\pi}; a view with low Ω\Omega dominates it locally. That is exactly where the LLM views of section 8.3 will enter.

Kelly criterion. Kelly (1956) maximizes the expected logarithmic growth rate of wealth (Github). For a bet with probability pp of winning and net odds bb:

G(f)=p⋅ln⁡(1+bf)+(1−p)⋅ln⁡(1−f)G(f) = p \cdot \ln(1 + b f) + (1 - p) \cdot \ln(1 - f)

Differentiating and setting to zero yields the optimal fraction (Github):

f∗=bp−(1−p)b=p(b+1)−1b=p−qbf^{*} = \frac{bp - (1-p)}{b} = \frac{p(b+1) - 1}{b} = p - \frac{q}{b}

The generalization with partial losses (Rotando and Thorp 1992; Thorp 2008), where aa are the odds of the negative outcome (Github):

f∗=pa−1−pbf^{*} = \frac{p}{a} - \frac{1-p}{b}

and the Gaussian continuous version, with its multivariate form (Github):

f∗=μ−rfσ2and multivariate:f∗=Σ−1(μ−rf1)f^{*} = \frac{\mu - r_f}{\sigma^2} \qquad \text{and multivariate:} \quad \mathbf{f}^{*} = \boldsymbol{\Sigma}^{-1}(\boldsymbol{\mu} - r_f \mathbf{1})

Multivariate Kelly coincides with the unnormalized tangency portfolio —the λ=1\lambda = 1 case of MVO—, which connects sizing and optimization in a single theory. Since full Kelly is extraordinarily sensitive to the estimated edge, standard practice is fractional Kelly f^=c⋅f∗\hat{f} = c \cdot f^{*} with c=1/2c = 1/2 or 1/41/4: half-Kelly retains roughly 75% of the growth with about half the volatility, and Thorp himself operated in that range (Github).

Equal Risk Contribution (ERC). Risk-only methods remove μ\boldsymbol{\mu} from the problem. The marginal risk contribution and the risk contribution of asset ii are (Maillard, Roncalli and Teïletche 2010) (Github):

MRCi=∂σp∂wi=(Σw)iw⊤ΣwRCi=wi⋅MRCi=wi(Σw)iσpMRC_i = \frac{\partial \sigma_p}{\partial w_i} = \frac{(\boldsymbol{\Sigma}\mathbf{w})_i}{\sqrt{\mathbf{w}^\top \boldsymbol{\Sigma} \mathbf{w}}} \qquad RC_i = w_i \cdot MRC_i = \frac{w_i (\boldsymbol{\Sigma}\mathbf{w})_i}{\sigma_p}

By the Euler identity of Module 7, σp=∑iRCi\sigma_p = \sum_i RC_i. The ERC condition requires each asset to contribute exactly 1/n1/n of total risk:

RCi=RCj=σpn∀i,j⟺wi(Σw)i=wj(Σw)j    ∀i,jRC_i = RC_j = \frac{\sigma_p}{n} \quad \forall i, j \quad \Longleftrightarrow \quad w_i (\boldsymbol{\Sigma}\mathbf{w})_i = w_j (\boldsymbol{\Sigma}\mathbf{w})_j \;\; \forall i,j

With no general closed-form solution, it is solved numerically (least-squares formulation; Spinu's 2013 version convexifies the problem via a logarithmic function) (Github):

wERC=arg⁡min⁡w∑i=1n∑j=1n(wi(Σw)i−wj(Σw)j)2s.t. w⊤1=1,  wi≥0\mathbf{w}_{ERC} = \arg\min_{\mathbf{w}} \sum_{i=1}^n \sum_{j=1}^n \left( w_i(\boldsymbol{\Sigma}\mathbf{w})_i - w_j(\boldsymbol{\Sigma}\mathbf{w})_j \right)^2 \quad \text{s.t. } \mathbf{w}^\top\mathbf{1}=1,\; w_i \geq 0

ERC sits between 1/N1/N and GMV on the diversification-risk spectrum.

Ledoit-Wolf covariance shrinkage. The sample covariance SS is noisy and ill-conditioned; the Ledoit-Wolf estimator (2003/2004) combines it convexly with a structured target FF (Source):

Σ^LW=δ∗F+(1−δ∗)S\widehat{\boldsymbol{\Sigma}}_{LW} = \delta^{*} F + (1 - \delta^{*}) S

with optimal intensity computable in closed form from the data, with no free parameters (AgentConn):

δ∗=∑i≠jVar⁡^(sij)∑i≠j(sij−fij)2\delta^{*} = \frac{\sum_{i \neq j} \widehat{\operatorname{Var}}(s_{ij})}{\sum_{i \neq j}(s_{ij} - f_{ij})^2}

Usual targets: constant correlation (2003: fii=siif_{ii} = s_{ii}, fij=ρˉsiisjjf_{ij} = \bar{\rho}\sqrt{s_{ii}s_{jj}}) and scaled identity (2004: F=Tr⁡(S)nIF = \frac{\operatorname{Tr}(S)}{n} I). Verified numerical example: with δ=0,45\delta = 0{,}45, sample correlation 0.72 and mean 0.42, the shrunk correlation is 0,45×0,42+0,55×0,72=0,5850{,}45 \times 0{,}42 + 0{,}55 \times 0{,}72 = 0{,}585 (maryammiradi.com). Course operating rule: never feed raw sample Σ\Sigma to BL or MVO with more than a dozen assets.

Maximum Diversification. Choueifaty and Coignard (2008) maximize the diversification ratio (TradingAgents-AI):

DR(w)=w⊤σw⊤Σw=∑iwiσiσpDR(\mathbf{w}) = \frac{\mathbf{w}^\top \boldsymbol{\sigma}}{\sqrt{\mathbf{w}^\top \boldsymbol{\Sigma} \mathbf{w}}} = \frac{\sum_i w_i \sigma_i}{\sigma_p}

The solution without the no-shorting constraint is wMD∝Σ−1σ\mathbf{w}_{MD} \propto \boldsymbol{\Sigma}^{-1} \boldsymbol{\sigma}, normalized to sum 1 (Cambridge University Press & Assessment). If all Sharpes are equal, MDP coincides with the tangency portfolio; moreover, DR2DR^2 is the effective number of independent risk sources in the portfolio (Cambridge University Press & Assessment).

HRP — Hierarchical Risk Parity. López de Prado (2016) achieves diversification without inverting Σ\boldsymbol{\Sigma}, eliminating at the root the instability of Σ−1\boldsymbol{\Sigma}^{-1} (ResearchGate). Three stages: (1) hierarchical clustering on the correlation-derived distance:

dij=12(1−ρij)d_{ij} = \sqrt{\tfrac{1}{2}\left(1 - \rho_{ij}\right)}

(2) quasi-diagonalization: reordering the rows and columns of Σ\boldsymbol{\Sigma} following the dendrogram so that similar assets end up adjacent; (3) recursive bisection: for each split into subclusters c1,c2c_1, c_2, the intra-cluster variance is computed with inverse-variance allocation,

w~c=1/σi2∑j∈c1/σj2,Vc=w~c⊤Σc w~c\tilde{\mathbf{w}}_{c} = \frac{1/\sigma_i^2}{\sum_{j \in c} 1/\sigma_j^2}, \qquad V_c = \tilde{\mathbf{w}}_{c}^\top \boldsymbol{\Sigma}_c \, \tilde{\mathbf{w}}_{c}

and the split factor between subclusters:

α1=1−V1V1+V2,α2=1−α1\alpha_1 = 1 - \frac{V_1}{V_1 + V_2}, \qquad \alpha_2 = 1 - \alpha_1

Weights propagate multiplicatively down to the leaves. Documented extensions include HERC/HERC2 (Raffinot 2018), NCO (López de Prado 2019) and Schur complementary allocation (Cotton 2024), which unifies HRP and minimum variance while guaranteeing var(Schur)≤var(HRP)\text{var}(\text{Schur}) \leq \text{var}(\text{HRP}) (arXiv.org).

HRP and fractional Kelly in production:

python
from pypfopt import HRPOpt

hrp = HRPOpt(returns)                 # Ward clustering + recursive bisection
w_hrp = hrp.optimize()                # without inverting Sigma: robust to ill-conditioning

# Fractional Kelly on the BL tangency portfolio (prudential sizing)
f_kelly_full = np.linalg.solve(S_bl.values, mu_bl.values - 0.03)   # Sigma^-1 (mu - rf 1)
c_frac = 0.25                                                         # quarter-Kelly
w_final  = c_frac * f_kelly_full / np.sum(np.abs(f_kelly_full))

(ResearchGate)

Reference implementation (PyPortfolioOpt):

python
from pypfopt import EfficientFrontier, risk_models, expected_returns

mu = expected_returns.mean_historical_return(prices)
S  = risk_models.CovarianceShrinkage(prices).ledoit_wolf()   # never raw sample_cov
ef = EfficientFrontier(mu, S)
w_tan = ef.max_sharpe(risk_free_rate=0.03)

ef_gmv = EfficientFrontier(mu, S)
w_gmv  = ef_gmv.min_volatility()

(arXiv.org)

GMV with cvxpy (full constraint control):

python
import cvxpy as cp
import numpy as np

n = S.shape[0]
w = cp.Variable(n)
prob = cp.Problem(
    cp.Minimize(cp.quad_form(w, S.values)),
    [cp.sum(w) == 1, w >= 0, w <= 0.25]        # long-only + per-asset cap
)
prob.solve()
w_gmv = w.value                                 # constrained GMV = implicit shrinkage (§8.2)

8.2 The fragility of optimization

8.2.1 Error maximization, estimation sensitivity and defenses

The enemy is the input, not the model. Merton (1980) showed that the covariance matrix can be estimated with high precision using data of reasonable frequency, but that the mean of returns is only estimable with histories far longer than those available: with realistic historical data, μ^\hat{\boldsymbol{\mu}} is essentially useless for computing optimal weights (B2BITS). Chopra and Ziemba (1993) quantified the damage hierarchy: errors in means have roughly an order of magnitude more impact on utility loss than errors in variances, and these in turn more than errors in covariances —the commonly cited rule of thumb is ~11× means versus variances and ~21× means versus covariances in certainty-equivalent terms, figures best taken as an order of magnitude and not as a universal constant. The didactic consequence is direct: the research budget should go first to μ\boldsymbol{\mu}, not to Σ\boldsymbol{\Sigma}.

The geometric mechanism is the inversion of Σ\boldsymbol{\Sigma}: in correlated universes the matrix is nearly singular and multiplying by Σ−1\boldsymbol{\Sigma}^{-1} amounts to multiplying by a large number, which magnifies small changes in expected returns into huge changes in weights (Best and Grauer 1991). The canonical numerical example: with correlation 0.7, changing one asset's expected return by only 2 percentage points (from 10% to 8%) reduces its optimal weight from 0.50 to 0.18 (B2BITS). The following figure reproduces the phenomenon with the four synthetic assets: moving Asset 4's expected return by ±2\pm 2 pp. shifts its tangency weight from 12.2% to 26.1% —almost 14 pp. of rotation from a perfectly plausible estimation error.

Sensitivity of optimal weights to perturbations in muw1 (tangency): −2.0 → 45, 0.0 → 45, 2.0 → 45. w2 (tangency): −2.0 → 23, 0.0 → 21, 2.0 → 19. w3 (tangency): −2.0 → 20, 0.0 → 15, 2.0 → 10. w4 (tangency): −2.0 → 12, 0.0 → 19, 2.0 → 26w1 (tangency)w2 (tangency)w3 (tangency)w4 (tangency)1020304050−2.0−1.5−1.0−0.50.00.51.01.52.0Perturbation of Asset 4 expected return (percentage points)Weight in the tangency portfolio (%)
Figure 8.2. Sensitivity of tangency-portfolio weights to a ±2 pp. perturbation in Asset 4's expected return: its weight moves from 12.2% to 26.1%. Own elaboration with synthetic data, Jul 2026.

Michaud and the 1/N1/N verdict. Michaud (1989) named the phenomenon: MVO is an error maximization device that aggressively exploits estimation errors instead of approximating the true mean-variance trade-off (Github). The formal line starts with Jobson and Korkie (1980), continues with Britten-Jones (1999) —the sampling error of tangency weights is enormous— and with Green and Hollifield (1992), who show that even without estimation error a dominant factor generates extreme weights (Foxholm Financial). The most uncomfortable empirical result is DeMiguel, Garlappi and Uppal (2009): fourteen sophisticated strategies (Bayes-Stein, minimum variance, constraints) against 1/N1/N on seven datasets, and none consistently beats the equal-weight allocation out of sample; with costs, the gap widens (Github). The caveat documented by Kirby and Ostdiek (2012) is equally important: much of the result comes from a design with high estimation risk and extreme turnover, and low-turnover MVO (volatility/reward-to-risk timing) can indeed beat 1/N1/N net of costs (Github).

Constraints as shrinkage (Jagannathan-Ma). The most counterintuitive and most useful result in the literature: the long-only GMV portfolio with upper caps computed with Σ^\hat{\boldsymbol{\Sigma}} is identical to the unconstrained GMV of a modified matrix in which the Lagrange multipliers shrink the covariances of the assets at the cap. Imposing "wrong" constraints acts as covariance shrinkage, and that is why the constrained GMV beats the unconstrained one out of sample (Jagannathan and Ma 2003) (arXiv.org). DeMiguel, Garlappi, Nogales and Uppal (2009) unified the landscape: norm constraints ∥w∥p≤δ\|\mathbf{w}\|_p \leq \delta nest as special cases Ledoit-Wolf shrinkage, the Jagannathan-Ma result and 1/N1/N itself (pypi.org). Operational lesson: sector constraints, per-asset caps and long-only are not concessions to compliance; they are statistical regularization.

Turnover and costs. Net return after rebalancing incorporates the transaction cost ϕ\phi (Palomar 2025) (arXiv.org):

Rtportf=(wt−1reb)⊤rtlin  −  ϕ(wt−1→wt−1reb)R^{portf}_t = \big(\mathbf{w}^{reb}_{t-1}\big)^\top \mathbf{r}^{lin}_t \;-\; \phi\big(\mathbf{w}_{t-1} \rightarrow \mathbf{w}^{reb}_{t-1}\big)

with a linear model ϕ=∑ici∣wireb−widrift∣\phi = \sum_i c_i |w_i^{reb} - w_i^{drift}| for commissions and spread, and market impact quadratic in weights (square root in volume, Almgren-Chriss; Module 7). The standard defense is to penalize turnover inside the objective (arXiv.org):

max⁡w{w⊤μ−λ2w⊤Σw−γ∑i∣wi−wiprev∣}\max_{\mathbf{w}} \left\{ \mathbf{w}^\top\boldsymbol{\mu} - \frac{\lambda}{2}\mathbf{w}^\top\boldsymbol{\Sigma}\mathbf{w} - \gamma \sum_i |w_i - w_i^{prev}| \right\}

For illustration: 200% annual turnover on a 100-million portfolio with an average effective cost of 15 bps per side destroys 300,000.00 of annual return (30 bps of drag) —enough to reverse the ranking of any pair of methods in the table below.

Deflated Sharpe Ratio. Every allocation backtest must be corrected for sample length, non-normality and selection bias from multiple trials (Bailey and López de Prado 2014) (Github):

DSR=Φ((SR^−E[max⁡SR])T−11−γ^3SR^+γ^4−14SR^2)DSR = \Phi\left( \frac{(\widehat{SR} - E[\max SR])\sqrt{T-1}}{\sqrt{1 - \hat{\gamma}_3 \widehat{SR} + \frac{\hat{\gamma}_4 - 1}{4}\widehat{SR}^2}} \right)

where E[max⁡SR]E[\max SR] is the maximum expected Sharpe under the null after NN independent trials:

E[max⁡SR]≈VSR[(1−ζ) Φ−1 ⁣(1−1N)+ζ Φ−1 ⁣(1−1Ne)]E[\max SR] \approx \sqrt{V_{SR}}\left[(1-\zeta)\,\Phi^{-1}\!\left(1 - \tfrac{1}{N}\right) + \zeta\,\Phi^{-1}\!\left(1 - \tfrac{1}{Ne}\right)\right]

with ζ\zeta the Euler-Mascheroni constant and VSRV_{SR} the variance of the Sharpes across trials. Practical rule: require DSR>0,95DSR > 0{,}95, complemented with PBO via CSCV and purged/embargoed cross-validation for series with overlapping labels (Github).

Table 8.1 — Allocation methods: assumptions, critical inputs, fragility and when to use them

MethodKey assumptionsCritical inputsDominant fragilityWhen to use it
GMVOnly risk matters; μ\boldsymbol{\mu} ignoredΣ\boldsymbol{\Sigma} (well estimated)Estimation of Σ\boldsymbol{\Sigma}; concentration in low-vol assetsRobust baseline; broad universe with little return signal
Tangency (max Sharpe)μ\boldsymbol{\mu}, Σ\boldsymbol{\Sigma} known; rfr_f existsμ\boldsymbol{\mu} and Σ−1\boldsymbol{\Sigma}^{-1}Extreme error maximization: ±2\pm 2 pp. in μi\mu_i → ±14 pp. in wiw_iOnly with shrunk μ\boldsymbol{\mu} (BL, Bayes-Stein) and constraints
Black-LittermanCAPM equilibrium as prior; views ∼N\sim \mathcal{N}wm\mathbf{w}_m, δ\delta, τ\tau, PP, q\mathbf{q}, Ω\boldsymbol{\Omega}Poor calibration of Ω\boldsymbol{\Omega}; overconfident viewsWhenever there are views (human or LLM) to combine with the market
Kelly (fractional)Estimable edge; logarithmic utilityEdge (pp, bb or μ/σ2\mu/\sigma^2)Overestimating the edge → ruinous over-leverageSizing bets with documented edge; always c≤1/2c \leq 1/2
ERC / Risk ParityDiversification by risk, not capitalΣ\boldsymbol{\Sigma}Rotation toward low-vol/estimated-correlation assetsMulti-asset portfolios without reliable return views
Maximum DiversificationMaximize DRDR; implicit homogeneous SharpesΣ\boldsymbol{\Sigma}, σ\boldsymbol{\sigma}Σ−1\boldsymbol{\Sigma}^{-1} reappears; sensitive to conditioningWhen equal ex-ante Sharpes are believed and maximum diversification is wanted
HRPHierarchical correlation structureΣ\boldsymbol{\Sigma} (not inverted), linkageArbitrariness of clustering; less efficient in-sampleProduction with ill-conditioned Σ\boldsymbol{\Sigma} or large nn

8.3 LLM views for Black-Litterman (full practical case)

8.3.1 Documented pipeline: from news to weights with human veto

The best empirically supported integration is Kim, Lee et al. (2025, arXiv 2504.14345), a complete and reproducible framework: for each stock in the universe (S&P 500) the LLM is queried N=100N = 100 times with recent news; the mean of the repeated responses constitutes the views vector q\mathbf{q}, and the variance of the responses populates the diagonal of Ω\boldsymbol{\Omega} —higher variance implies higher uncertainty and, automatically, lower weight of the view in the posterior—, with P=IP = I (one absolute view per asset) (pypi.org). The reported result is that portfolios guided by the best-performing LLMs outperform traditional baselines in absolute and risk-adjusted terms, but —an essential caveat— the choice of LLM is not the search for a better forecaster but "a strategic choice of investment style whose success depends on its alignment with the prevailing market regime" (pypi.org). The equivalent GLS specification used by the paper makes the stacked prior-and-views structure explicit (Cambridge University Press & Assessment):

y=Xμ+ε,y=[πq],X=[IP],V=[τΣ00Ω]\mathbf{y} = X\boldsymbol{\mu} + \boldsymbol{\varepsilon}, \quad \mathbf{y} = \begin{bmatrix}\boldsymbol{\pi}\\ \mathbf{q}\end{bmatrix}, \quad X = \begin{bmatrix} I \\ P \end{bmatrix}, \quad V = \begin{bmatrix} \tau\boldsymbol{\Sigma} & \mathbf{0} \\ \mathbf{0} & \boldsymbol{\Omega} \end{bmatrix}

The full institutional pipeline, with LangChain/LangGraph at the view-generation layer and deterministic tools downstream, respects the course's backbone pattern: the LLM reasons, the math decides, the human vetoes.

The LLM reasons the views, Black-Litterman and a deterministic optimizer decide the portfolio, and a human committee approves or vetoes with an auditable trace.News / filings point-in-time → LangChain: extraction + scoring, JSON validated by Pydantic schema; LangChain: extraction + scoring, JSON validated by Pydantic schema → N = 100 repeated queries per asset; N = 100 repeated queries per asset → q = mean of responses Omega = variance of responses; q = mean of responses Omega = variance of responses → Black-Litterman: prior pi = delta Sigma w_m posterior mu_BL, Sigma_BL; Ledoit-Wolf Sigma → Black-Litterman: prior pi = delta Sigma w_m posterior mu_BL, Sigma_BL; Black-Litterman: prior pi = delta Sigma w_m posterior mu_BL, Sigma_BL → Deterministic optimizer PyPortfolioOpt / cvxpy long-only, caps, turnover; Deterministic optimizer PyPortfolioOpt / cvxpy long-only, caps, turnover → Human committee: veto / approval with auditable trail; Human committee: veto / approval with auditable trail → Orders to the OMS (approved); Human committee: veto / approval with auditable trail → Veto log + Omega recalibration (vetoed)approvedvetoedNews / filingspoint-in-timeLangChain: extraction +scoring, JSON validatedby Pydantic schemaN = 100 repeatedqueries per assetq = mean of responsesOmega = variance of responsesBlack-Litterman:prior pi = delta Sigma w_mposterior mu_BL, Sigma_BLLedoit-Wolf SigmaDeterministic optimizerPyPortfolioOpt / cvxpylong-only, caps, turnoverHuman committee:veto / approvalwith auditable trailOrders to the OMSVeto log +Omega recalibration
LLM views in Black-Litterman. The LLM answers 100 times per asset; the mean sets q and the variance sets Omega, the optimizer decides the weights, and a human committee approves or vetoes.

Snippet — view-generation layer with LangChain (structured output, closed schema):

python
from pydantic import BaseModel, Field
from langchain_openai import ChatOpenAI

class VistaActivo(BaseModel):
    ticker: str
    retorno_esperado_anual: float = Field(description="Vista de retorno, en tanto por uno")
    justificacion: str = Field(max_length=500)
    evidencia_literal: str = Field(description="Cita verbatim de la noticia que sustenta la vista")

llm = ChatOpenAI(model="gpt-5", temperature=1.0)   # temperature > 0: dispersion is the signal
chain = llm.with_structured_output(VistaActivo)

# N = 100 repeated queries per asset (arXiv 2504.14345)
respuestas = [chain.invoke({"noticias": noticias_pit, "ticker": tk}) for _ in range(100)]
q_i     = float(np.mean([r.retorno_esperado_anual for r in respuestas]))
omega_i = float(np.var([r.retorno_esperado_anual for r in respuestas], ddof=1))

Two design decisions are non-negotiable. First, the closed schema with literal evidence: each view must quote verbatim the news item that supports it (the anti-hallucination discipline of Module 6), and the news must be point-in-time —published before the decision timestamp, with ingestion latency modeled—. Second, temperature is not minimized: the dispersion of the responses is the measure of uncertainty that feeds Ω\boldsymbol{\Omega}.

Snippet — BL posterior with PyPortfolioOpt and constrained optimization:

python
from pypfopt.black_litterman import BlackLittermanModel

bl = BlackLittermanModel(
    S_lw,                                # Ledoit-Wolf covariance (never raw sample)
    pi="market_cap",                     # equilibrium prior: pi = delta Sigma w_m
    absolute_views=pd.Series(q_dict),    # q: means of the N=100 queries
    omega="idzorek",                     # or diagonal = variance of the queries
    tau=0.025,
)
mu_bl   = bl.bl_returns()
S_bl    = bl.bl_cov()
ef      = EfficientFrontier(mu_bl, S_bl)
ef.add_constraint(lambda w: w >= 0)                  # long-only
ef.add_constraint(lambda w: w <= 0.10)               # per-asset cap (Jagannathan-Ma)
weights = ef.max_sharpe(risk_free_rate=0.03)         # -> human veto before the OMS

(arXiv.org)

Critical context of the case. The headline-sentiment signal has the best empirical pedigree in the LLM literature (Lopez-Lira and Tang 2023: post-cutoff GPT-4 scores that predict the initial reaction and the subsequent drift, stronger in small-caps and negative news), but the authors themselves document that "strategy returns decay as LLM adoption increases, consistent with improved price efficiency" —the edge gets arbitraged away (skfolio.org). And Glasserman and Lin (2023) decompose the bias into look-ahead and distraction effect: in-sample, anonymized headlines perform better than identified ones, because general knowledge of the company contaminates the sentiment reading more than recall of the future —especially in large caps—, which turns headline anonymization into standard de-biasing procedure before generating views (Cambridge University Press & Assessment).

8.4 Critical evidence on LLMs and prediction

8.4.1 Memorization, Alpha Illusion and the consequence for Ω\boldsymbol{\Omega}

Four results delimit what an LLM can contribute to portfolio construction.

Memorization Problem. Lopez-Lira, Tang and Zhu (2025) —the same first author of the foundational pro-predictability paper, in a remarkable self-correction by the community— show that LLMs recall with recall-precision the exact values of economic variables prior to their cutoff (MAE of 0.03%–0.15% on unemployment, GDP and S&P 500; directional accuracy above 96%), that neither explicit instructions to respect temporal boundaries nor masking prevents it, and that post-cutoff the recall disappears (arXiv.org). Devastating conclusion: one cannot tell whether the LLM is forecasting or accessing memorized data; every backtest of LLM views inside the training window is contaminated.

Alpha Illusion and reproducibility. "The Alpha Illusion" audit (2026) of FinCon, FinMem, TradingAgents, FinAgent, QuantAgent and FLAG-Trader concludes that the alpha reported by end-to-end LLM agents should not be treated as deployment evidence: current public evidence does not distinguish robust predictive ability from temporal contamination, unmodeled frictions, Sharpe uncertainty in short windows, narrative fitting and parametric priors (Github). The "Agentic Trading" audit (2026) protocolizes 77 empirical studies and reports that zero meet the full reproducibility criteria (arXiv.org); "Profit Mirage" (2025) quantifies how dazzling returns evaporate once the model's knowledge window ends (arXiv.org). Look-ahead is structural in pre-trained language models (Sarkar and Vafa 2024) (Github).

Why LLMs do not beat systematic factors. The few works with rigorous factor control show that sentiment "alpha" shrinks substantially after adjusting for Fama-French and costs; the documented survival corresponds to small specialized models trained year by year (FinText, by Rahimikia and Drinkall), not to generalist LLMs (metricgate.com). Moreover, the "styles" LLMs exhibit in the enhanced BL are undeclared implicit factor exposures: when the model "chooses" small-caps or value, it is replicating known FF/Carhart premia without attribution (Github). The honest comparison standard remains Gu, Kelly and Xiu (2020).

Operational implication for the section 8.3 pipeline. LLM views are treated as a weak signal with high Ω\boldsymbol{\Omega}, never as truth: (i) evaluate only post-cutoff or with living benchmarks; (ii) anonymize headlines (anti-distraction); (iii) inflate Ω\boldsymbol{\Omega} with a prudential factor; (iv) validate the full system with DSR > 0.95 and PBO; (v) attribute the result against FF5/Carhart factors before claiming alpha.

Table 8.2 — Critical evidence on LLMs in financial prediction

PaperFindingDocumented bias
Lopez-Lira & Tang (2023, arXiv 2304.07619)Post-cutoff GPT-4 scores predict initial reaction (~90% hit rate portfolio-day, not tradable) and drift; long-short Sharpe 3.8 (v4) → 3.28 (v5)No costs; numbers change across versions; decay with adoption
Glasserman & Lin (2023, arXiv 2309.17322)Anonymized headlines perform better in-sample: distraction dominates look-aheadDistraction effect, mostly in large caps
Kim, Lee et al. (2025, arXiv 2504.14345)LLM views (mean of 100 queries, variance → Ω\boldsymbol{\Omega}) beat baselines; each LLM is a regime-dependent "style"Styles = implicit factor exposures; short window
Lopez-Lira, Tang & Zhu (2025, arXiv 2504.14765)Exact pre-cutoff recall (>96% directional accuracy; MAE 0.03–0.15%); zero recall post-cutoffMemorization: forecasting indistinguishable from recall
The Alpha Illusion (2026, arXiv 2605.16895)End-to-end agents' alpha is not deployment evidence; "linguistic confidence is not a tradable probability"Temporal contamination, omitted frictions, short-window Sharpe
Agentic Trading (2026) / Profit Mirage (2025, arXiv 2510.07920)0 of 77 studies fully reproducible; returns evaporate after the cutoffParametric leakage; systemic irreproducibility

Exercises

  1. GMV with cvxpy. With the module's four synthetic assets (μ=(0,06,0,09,0,12,0,15)\boldsymbol{\mu} = (0{,}06, 0{,}09, 0{,}12, 0{,}15), correlations given), solve the long-only GMV with a 40% per-asset cap using cvxpy. Numerically verify the closed-form formula wGMV=Σ−11/(1⊤Σ−11)\mathbf{w}_{\text{GMV}} = \boldsymbol{\Sigma}^{-1}\mathbf{1}/(\mathbf{1}^\top\boldsymbol{\Sigma}^{-1}\mathbf{1}) without constraints and compare. Repeat with the Ledoit-Wolf shrunk covariance (δ∗=0,45\delta^* = 0{,}45) and quantify the change in σGMV\sigma_{\text{GMV}}.

  2. Black-Litterman with simulated LLM views. Starting from π=δΣwm\boldsymbol{\pi} = \delta\boldsymbol{\Sigma}\mathbf{w}_m with δ=2,5\delta = 2{,}5, simulate two absolute "LLM" views: q=(0,18,0,02)\mathbf{q} = (0{,}18, 0{,}02) on assets 3 and 4, with ω1=0,001\omega_1 = 0{,}001 (confident view) and ω2=0,05\omega_2 = 0{,}05 (weak view). Compute μBL\boldsymbol{\mu}_{BL} with both posterior forms and check that they coincide to machine precision. Then double both ω\omega and explain, using the formulas, why the posterior retracts toward π\boldsymbol{\pi}.

  3. Fractional Kelly. A strategy has p=0,55p = 0{,}55, b=1b = 1. (a) Compute f∗f^* with the discrete formula. (b) Plot G(f)G(f) and mark f∗f^*, half-Kelly and quarter-Kelly. (c) Simulate 1,000 trajectories of 252 bets for c∈{1,1/2,1/4}c \in \{1, 1/2, 1/4\} and compare median growth, volatility and maximum drawdown. Why does institutional practice choose c≤1/2c \leq 1/2 even though expected growth is lower?

  4. HRP versus GMV. With an 8-asset correlation matrix with two strong clusters (intra-cluster correlation 0.7, inter-cluster 0.1), implement HRP recursive bisection (distance (1−ρ)/2\sqrt{(1-\rho)/2}, Ward linkage) and compare the weights and the simulated out-of-sample variance against GMV with sample covariance. Repeat with 60 observations per asset to exacerbate the ill-conditioning of Σ^\hat{\boldsymbol{\Sigma}} and explain the result.

  5. Sensitivity and defenses. Perturb each component of μ^\hat{\boldsymbol{\mu}} by ±1\pm 1 pp. (16 configurations) and record the variation range of the unconstrained tangency weights. Repeat with (a) long-only constraints + 25% cap and (b) μ\boldsymbol{\mu} shrunk 50% toward μGMV\mu_{\text{GMV}}. Relate the sensitivity reduction to the Jagannathan-Ma theorem.

  6. Critical validation. Take the backtest Sharpe from exercise 4, assume T=36T = 36 months, γ^3=−0,5\hat{\gamma}_3 = -0{,}5, γ^4=4\hat{\gamma}_4 = 4 and N=20N = 20 trials with VSR=0,25V_{SR} = 0{,}25, and compute the DSR. Does it pass the 0.95 threshold? List which biases from Table 8.2 could be present if the "views" had been generated by an LLM with a cutoff later than the start of the backtest.


Module 8 of 15 — LangChain for Quantitative Trading. Data and versions verified as of July 2026; prices and market figures subject to change. LangChain 1.3.14 / langchain-core 1.5.2.


// check

Check your understanding

Self-assessment with instant feedback. No score is stored.

  1. What property makes the GMV portfolio "the most robust estimator of the Markowitz family"?

    Show answer

    B. The closed-form formula w_GMV = Σ⁻¹1/(1ᵀΣ⁻¹1) contains no μ in any term. Since Merton (1980) showed that the mean is practically inestimable while the covariance is estimated with good precision, giving up the noisiest input is exactly what gives the GMV its robustness (sections 8.1.1 and 8.2).

  2. With correlation 0.7, lowering one asset's expected return from 10% to 8% reduces its optimal weight from 0.50 to 0.18 (Best and Grauer). What phenomenon does this example illustrate?

    Show answer

    C. In correlated universes Σ is nearly singular, and multiplying by Σ⁻¹ amounts to multiplying by a large number: plausible estimation errors turn into massive rotations. This is the mechanism Michaud named error maximization and which Figure 8.2 reproduces (12.2% → 26.1% with ±2 pp.).

  3. According to Jagannathan and Ma (2003), why does the long-only GMV with upper caps beat the unconstrained GMV out of sample?

    Show answer

    B. The constrained GMV computed with Σ̂ is identical to the unconstrained GMV of a modified matrix where the Lagrange multipliers shrink certain covariances. Constraining is regularizing: that is why the module's operational lesson is that caps and long-only are statistical regularization, not concessions to compliance (section 8.2.1).

  4. In the Kim, Lee et al. pipeline (arXiv 2504.14345) that integrates LLM views into Black-Litterman, what populates the vector q and the diagonal of Ω?

    Show answer

    C. The framework queries the LLM 100 times per stock: the mean of the responses is the view and their variance measures the uncertainty, so a dispersed response automatically receives less weight in the posterior. That is why temperature is not minimized: dispersion is the signal (section 8.3.1).

  5. Glasserman and Lin (2023) show that, in-sample, anonymized headlines perform better than identified ones. What does this operationally imply for the views pipeline?

    Show answer

    B. Distraction dominates recall of the future, especially in large caps: knowing which company is being discussed degrades the reading of the headline. That is why the module turns anonymization into standard de-biasing procedure before generating views (critical context of section 8.3.1 and Table 8.2).

  6. A backtest of LLM views over 2021–2023, with a model whose training cutoff is 2024, reports a Sharpe of 2.1 without costs. What is the correct conclusion?

    Show answer

    C. The Memorization Problem (Lopez-Lira, Tang and Zhu 2025) documents exact recall of pre-cutoff economic values that neither instructions nor masking eliminate, and the contamination is undetectable by inspecting the code. Evaluation is only valid post-cutoff or with living benchmarks (section 8.4.1).

  7. Why does institutional practice use fractional Kelly with c ≤ 1/2 even though it reduces expected growth?

    Show answer

    B. f* depends on the edge (p, b or μ/σ²), which is estimated with error; overestimating it with full Kelly leads to over-leverage. Fractioning is the standard insurance —Thorp himself operated in that range— and connects to the same fragility of the tangency portfolio, since multivariate Kelly is the unnormalized tangency (section 8.1.2).

  8. What does the Deflated Sharpe Ratio (Bailey and López de Prado 2014) correct when evaluating an allocation backtest?

    Show answer

    B. The DSR compares the estimated Sharpe with the maximum expected Sharpe under the null after N trials, adjusting for skewness, kurtosis and T. The module's practical rule is to require DSR > 0.95, complemented with PBO via CSCV, before considering any allocation as deployment evidence (section 8.2.1).