∇ProvenDecisions
Ctrl K

Cash-flow matching with bonds: a linear programming example, solved and checked

The cash-flow matching with bonds 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 308.668, at xA = 0.86469, xB = 1.42857, xC = 1.06469, s1 = 0, s2 = 0. All 8 constraints are satisfied exactly. Exactly proven optimal.

Solve your own version free, no account needed

The problem

Liabilities of $100k, $120k and $150k are due at the ends of years 1, 2 and 3. Bond A (price $95) pays $100 at year 1. Bond B (price $90) pays $5 at years 1 and 2 and $105 at year 3. Bond C (price $92) pays $6 at year 1 and $106 at year 2. Surplus cash is carried forward at 0% interest. Buy fractional units (in thousands) to meet every liability at minimum cost.

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 100
limit 2: left side must equal 120
limit 3: left side must equal 150
units of Bond A bought (thousands of bonds) cannot be negative
units of Bond B bought (thousands of bonds) cannot be negative
units of Bond C bought (thousands of bonds) cannot be negative
surplus cash carried from year 1 to year 2 ($k) cannot be negative
surplus cash carried from year 2 to year 3 ($k) cannot be negative

In matrix form

With its numbers:

What is being decided

There are 5 decision variables.

VariableTypeMeaning
xAreal numberunits of Bond A bought (thousands of bonds)
xBreal numberunits of Bond B bought (thousands of bonds)
xCreal numberunits of Bond C bought (thousands of bonds)
s1real numbersurplus cash carried from year 1 to year 2 ($k)
s2real numbersurplus cash carried from year 2 to year 3 ($k)

Goal and limits

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

Problem type

LP, complexity level 2: a linear program. Solved with HIGHS at the Medium solver tier.

The answer at a glance

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

xA0.86469xB1.42857xC1.06469s10s20

Which constraints hold the answer in place

Binding (no slack left): (1) -s1 + 100*xA + 5*xB + 6*xC = 100; (2) s1 - s2 + 5*xB + 106*xC = 120; (3) s2 + 105*xB = 150; (7) s1 >= 0; (8) s2 >= 0. Changing a binding constraint changes the answer; a slack one can move a little without effect.

#ConstraintValueLimitSlackBinding
1-s1 + 100*xA + 5*xB + 6*xC = 1001001000yes
2s1 - s2 + 5*xB + 106*xC = 1201201200yes
3s2 + 105*xB = 1501501500yes
4xA >= 00.8646900.86469
5xB >= 01.4285701.42857
6xC >= 01.0646901.06469
7s1 >= 0000yes
8s2 >= 0000yes

Why this is optimal

A proof you can check by hand. Multiply each constraint in the table by its weight and add them up: the result is a lower limit on the objective that holds for every plan meeting the constraints. Our answer reaches that limit exactly, so no plan does better. Every step was checked in exact fractions, not rounded decimals.

#ConstraintWeight
1-s1 + 100·xA + 5·xB + 6·xC = 10019/20
2s1 - s2 + 5·xB + 106·xC = 120863/1060
3s2 + 105·xB = 1501721/2226

Algebraic model (low level)

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

Standard form

As a linear program: minimize cᵀx subject to A x ≤ b (the inequality rows) and A_eq x = b_eq (the equations); a maximization is written as minimizing the negative.

Model code (cvxpy)

The same model in cvxpy, ready to run.

import cvxpy as cp

xA = cp.Variable(name='xA')  # units of Bond A bought (thousands of bonds)
xB = cp.Variable(name='xB')  # units of Bond B bought (thousands of bonds)
xC = cp.Variable(name='xC')  # units of Bond C bought (thousands of bonds)
s1 = cp.Variable(name='s1')  # surplus cash carried from year 1 to year 2 ($k)
s2 = cp.Variable(name='s2')  # surplus cash carried from year 2 to year 3 ($k)

objective = cp.Minimize(95*xA + 90*xB + 92*xC)
constraints = [
    -s1 + 100*xA + 5*xB + 6*xC == 100,
    s1 - s2 + 5*xB + 106*xC == 120,
    s2 + 105*xB == 150,
    xA >= 0,
    xB >= 0,
    xC >= 0,
    s1 >= 0,
    s2 >= 0,
]
problem = cp.Problem(objective, constraints)
problem.solve(solver='HIGHS')
print(problem.status, problem.value)
print('xA =', xA.value)
print('xB =', xB.value)
print('xC =', xC.value)
print('s1 =', s1.value)
print('s2 =', s2.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 (308.668).

Dual variablePricesValue
y1price of constraint '-s1 + 100*xA + 5*xB + 6*xC = 100' (objective change per extra unit of its right-hand side)0.95
y2price of constraint 's1 - s2 + 5*xB + 106*xC = 120' (objective change per extra unit of its right-hand side)0.814151
y3price of constraint 's2 + 105*xB = 150' (objective change per extra unit of its right-hand side)0.773136

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 95 xA + 90 xB + 92 xC
subject to
100 xA + 5 xB + 6 xC - s1 = 100
s1 + 5 xB + 106 xC - s2 = 120
s2 + 105 xB = 150
xA, xB, xC, s1, s2 >= 0
# xA = units of Bond A bought (thousands of bonds)
# xB = units of Bond B bought (thousands of bonds)
# xC = units of Bond C bought (thousands of bonds)
# s1 = surplus cash carried from year 1 to year 2 ($k)
# s2 = surplus cash carried from year 2 to year 3 ($k)

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: