Sub topic 10
Solver in practice: product mix, funding mix, and capital allocation
This chapter applies Solver to three standard finance problems. It assumes you can set up the objective cell, variable cells, and constraints from the earlier chapters, and that you know the three solving methods (Simplex LP, GRG Nonlinear, Evolutionary). Here the focus is on how each business question becomes a model, which method fits, and which mistakes recur.
The shared pattern
Every Solver problem in this chapter follows the same steps.
- Put the decision quantities in input cells. These become the variable cells.
- Write formulas that turn those inputs into one objective, such as profit, cost of capital, or NPV.
- Write formulas for each limit, such as machine hours, a budget, or a funding cap. Put each limit in its own cell, next to the figure it restricts.
- Tell Solver to maximize or minimize the objective, add one constraint per limit, and choose a method.
The method follows from the structure of the formulas.
Product mix
A product mix problem decides how many units of each product to make when resources are limited. It is the classic linear problem, because profit and resource use both scale in direct proportion to units.
Suppose product X earns 20 per unit and product Y earns 30. X uses 2 machine hours per unit and Y uses 4. You have 100 machine hours and a demand cap of 40 total units.
A workable layout:
A B C
1 Product X Y
2 Units (variable) 30 10
3 Profit per unit 20 30
4 Machine hrs/unit 2 4
6 Total profit =SUMPRODUCT(B2:C2,B3:C3) <- objective
7 Hours used =SUMPRODUCT(B2:C2,B4:C4) <= 100
8 Total units =SUM(B2:C2) <= 40In Solver:
- Set the objective to the cell holding total profit, with Max selected.
- Set the variable cells to the units row.
- Add the constraints: hours used is at most 100, total units is at most 40.
- Tick "Make Unconstrained Variables Non-Negative".
- Choose Simplex LP.
The optimum is 30 units of X and 10 of Y, for a profit of 900. Both constraints are binding there, which means each is used up exactly. The sensitivity report shows a positive shadow price for each. A shadow price is the profit gained from one more unit of that resource.
You can check the answer outside Excel with a linear program:
from scipy.optimize import linprog
# Maximize 20*x + 30*y, so minimize the negative.
c = [-20, -30]
A_ub = [[2, 4], # machine hours per unit of each product
[1, 1]] # total units limited by a demand cap
b_ub = [100, 40]
res = linprog(c, A_ub=A_ub, b_ub=b_ub, bounds=[(0, None), (0, None)])
print(res.x, -res.fun)The output is [30. 10.] 900.0.
Common product mix errors
- Using a hardcoded total. If the hours-used cell contains a typed number instead of a formula, Solver finds a "solution" that ignores the real limit.
- Missing the non-negativity bound. Without it, Solver may choose negative units of a low-margin product to free up capacity for a high-margin one.
- Fractional units. Simplex LP returns 12.5 units when 12.5 is optimal. If units are indivisible, add an
intconstraint on the variable cells. This makes the problem harder to solve, and the answer can be slightly worse than the fractional one.
Funding mix
A funding mix problem chooses the share of capital raised from each source, usually to minimize the weighted average cost of capital (WACC). The variable cells are the weights. The objective is the sum of each weight times its after-tax cost.
| Source | Cost used in WACC | Limit |
|---|---|---|
| Debt | 5% pre-tax, 3.75% after 25% tax | At most 40% of capital |
| Preferred | 6% | At most 10% |
| Equity | 11% | At least 50% |
The constraints are:
- The weights sum to 100%. Use an equality constraint (
=) here, and do not rely on an inequality. - Each weight stays within its limit.
With these fixed costs the problem is linear. The optimum fills the cheapest sources first: 40% debt, 10% preferred, and 50% equity, which gives a WACC of 7.6%.
Real funding problems are rarely this clean. Lenders charge more and equity holders demand more as leverage rises, so the cost of each source depends on the weights. If you model the cost of equity as a function of debt-to-equity, the objective is no longer linear. Switch to GRG Nonlinear and give it a sensible starting mix, because GRG may stop at a local optimum. A local optimum is the best point near where the search started, which is not always the best point overall.
Common funding mix errors
- Weights not summing to 1. If you leave out the equality constraint, Solver sets all the cheap weights to their maximum and the total exceeds 100%.
- A starting point of all zeros. Some nonlinear formulas divide by a weight, so a zero start produces
#DIV/0!and Solver stops. Start with a plausible mix such as 30/10/60. - Treating the solution as a recommendation. The result depends on the cost assumptions and the limits. Those are inputs to challenge, and Solver does not validate them.
Capital allocation
A capital allocation problem decides which projects to fund from a limited budget. Each project is a yes-or-no decision, so the variable cells are binary: 1 means fund it and 0 means skip it. The objective is total NPV, and the budget is the constraint.
| Project | Capex | NPV |
|---|---|---|
| A | 40 | 18 |
| B | 30 | 14 |
| C | 50 | 20 |
| D | 20 | 7 |
The budget is 100. Layout:
A B C D
1 Project A B C D
2 Fund? (1/0) 0 0 0 0 <- variable cells
3 Capex 40 30 50 20
4 NPV 18 14 20 7
6 Total NPV =SUMPRODUCT(B2:E2,B4:E4) <- maximize
7 Capex used =SUMPRODUCT(B2:E2,B3:E3) <= 100Add a constraint that the variable cells are bin. Solver treats bin as an integer limited to 0 or 1. Choose Simplex LP.
Compare this with the version that allows partial funding. If the variable cells may be any value from 0 to 1, the best plan is to fund B, then A, then 30/50 of C. That gives an NPV of 44, but nobody can fund 60% of a project that is all-or-nothing. With binary variables the best plan is B, C, and D, which uses exactly 100 of budget and has an NPV of 41. Ranking by NPV per unit of capex (a profitability index) gives the fractional answer. For binary choices it can pick a worse set than the best one.
You can confirm the binary result with a mixed-integer solver:
import numpy as np
from scipy.optimize import milp, LinearConstraint, Bounds
npv = np.array([18, 14, 20, 7])
capex = np.array([40, 30, 50, 20])
res = milp(
c=-npv, # maximize NPV
constraints=LinearConstraint(capex.reshape(1, -1), ub=100),
integrality=np.ones(4), # every variable is integer
bounds=Bounds(0, 1), # integer within 0..1 means binary
)
print(res.x, -res.fun)The output is [0. 1. 1. 1.] 41.0.
Extensions that stay linear
You can add real-world rules without leaving Simplex LP, as long as each rule is a sum of the binary cells compared with a number.
- Mutually exclusive projects. If A and B are alternatives, require that their fund cells sum to at most 1.
- Dependency. If C needs D to be funded, require that C's cell is at most D's cell.
- Multiple budget years. Add one capex row and one constraint per year.
Why Solver may report different answers on different runs
For a linear problem, Simplex LP finds the global optimum, and Solver confirms this with a message that the problem satisfies all conditions. For nonlinear problems and Evolutionary runs, the result can change with the starting values or the random seed. Run those a few times from different starts. If the results disagree, the objective is probably multi-peaked, so keep the best result and test it independently.
Checklist before trusting a result
- Every variable cell holds a typed value, not a formula.
- The objective and each constraint cell depend on the variable cells through formulas.
- The method matches the structure: Simplex LP only if the model is truly linear.
- At least one constraint is binding. If none is, the problem may be unbounded in practice, or a limit is missing.
- Recompute the answer by hand or in code, as the Python checks above do.
Exercise
In the capital allocation example, the budget rises from 100 to 120, and the four projects (A: capex 40, NPV 18; B: 30, 14; C: 50, 20; D: 20, 7) are still all-or-nothing. Which projects should be funded, and what is the total NPV?
Show answer
Test the sets that fit within 120. A+B+C costs 120 with an NPV of 18+14+20 = 52. A+B+D costs 90 with an NPV of 39. A+C+D costs 110 with an NPV of 45. B+C+D costs 100 with an NPV of 41. All four cost 140, which is too much. The best plan funds A, B, and C, using the full 120 for an NPV of 52.
Exercise
A funding model has three weights (debt, preferred, equity) and you forget to add the constraint that they sum to 100%. What does Solver do when you minimize WACC, and how do you fix it?
Show answer
Solver minimizes cost by setting each cheap source to its maximum and the weights can sum to less than 100%. In the extreme it can set all weights to zero, which gives a WACC of 0%. Fix it by adding an equality constraint that the weights sum to 1, and keep the non-negativity bound on.