Markowitz mean-variance optimization picks portfolio weights to balance expected return against variance. For target return :
Sweep to trace the efficient frontier — the set of portfolios with maximum return per unit of variance.
The math is convex and has clean closed forms via Lagrangians. The trick is the inputs: and are estimated from data and tiny errors in expected returns can produce hugely concentrated, unstable optimal portfolios. This is the "Markowitz curse" — and is why robust techniques (shrinkage, Black-Litterman, robust optimization) are widely used in practice.
Despite its limitations, mean-variance is the foundation of modern portfolio theory and underlies CAPM, factor investing, and risk parity.