Sub topic 7
Adding a circuit-breaker switch
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 creates a circular reference, and that you have enabled iterative calculation in Excel. Here you add the switch that makes a circular model safe to use and to repair.
Why a circular model needs a breaker
Iterative calculation lets Excel evaluate a loop repeatedly until the values settle. It has a weakness: the loop feeds on its own previous result. If one cell in the loop ever holds an error such as #DIV/0!, #VALUE! or #REF!, the next pass reads that error and passes it on. Each cell in the loop now depends on an error, so the error keeps itself alive.
Fixing the original cause does not help, because the cells still read each other's stored errors. Without a breaker, the usual remedy is to delete and retype formulas in the loop, which is slow and error-prone.
A circuit breaker is an input cell that cuts the loop on demand. When the switch is off, interest no longer reads the closing balance. The loop is open, the cells recalculate from clean inputs, and the stuck error disappears.
The standard pattern
The switch is one input cell, usually with a named range such as Circ_Switch. A value of 1 means "use the average balance (circular)". A value of 0 means "use the opening balance (no circularity)".
Circ_Switch (input cell): 1 = average balance, 0 = opening balance (breaker)
Interest: =IF(Circ_Switch=1, Rate*AVERAGE(Debt_Open, Debt_Close), Rate*Debt_Open)
Repayment: =MIN(Debt_Open, MAX(0, CFADS - Interest))
Debt_Close: =Debt_Open - RepaymentThe loop runs through three cells:
- Interest reads
Debt_Close. Debt_ClosereadsRepayment.RepaymentreadsInterest.
The loop is closed only when Circ_Switch is 1. When it is 0, the IF takes the second branch, which reads only Debt_Open. Debt_Open is last period's closing balance, so it is not part of this period's loop.
Why the switch clears errors
Excel evaluates only the branch of an IF that it selects. With the switch at 0, the AVERAGE(Debt_Open, Debt_Close) branch is never evaluated. An error stored in Debt_Close is therefore not read by Interest. Interest returns a clean number, Repayment and Debt_Close then recalculate from that number, and the error is gone.
Seeing the effect in code
You can reproduce the behavior outside Excel. The function below plays the role of a recalculation. It receives the interest value currently stored in the cell, as Excel would, and updates it.
import math
OPENING, CFADS, RATE = 500.0, 100.0, 0.08
def recalculate(interest, switch, passes=60):
"""Recalculate the schedule; `interest` is the value stored in the cell."""
for _ in range(passes):
if switch == 1:
closing = OPENING - (CFADS - interest)
interest = RATE * (OPENING + closing) / 2
else:
interest = RATE * OPENING
return interest, OPENING - CFADS + interest
def show(result):
print(tuple(round(x, 6) for x in result))
stuck = math.nan
show(recalculate(stuck, 1)) # (nan, nan): the error feeds itself
show(recalculate(stuck, 0)) # (40.0, 440.0): breaker on, loop opened
show(recalculate(40.0, 1)) # (37.5, 437.5): loop closed again, convergedThe first call starts from an error and keeps it, because every pass reads the previous nan. The second call, with the breaker at 0, ignores the stored value and produces opening-balance interest of 40. The third call starts from that clean 40 and converges to 37.5 with a closing balance of 437.5. This is the same answer as the algebraic solution you meet later in this tutorial.
Note that 40 is not the final answer. The breaker value is a safe placeholder, not a correct result under average-balance interest. A model left at 0 is wrong by the difference between the two methods, here 2.5 on a balance of 500.
What each setting means
| Switch value | Interest formula uses | Loop closed? | When to use it |
|---|---|---|---|
| 1 | Average of opening and closing balance | Yes | Normal operation, reporting, and final outputs |
| 0 | Opening balance only | No | Clearing errors, debugging, and testing structure |
Building it step by step
- Put the switch on your inputs or control sheet. Format it as an obvious input and add data validation that allows only 0 and 1.
- Name the cell
Circ_Switchso every formula refers to the same cell. - Wrap each circular interest formula in the
IFshown above. If a model has several loops, such as a term loan, a revolver and interest income on cash, use the same switch for all of them. One switch should open every loop at once. - Make sure the opening-balance branch contains no reference to any cell downstream in the loop. It may refer only to the opening balance and the rate.
- Turn on iterative calculation (File > Options > Formulas > Enable iterative calculation).
- Test the switch both ways. At 0 the model should show no circular reference warning and no errors. At 1 it should settle on stable values.
Settings that affect the loop
Excel's iterative calculation has two controls: the maximum number of iterations and the maximum change. The defaults are 100 iterations and 0.001. Excel stops when either limit is reached. If you model in thousands or millions, 0.001 is a loose tolerance in relative terms, so many modelers tighten it to 0.00001 or smaller. A smaller tolerance does not cost much, because the loop converges fast for ordinary interest rates.
Recovery procedure
When a #REF!, #DIV/0! or similar error appears in the loop, follow this sequence.
- Set
Circ_Switchto 0. - Recalculate (F9) and check that the errors are gone. If errors remain, they do not come from the loop. Trace them to their real source, such as a deleted row, a division by a blank cell, or a bad lookup.
- Fix the underlying cause.
- Set
Circ_Switchback to 1. - Confirm the outputs are sensible and the checks pass.
Skipping step 3 is the most common mistake. If you flip the switch back to 1 before fixing the cause, the error enters the loop again within a pass.
Common errors and gotchas
- Hiding errors with IFERROR. Wrapping loop formulas in
IFERROR(..., 0)stops errors from sticking, but it also hides real problems and can bake a wrong zero into the results. Prefer the switch, which keeps errors visible and gives you a clean way to clear them. - A breaker on only one formula. If a second loop, such as revolver interest, does not read the switch, errors in it survive when you set the switch to 0. Every circular formula must depend on the same switch.
- Leaving the switch at 0. The model then looks fine but uses opening-balance interest. Add a visible flag, for example a check cell that returns an error message when
Circ_Switchis not 1, and include it in the model's overall check total. - Iteration setting follows the first workbook opened. Excel's iterative calculation setting belongs to the application session. If you open a non-circular workbook first, it may open with iteration off and show circular reference warnings. Close everything, open the circular model first, and check the setting.
- Treating a warning as the problem. With iteration on, Excel shows no circular warning. If a warning appears, either iteration is off or you have created a second, unintended loop. Check the Formulas > Error Checking > Circular References list.
- Non-converging or wandering values. A loop that keeps changing after 100 iterations often comes from a switch or
MIN/MAXinteraction that makes the loop discontinuous. Set the switch to 0, check that the structure is right, and then set it back to 1.
A short checklist
- One named switch cell, data-validated to 0 or 1.
- Every circular formula reads the switch.
- The 0 branch never refers back into the loop.
- Iterative calculation is on, with a tolerance suited to your units.
- A check flags the model when the switch is not 1.
- You have tested a recovery by deliberately inducing an error, setting the switch to 0, and restoring it.
Exercise
A circular debt schedule shows #VALUE! in Interest, Repayment and DebtClose. You set CircSwitch to 0 and the errors vanish. You set it back to 1 and they return immediately. What does this tell you, and what should you do next?
Show answer
The loop is not the cause. With the switch at 0 the loop is open and the formulas calculate cleanly, so the stuck error was cleared. When the switch returns to 1, the same error returns because its source is still in the model, for example a blank or text input that feeds CFADS or the rate. Set the switch to 0 again, trace the #VALUE! back through CFADS and the inputs until you find the faulty cell, fix it, and only then set the switch to 1.
Exercise
Using the Python function above with OPENING=500, CFADS=100 and RATE=0.08, what interest value does the model produce with the switch at 0, and why is it different from the value with the switch at 1 after convergence?
Show answer
With the switch at 0, interest is the rate times the opening balance: 0.08 x 500 = 40. With the switch at 1 after convergence, interest is the rate times the average of the opening balance (500) and the closing balance (437.5), which is 0.08 x 468.75 = 37.5. The difference is 2.5. The opening-balance method ignores the repayment made during the period, so it charges interest on a balance that is already partly repaid by the end of the period.