Sub topic 5
Solving the loop with iterative calculation
This chapter assumes you can build a debt schedule with a cash flow waterfall, and that you know why average-balance interest on a cash-sweep loan creates a circular reference. You should also be comfortable with IF, MIN, MAX and AVERAGE. Here you will see what Excel does when you allow the loop, how to read its two settings, and how to predict the answer it settles on.
What iterative calculation does
Normally Excel refuses a circular reference. It shows a warning and leaves the cells at zero or at their last value. Turning on iterative calculation changes this rule. Excel recalculates the cells in the loop repeatedly, and each pass uses the values left by the previous pass. It stops when a limit is reached.
This is a fixed-point search. You are looking for an interest value that, once fed through the closing balance and back into the interest formula, returns itself. Iteration finds it by trial: guess, compute, feed the result back as the next guess.
The loop from the debt schedule looks like this:
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 - RepaymentInterest depends on Debt_Close. Debt_Close depends on Repayment. Repayment depends on Interest. Excel can only evaluate this ring with iteration enabled.
Turning it on
In Excel for Windows, go to File, Options, Formulas, and tick Enable iterative calculation. On a Mac, the setting is under Excel, Preferences, Calculation. Two numbers sit under the tick box.
| Setting | Default | Meaning |
|---|---|---|
| Maximum Iterations | 100 | The most passes Excel will run per recalculation. |
| Maximum Change | 0.001 | Excel stops when no value in the loop moves by more than this between passes. |
Excel stops at whichever limit it reaches first. In a well-behaved debt schedule the change limit is reached long before 100 passes.
Where the setting lives
Iterative calculation is an application setting, but Excel saves it inside each workbook. When you open a workbook, Excel adopts the setting from the first workbook opened in that session. If a colleague opens a different workbook first, with iteration off, your model opens with the circular reference warning, even though you saved it with iteration on. Tell users of the model to open it first, or close other workbooks. Many teams put a visible note on the cover sheet.
Choosing Maximum Change
The default of 0.001 is an absolute amount. If the model is in millions, 0.001 means one thousand currency units, which is usually fine. If the model is in single units, 0.001 means a tenth of a cent. Pick a value that is far smaller than the precision anyone reads. Many modelers use 0.00001 or smaller. A tighter tolerance costs a few extra passes, which is cheap.
A worked pass-by-pass example
Take the numbers from the Python examples. The opening debt is 500, the cash flow available for debt service (CFADS) is 100, and the rate is 8%. The unconstrained repayment equals CFADS minus interest, so the closing balance is 500 - 100 + interest.
Assume every cell in the loop starts at zero. Then each pass does this:
- Take the current interest value.
- Compute the closing balance as
500 - 100 + interest. - Compute new interest as
0.08 x (500 + closing) / 2.
| Pass | Interest used | Closing balance | New interest | Change |
|---|---|---|---|---|
| 1 | 0 | 400 | 36 | 36 |
| 2 | 36 | 436 | 37.44 | 1.44 |
| 3 | 37.44 | 437.44 | 37.4976 | 0.0576 |
| 4 | 37.4976 | 437.4976 | 37.499904 | 0.002304 |
The change shrinks by a constant factor of 0.04 each pass. That factor is half the interest rate (0.08 / 2), and the next chapter explains why. With the default Maximum Change of 0.001, Excel would run one or two more passes after pass 4 and stop near 37.5.
You can reproduce this outside Excel. The function below does the same pass, and it stops when the change falls below a tolerance, which mimics Excel's Maximum Change.
def solve_interest_iteratively(opening, cfads, rate, tol=1e-9, max_iter=100):
interest = 0.0
for i in range(1, max_iter + 1):
closing = opening - (cfads - interest)
new_interest = rate * (opening + closing) / 2
if abs(new_interest - interest) < tol:
closing = opening - cfads + new_interest
return new_interest, closing, i
interest = new_interest
raise RuntimeError('did not converge')
interest, closing, n = solve_interest_iteratively(500.0, 100.0, 0.08)
print(round(interest, 4), round(closing, 4), n)It prints 37.5 437.5 followed by the number of passes needed. The tolerance here is far tighter than Excel's default, so the pass count is larger than what Excel would use.
To watch the convergence, print each pass:
def trace_iterations(opening, cfads, rate, passes=6):
interest = 0.0
print("pass interest_in closing interest_out change")
for i in range(1, passes + 1):
closing = opening - cfads + interest
new_interest = rate * (opening + closing) / 2
change = abs(new_interest - interest)
print(f"{i:<5} {interest:<12.6f} {closing:<11.6f} {new_interest:<13.6f} {change:.6f}")
interest = new_interest
trace_iterations(500.0, 100.0, 0.08)The last column should match the Change column in the table above, then keep falling: about 0.000092 on pass 5 and 0.000004 on pass 6.
What Excel does differently from this sketch
The Python function is a clean model. Excel behaves in a few ways that matter to a modeler.
- Excel keeps state between recalculations. The first pass of any recalculation starts from the values already in the cells, not from zero. This is useful, because a small input change starts close to the answer and converges in a pass or two. It is also the root of the stuck-error problem covered in a later chapter. A bad value that enters the loop becomes the starting point for the next recalculation.
- Excel calculates in a fixed order, and each cell sees the latest values. Within one pass, cells later in the order use values already updated earlier in the same pass. This usually speeds convergence compared with the textbook method, where every cell uses only the previous pass. The exact order depends on sheet layout and how the workbook was built. You should not rely on it for correctness, only for the fact that the answer is the same fixed point either way.
- Excel stops silently. If it hits Maximum Iterations without meeting Maximum Change, it shows whatever values it has. There is no warning. A model that has not converged looks exactly like one that has.
- The status bar may say "Calculate" or "Circular References". These messages are a hint, not a check. They do not tell you whether the loop converged.
Checking the answer in the workbook
You can test the result without leaving the sheet. After iteration stops, compute the interest the formula implies from the final displayed balances, and compare it to the interest cell:
Interest_Check: =Rate*AVERAGE(Debt_Open, Debt_Close) - Interest
Check_Flag: =IF(ABS(Interest_Check) < 0.0001, 0, 1)At a true fixed point, Interest_Check is close to zero. If it is not, the loop stopped early. A later chapter develops this idea into a full set of validation checks. For now, the key point is that the check must not itself be part of the loop, so that it measures the loop without disturbing it.
Costs of leaving iteration on
Iterative calculation is a global change to how the workbook behaves, so there are side effects.
- Accidental circularities go unnoticed. With iteration off, Excel warns you the moment a formula creates a loop by mistake, for example a stray reference that makes a total depend on itself. With iteration on, that warning disappears. A typing error can create a loop that silently converges to nonsense, or does not converge at all. A model with iteration enabled needs a deliberate list of the intended loops, so that any other loop is a defect.
- Calculation is slower. Each recalculation repeats the loop cells and everything that depends on them, up to the pass limit. In a large model with data tables or many scenarios, this adds up.
- Results may differ in the last decimals. The answer depends on the starting values and the stopping rule. Two copies of the same model can show interest that differs by a few thousandths. This is within tolerance but will fail an exact-equality comparison. Use a tolerance when you compare outputs.
- Convergence depends on the loop. For the loop in this chapter, convergence is fast because the feedback factor is small. The next chapter looks at when that holds and when it does not.
Common mistakes
- Enabling iteration to silence a warning you do not understand. The warning may point to an unintended loop. Find the loop first, then decide whether it is meant to exist.
- Leaving Maximum Change at the default in a model with small units. The loop can stop while the interest is still visibly off.
- Raising Maximum Iterations to 10,000 to "fix" a model. If 100 passes are not enough, the loop usually has a design problem such as a missing bound, a sign error, or a feedback factor close to or above 1. More passes only hide the problem for longer.
- Trusting a balanced balance sheet as proof of convergence. A balance sheet can balance at an unconverged state, because every cell is consistent with its inputs at the last pass. Only a check on the fixed-point condition proves convergence.
- Forgetting the setting when sharing the file. The recipient sees a circular reference warning. Document the setting on the cover sheet.
Summary of the working model
Iterative calculation turns a circular reference into a repeated substitution. Excel feeds each pass's result into the next, stops on a change limit or a pass limit, and then shows the values without comment. For a cash-sweep loan with average-balance interest, the loop converges quickly to the same answer the algebra gives. Because Excel keeps the previous values in the cells and does not report a failure to converge, you need to supply the safeguards yourself: a tight Maximum Change, a visible setting note, and a check cell.
Exercise
With opening debt of 1,000, CFADS of 200 and a rate of 10%, take interest as 0 for the first pass and use average-balance interest with no repayment limits. What are the new interest values after pass 1 and pass 2, and by what factor does the change shrink from one pass to the next?
Show answer
Pass 1: closing = 1,000 - 200 + 0 = 800, so new interest = 0.10 x (1,000 + 800) / 2 = 90. Pass 2: closing = 1,000 - 200 + 90 = 890, so new interest = 0.10 x (1,000 + 890) / 2 = 94.5. The changes are 90 and 4.5, so the change shrinks by a factor of 0.05, which is rate / 2.
Exercise
A colleague raises Maximum Iterations from 100 to 5,000 because a debt schedule's check cell still shows a non-zero difference. Give two reasons this may not fix the problem, and one check to run instead.
Show answer
First, if the feedback factor is near or above 1 (for example from a sign error or a missing bound), the loop never settles, so more passes do not help. Second, the cells may already hold a stuck error value or a bad starting value that each pass reproduces. Instead, compare the interest cell to Rate x AVERAGE(DebtOpen, DebtClose) computed from the displayed balances. If the difference does not shrink as passes increase, investigate the loop's design, not the pass limit.