The bottom line: how you define "risk" changes which investment portfolio an optimizer tells you to buy. A demonstration notebook built with AMPL, a modeling language for optimization, and Python walks through three different mathematical ways to measure risk, then builds the best possible portfolio under each one. The point isn't that one method is right and the others are wrong — it's that the choice of risk measure is itself a decision that belongs to the investor, not just the software.

Classic portfolio theory, going back to Harry Markowitz in the 1950s, measures risk as the variance (wobbliness) of returns — good and bad swings count equally. That's mathematically convenient but strange in practice: nobody complains about a portfolio that unexpectedly goes up. The three strategies in this notebook — semivariance, Conditional Value-at-Risk (CVaR), and Conditional Drawdown-at-Risk (CDaR) — all try to fix that by focusing specifically on the downside: how bad losses can get, and how bad they've been historically.

Semivariance only counts the volatility that comes from returns falling below a target, ignoring upside swings entirely. In plain terms, an optimizer using semivariance is only "afraid" of days the portfolio loses money, not days it makes an unusually large gain. Formally, for a portfolio return $r_p$ with target $\tau$, the downside risk is $$ SV = \mathbb{E}\big[\min(r_p - \tau, 0)^2\big], $$ and the optimizer picks portfolio weights $w$ to minimize this quantity (or trade it off against expected return) subject to the weights summing to 1 and staying non-negative.

CVaR, sometimes called "expected shortfall," asks a sharper question: if things go bad — say, in the worst 5% of outcomes — how bad, on average, does it get? Regulators and risk managers like CVaR because, unlike a simple Value-at-Risk cutoff, it doesn't ignore the severity of the tail once you're past the threshold. Mathematically, for a loss distribution and confidence level $\alpha$ (e.g., 95%), CVaR is defined as $$ CVaR_\alpha = \mathbb{E}\big[L \mid L \ge VaR_\alpha\big], $$ and — thanks to a formulation by Rockafellar and Uryasev — it can be minimized with a linear program, which is a big part of why it's popular with practitioners who need something a solver can actually crunch at scale.

CDaR looks at a different kind of pain: not single bad days, but sustained losing streaks. Drawdown measures how far a portfolio has fallen from its previous peak; CDaR focuses optimization effort on the worst stretches of drawdown, which matters enormously to investors (or fund managers reporting to clients) who care as much about how long a slump lasts as how deep any single day's loss is.

In the notebook, all three strategies are set up as optimization problems, solved with AMPL, and compared using ordinary performance yardsticks: annualized return, volatility, Sharpe ratio, and maximum drawdown. Because each method targets a different flavor of "bad," they can produce noticeably different portfolios from the same set of assets and historical data — one might trade off more average volatility to avoid deep drawdowns, another might tolerate occasional bad tail events to squeeze out steadier day-to-day performance.

This matters for anyone building or evaluating a systematic investment strategy: a pension fund worried about multi-year slumps might prefer CDaR; a trading desk worried about a single catastrophic quarter might lean on CVaR; an asset manager who just wants smoother year-over-year performance might use semivariance. The broader lesson for the optimization crowd is a familiar one — the objective function is a modeling choice with real consequences, and swapping it out is often as simple as changing a few lines of an AMPL model, which is exactly what makes tools like this useful for testing multiple strategies quickly before committing real capital.

Sources: AMPL Colaboratory, "Porfolio Optimization with Multiple Risk Strategies in Python with AMPL," https://ampl.com/colab/notebooks/porfolio-optimization-with-multiple-risk-strategies-in-python-with-ampl.html (notebook author: Mukeshwaran Baskaran)