Sub topic 9
Removing the loop with algebra
This chapter assumes you can build a debt schedule with a cash flow waterfall and that you know IF, MIN, MAX and AVERAGE. It also assumes you have seen why average-balance interest on a cash-sweep loan is circular. Here you remove the loop by rearranging the equations, so the spreadsheet never needs iterative calculation.
The idea in one paragraph
A circular reference is a set of equations that each refer to the others. If the equations are linear, you can solve them on paper once and put the solution in the cells. Average-balance interest on a sweep is linear, because interest is a rate times a balance and the balance is a sum of cash flows. The result is a formula that returns the same numbers as the iterated loop, with no circular reference, no circuit breaker and no stuck errors.
Deriving the closed form
Use the same debt schedule as the earlier chapters. The opening balance is O, cash flow available for debt service is C, and the annual rate is r. Interest is I, repayment is P, and the closing balance is K.
- Interest is charged on the average balance: I = r × (O + K) / 2.
- The sweep repays whatever cash is left after interest: P = C − I.
- The closing balance is the opening balance less repayment: K = O − P = O − C + I.
Interest appears on both sides once you substitute step 3 into step 1:
I = r × (O + O − C + I) / 2 = r × (2O − C) / 2 + (r / 2) × I
Move the I term to the left and divide:
I × (1 − r/2) = r × (2O − C) / 2
I = r × (2O − C) / 2 / (1 − r/2)
With O = 500, C = 100 and r = 8%:
- The numerator is 0.08 × 900 / 2 = 36.
- The denominator is 1 − 0.04 = 0.96.
- Interest is 36 / 0.96 = 37.5.
- Repayment is 100 − 37.5 = 62.5, and the closing balance is 437.5.
Check by plugging back in: the average balance is (500 + 437.5) / 2 = 468.75, and 8% of that is 37.5. The loop is consistent.
A better form: solve for repayment first
The formula above gives interest first, but it only holds when the sweep is unconstrained. A more useful rearrangement solves for repayment. Substitute I = C − P into the interest equation:
C − P = r × (O + O − P) / 2 = r × O − (r/2) × P
Collect the P terms:
P × (1 − r/2) = C − r × O
P = (C − r × O) / (1 − r/2)
Check with the same numbers: (100 − 40) / 0.96 = 62.5. The two derivations agree.
Repayment now depends only on inputs: the opening balance, CFADS and the rate. Closing debt follows from repayment, and interest follows from closing debt. Nothing points back, so the chain is a straight line.
Handling the MIN and MAX limits
Real sweeps have limits. You cannot repay more than the opening balance, and you do not borrow more when CFADS falls short of interest, at least on a term loan. The earlier chapters wrote this as MIN(Debt_Open, MAX(0, CFADS - Interest)).
The limits are easy to keep because the closed-form repayment is monotonic in CFADS. If the unconstrained answer is below zero, the true answer is zero. If it is above the opening balance, the true answer is the opening balance. You clamp the closed-form value instead of clamping a value that depends on interest.
There are three regimes:
| Regime | Condition on CFADS | Repayment | Interest |
|---|---|---|---|
| Shortfall | C below r × O | 0 | r × O |
| Partial sweep | r × O up to O + r × O / 2 | (C − r × O) / (1 − r/2) | r × (O − P/2) |
| Full repayment | C above O + r × O / 2 | O | r × O / 2 |
The thresholds are the points where the unconstrained formula crosses 0 and O. For P = 0, C = r × O. For P = O, C = r × O + O × (1 − r/2) = O + r × O / 2. At the boundaries the clamped and unclamped answers are equal, so the result has no jumps.
In the shortfall regime, interest is a full year on the opening balance because nothing is repaid. In the full repayment regime, the average balance is O / 2, so interest is r × O / 2.
The spreadsheet formulas
This replaces the circular version from the earlier chapter. Interest is the last cell in the chain.
Repayment: =MIN(Debt_Open, MAX(0, (CFADS - Rate*Debt_Open) / (1 - Rate/2)))
Debt_Close: =Debt_Open - Repayment
Interest: =Rate * AVERAGE(Debt_Open, Debt_Close)Interest is still defined as rate times the average balance. The only change is that repayment no longer reads interest. Excel's iterative calculation setting can stay off, and the circuit-breaker input is not needed for this block.
Keep one check row beside the block, because the algebra is easy to break by editing one cell:
Sweep_Check: =Repayment - MIN(Debt_Open, MAX(0, CFADS - Interest))This should be 0 in every period. It restates the original waterfall, where repayment is CFADS less interest, and confirms that the closed form agrees with it.
Testing the algebra against the iteration
Before trusting the formula in a model, compare it with the iterative method on several cases, including the regimes where limits bind. The script below does that. It runs the closed form and the iterative solver for three CFADS levels, one per regime.
def solve_algebraic(opening, cfads, rate):
repayment = (cfads - rate * opening) / (1 - rate / 2)
repayment = min(opening, max(0.0, repayment))
closing = opening - repayment
interest = rate * (opening + closing) / 2
return interest, repayment, closing
def solve_iteratively(opening, cfads, rate, tol=1e-12, max_iter=200):
interest = 0.0
for _ in range(max_iter):
repayment = min(opening, max(0.0, cfads - interest))
closing = opening - repayment
new_interest = rate * (opening + closing) / 2
if abs(new_interest - interest) < tol:
return new_interest, repayment, closing
interest = new_interest
raise RuntimeError("did not converge")
opening, rate = 500.0, 0.08
for cfads in (20.0, 100.0, 600.0):
alg = solve_algebraic(opening, cfads, rate)
itr = solve_iteratively(opening, cfads, rate)
assert all(abs(a - b) < 1e-6 for a, b in zip(alg, itr))
print(f"{cfads:6.1f} {alg[0]:9.4f} {alg[1]:9.4f} {alg[2]:9.4f}")The output columns are CFADS, interest, repayment and closing balance:
20.0 40.0000 0.0000 500.0000
100.0 37.5000 62.5000 437.5000
600.0 20.0000 500.0000 0.0000The three rows are the shortfall, partial sweep and full repayment regimes. The assertion passes for all of them, so the clamped closed form matches the iteration.
Extending the method to a revolver
A revolver draw has the same structure with the sign reversed. Let S be the cash shortfall before revolver interest, and O the opening revolver balance. The draw D must cover the shortfall and the interest on the average balance:
D = S + r × (O + O + D) / 2
D × (1 − r/2) = S + r × O
D = (S + r × O) / (1 − r/2)
Clamp the draw at zero when there is no shortfall, and at the available commitment when the facility is capped. Repayment of an existing balance from surplus cash is the sweep formula above. A model with both a revolver and a sweep needs a rule for which applies in each period, usually by the sign of the pre-revolver cash flow. Write the algebra for each case separately.
Where the algebra stops working
The closed form depends on the equations being linear in interest. Several common features break that, or make the algebra long enough that mistakes become likely.
- Interest on cash balances. If the cash balance earns interest and the sweep depends on it, the loop is larger. You can still solve it, but each extra balance adds terms.
- Several tranches with a priority order. A sweep that pays senior debt first and then junior debt couples the tranches. The regimes multiply: each tranche can be unpaid, partly paid or fully paid.
- Tax on interest. If CFADS is after tax and tax falls when interest rises, then CFADS depends on interest. With a flat tax rate this is still linear, but a tax floor such as
MAX(0, ...)adds a regime change. - Fees on the average balance or a margin ratchet. A margin that steps with leverage makes the rate depend on the closing balance. That is a lookup, not a linear term, so there is no closed form.
- Minimum cash and dividend lock-ups. Conditions that switch on based on balances add regimes that you must enumerate.
When any of these applies, you have two choices. You can find the regimes and write a formula for each, which is accurate but needs care. Or you can use iterative calculation with a circuit breaker, which handles any structure but brings the error and convergence issues covered in the other chapters.
A sweep percentage below 100%
If only a fraction s of cash after interest is swept, then P = s × (C − I). Repeating the derivation with I = r × (O + O − P) / 2 = r × O − (r/2) × P gives:
P = s × (C − r × O + (r/2) × P)
P × (1 − s × r/2) = s × (C − r × O)
P = s × (C − r × O) / (1 − s × r/2)
With s = 1 this reduces to the formula you already have. The limits are the same: clamp at 0 and at the opening balance. The thresholds for the regimes differ, so recompute them if you want to document the boundaries.
Deciding whether the algebra is worth it
Use the closed form when the loop is a single average-balance interest term, the sweep and limits are simple, and the model is shared with people who dislike iterative calculation settings. It is deterministic, fast, and free of the stuck errors that iteration can cause.
Use another method when the structure is rich enough that deriving the formula costs more than managing a circuit breaker. The deciding question is whether you can write the regimes down with confidence, and test each against an iterative solver as in the script above.
Exercise
A term loan has opening balance 800, CFADS 150 and an annual rate of 10%, with a 100% sweep and interest on the average balance. Find the repayment, interest and closing balance with the closed form. Then say which regime applies.
Show answer
Repayment = (150 − 0.10 × 800) / (1 − 0.05) = 70 / 0.95 = 73.6842. Closing balance = 800 − 73.6842 = 726.3158. Interest = 0.10 × (800 + 726.3158) / 2 = 76.3158. Check: CFADS less interest is 150 − 76.3158 = 73.6842, which equals the repayment. The regime is a partial sweep, because CFADS (150) is above r × O = 80 and below O + r × O / 2 = 840.
Exercise
Using the same loan with CFADS of 60, what are repayment and interest, and why does the unconstrained formula give the wrong answer?
Show answer
The unconstrained formula gives (60 − 80) / 0.95 = −21.05, which is a negative repayment, meaning a draw. A term loan cannot be redrawn, so the MAX(0, ...) clamp sets repayment to 0. The loan is in the shortfall regime, since 60 is below r × O = 80. Interest is 0.10 × 800 = 80 on the full opening balance, and the closing balance stays at 800. The shortfall of 20 must be funded elsewhere, for example by a revolver or cash.
Exercise
A revolver has opening balance 0, a pre-revolver cash shortfall S of 200 and a rate of 6%, with interest on the average balance. What is the draw, and what is the interest on it?
Show answer
Draw = (S + r × O) / (1 − r/2) = (200 + 0) / 0.97 = 206.1856. Interest = 0.06 × (0 + 206.1856) / 2 = 6.1856. Check: the shortfall plus interest is 200 + 6.1856 = 206.1856, which equals the draw.