∇ProvenDecisions
Ctrl K

Markowitz minimum-variance portfolio: a quadratic programming example, solved and checked

The Markowitz minimum-variance portfolio is a classic quadratic programming problem. Here it is solved by a real solver (CLARABEL) and checked: every constraint, the dual, and the optimality certificate. Change the numbers below and solve your own.

Answer. The smallest objective value is 0.0159946, at w1 = 0.430427, w2 = 0.329002, w3 = 0.24057. All 5 constraints are satisfied (largest violation 9e-15, within the solver's tolerance). Optimal, numerically checked.

Solve your own version free, no account needed

Say it or snap it

You can give ProvenDecisions this problem out loud or as a photo. The app wrote down both, solved them, and got the same checked answer as the typed version.

🎙️ Spoken (23 seconds)

What the app heard: “3 assets have expected returns of 8, 12 and 15 percent and volatilities of 10, 20 and 30 percent. The correlation is 0.2 between assets 1 and 2, 0.1 between assets 1 and 3, and 0.3 between assets 2 and 3. Invest all the money with no short sales and an expected return of at least 11 percent. Minimize the portfolio variance.”

📷 Photographed
Photo of the Markowitz minimum-variance portfolio written on a note

The problem

Three assets have expected returns 8%, 12% and 15%, volatilities 10%, 20% and 30%, and correlations 0.2 (1-2), 0.1 (1-3), 0.3 (2-3). Invest fully, no short sales, with expected return at least 11%. Minimize portfolio variance.

How the model was built

The objective as written from the problem, before the numbers are multiplied out:

The model

Each line has a plain-language note on the right.

make this as small as possible
limit 1: left side must equal 1
limit 2: left side must reach at least 0.11
fraction of portfolio invested in asset 1 (fraction) cannot be negative
fraction of portfolio invested in asset 2 (fraction) cannot be negative
fraction of portfolio invested in asset 3 (fraction) cannot be negative

In matrix form

With its numbers:

What is being decided

There are 3 decision variables.

VariableTypeMeaning
w1real numberfraction of portfolio invested in asset 1 (fraction)
w2real numberfraction of portfolio invested in asset 2 (fraction)
w3real numberfraction of portfolio invested in asset 3 (fraction)

Goal and limits

Minimize the objective subject to 5 constraints, of which 3 are simple bounds on a single variable.

Problem type

Convex QP, complexity level 3: a convex quadratic objective or constraint. Solved with CLARABEL at the Medium solver tier.

The answer at a glance

The optimal value of each decision, as the solver returned it.

w10.430427w20.329002w30.24057

Which constraints hold the answer in place

Binding (no slack left): (1) w1 + w2 + w3 = 1; (2) 0.08*w1 + 0.12*w2 + 0.15*w3 >= 0.11. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1w1 + w2 + w3 = 1110yes
20.08*w1 + 0.12*w2 + 0.15*w3 >= 0.110.110.114.30819e-09yes
3w1 >= 00.43042700.430427
4w2 >= 00.32900200.329002
5w3 >= 00.2405700.24057

Algebraic model (low level)

Decision variables, objective and every constraint written out; this is exactly what the solver receives.

Model code (cvxpy)

The same model in cvxpy, ready to run.

import cvxpy as cp

w1 = cp.Variable(name='w1')  # fraction of portfolio invested in asset 1 (fraction)
w2 = cp.Variable(name='w2')  # fraction of portfolio invested in asset 2 (fraction)
w3 = cp.Variable(name='w3')  # fraction of portfolio invested in asset 3 (fraction)

objective = cp.Minimize(0.01*w1**2 + 0.008*w1*w2 + 0.006*w1*w3 + 0.04*w2**2 + 0.036*w2*w3 + 0.09*w3**2)
constraints = [
    w1 + w2 + w3 == 1,
    0.08*w1 + 0.12*w2 + 0.15*w3 >= 0.110000000000000,
    w1 >= 0,
    w2 >= 0,
    w3 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='CLARABEL')
print(problem.status, problem.value)
print('w1 =', w1.value)
print('w2 =', w2.value)
print('w3 =', w3.value)

The dual problem

Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. Strong duality: primal and dual optima are equal (0.0159946).

Dual variablePricesValue
y1multiplier of an inequality constraint0.643504
y2multiplier of an inequality constraint0
y3multiplier of an inequality constraint0
y4multiplier of an inequality constraint4.88951e-09
nu1multiplier of an equality constraint0.0387963

Solve your own

This is the model as the app reads it. Change any number and solve it in the free box on the front page (no account needed).

minimize 0.01*w1^2 + 0.04*w2^2 + 0.09*w3^2 + 0.008*w1*w2 + 0.006*w1*w3 + 0.036*w2*w3
subject to
w1 + w2 + w3 = 1
0.08*w1 + 0.12*w2 + 0.15*w3 >= 0.11
w1, w2, w3 >= 0
# w1 = fraction of portfolio invested in asset 1 (fraction)
# w2 = fraction of portfolio invested in asset 2 (fraction)
# w3 = fraction of portfolio invested in asset 3 (fraction)

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (CLARABEL, OSQP) agree on. Built 2026-11-10.

Related examples

All 50 solved examples

Try ProvenDecisions free: type, photograph or say an optimization problem; every answer is checked by a solver.

What do you want to optimize?

Type the math, describe it in words, snap a photo or say it. ProvenDecisions builds the model, solves it, checks it and walks you through it.

One constraint per line, or separated by commas. Add integer: x, y or binary: z for whole-number decisions. LaTeX works too.

Try: