∇ProvenDecisions
Ctrl K

Mean-absolute-deviation portfolio: a linear programming example, solved and checked

The mean-absolute-deviation portfolio is a classic linear programming problem. Here it is solved by a real solver (HIGHS) 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.611111, at wa = 0.222222, wb = 0.777778. All 3 constraints are satisfied exactly. Optimal, numerically checked.

Solve your own version free, no account needed

The problem

Two funds returned (%) A: 4, -2, 3, 1 and B: 1, 2, -1, 2 in four equally likely scenarios. Fully invested, no shorts. Minimize the mean absolute deviation of the portfolio return from its mean.

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
fraction of the portfolio invested in fund A cannot be negative
fraction of the portfolio invested in fund B cannot be negative

In matrix form

With its numbers:

The problem as a linear program

Each absolute value (or max, min) gets a helper variable, tied to the term it stands for by the lines below: t1 stands for |0.5*wa - wb|; t2 stands for |3.5*wa - wb|; t3 stands for |1.5*wa - 2*wb|; t4 stands for |wa|. At the optimum each helper equals its term, so this linear program has the same optimum as your problem; it is what the solver solved, and what the dual is built from.

the same objective, with each helper in place of the term it stands for
limit 1: left side must equal 1
fraction of the portfolio invested in fund A cannot be negative
fraction of the portfolio invested in fund B cannot be negative
t1 is at least 0.5*wa - wb
and at least -0.5*wa + wb, so t1 is at least |0.5*wa - wb|
t2 is at least 3.5*wa - wb
and at least -3.5*wa + wb, so t2 is at least |3.5*wa - wb|
t3 is at least 1.5*wa - 2*wb
and at least -1.5*wa + 2*wb, so t3 is at least |1.5*wa - 2*wb|
t4 is at least wa
and at least -wa, so t4 is at least |wa|

What is being decided

There are 2 decision variables.

VariableTypeMeaning
wareal numberfraction of the portfolio invested in fund A
wbreal numberfraction of the portfolio invested in fund B

Goal and limits

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

Problem type

LP (after reformulating |.|, max, min), complexity level 1: a small linear program. Solved with HIGHS at the Medium solver tier.

Picture

Shaded: every point that satisfies all the constraints. Dot: the optimum. Dashed: the objective's level line through it.

(0.222222, 0.777778)-0.4-0.40.050.050.50.50.950.951.41.4wawb

The answer at a glance

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

wa0.222222wb0.777778

Which constraints hold the answer in place

Binding (no slack left): (1) wa + wb = 1. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1wa + wb = 1110yes
2wa >= 00.22222200.222222
3wb >= 00.77777800.777778

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

wa = cp.Variable(name='wa')  # fraction of the portfolio invested in fund A
wb = cp.Variable(name='wb')  # fraction of the portfolio invested in fund B

objective = cp.Minimize(0.625*cp.abs(wa) + 0.25*cp.abs(0.5*wa - wb) + 0.25*cp.abs(1.5*wa - 2*wb) + 0.25*cp.abs(3.5*wa - wb))
constraints = [
    wa + wb == 1,
    wa >= 0,
    wb >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('wa =', wa.value)
print('wb =', wb.value)

The dual problem

Every constraint of the original (primal) problem gets a price, and every primal variable becomes a constraint on those prices. First the problem was written as an exact linear program with helper variables t1, t2, t3, t4: each helper is held at or above (or below) the terms it stands for, so at the optimum it equals them and the optimum is unchanged. This is the dual of that linear program. Strong duality: primal and dual optima are equal (0.611111).

Dual variablePricesValue
y1price of constraint 'wa + wb = 1' (objective change per extra unit of its right-hand side)0.611111
y2price of constraint 't1 >= 0.5*wa - wb' (objective change per extra unit of its right-hand side)0
y3price of constraint 't1 >= -0.5*wa + wb' (objective change per extra unit of its right-hand side)0.25
y4price of constraint 't2 >= 3.5*wa - wb' (objective change per extra unit of its right-hand side)0.194444
y5price of constraint 't2 >= -3.5*wa + wb' (objective change per extra unit of its right-hand side)0.0555556
y6price of constraint 't3 >= 1.5*wa - 2*wb' (objective change per extra unit of its right-hand side)0
y7price of constraint 't3 >= -1.5*wa + 2*wb' (objective change per extra unit of its right-hand side)0.25
y8price of constraint 't4 >= wa' (objective change per extra unit of its right-hand side)0.625
y9price of constraint 't4 >= -wa' (objective change per extra unit of its right-hand side)0

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.25*(abs(2.5*wa) + abs(-3.5*wa + wb) + abs(1.5*wa - 2*wb) + abs(-0.5*wa + wb))
subject to
wa + wb = 1
wa, wb >= 0
# wa = fraction of the portfolio invested in fund A
# wb = fraction of the portfolio invested in fund B

Change the numbers and solve it

Checked: the app's answer matches the reference answer in our test set, which two solvers (HIGHS, CLARABEL) 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: