Sub topic 5
Solving the Loop with Iterative Calculation
Assume you can build a basic debt schedule and understand cash flow available for debt service (CFADS), interest, repayment, and closing debt. You should also know Excel formulas such as IF, MIN, MAX, and AVERAGE.
How the loop works
Suppose a borrower uses all cash after interest to repay debt:
- Interest depends on the average of opening and closing debt.
- Repayment depends on CFADS after interest.
- Closing debt equals opening debt minus repayment.
The dependency chain is:
For example, these formulas create a circular reference:
Circ_Switch: 1
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 - RepaymentWhen Circ_Switch is 1, Excel must calculate Interest to find Repayment, then calculate Debt_Close, and then use Debt_Close to recalculate Interest. Ordinary spreadsheet calculation cannot finish this dependency chain in one pass.
Enabling iterative calculation
Iterative calculation tells Excel to recalculate circular formulas repeatedly. Each pass uses the results from the previous pass. Excel stops when either the result is close enough to the previous result or the maximum number of iterations is reached.
In Excel, enable it under:
- Select File > Options > Formulas.
- Select Enable iterative calculation.
- Set Maximum Iterations to a suitable limit, such as
100. - Set Maximum Change to a tolerance such as
0.01or0.000001, depending on the model's units.
The maximum change is the largest permitted difference between two calculation passes. If the change falls below this value, Excel treats the model as converged.
A worked iteration
Assume:
| Input | Value |
|---|---|
| Opening debt | 500.00 |
| CFADS | 100.00 |
| Interest rate | 8.00% |
| Initial interest guess | 0.00 |
With an initial interest value of zero, repayment is 100.00, so closing debt is 400.00. Average debt is 450.00, producing new interest of 36.00.
The next pass uses interest of 36.00. Repayment becomes 64.00, closing debt becomes 436.00, and new interest becomes 37.44. Further passes get closer to the final result.
This simplified Python example shows the same process:
def solve_interest_iteratively(opening, cfads, rate, tolerance=1e-9, max_iterations=100):
interest = 0.0
for iteration in range(1, max_iterations + 1):
repayment = min(opening, max(0.0, cfads - interest))
closing = opening - repayment
new_interest = rate * (opening + closing) / 2
if abs(new_interest - interest) < tolerance:
return new_interest, closing, iteration
interest = new_interest
raise RuntimeError("The circular calculation did not converge")
interest, closing, passes = solve_interest_iteratively(500.0, 100.0, 0.08)
print(f"Interest: {interest:.4f}")
print(f"Closing debt: {closing:.4f}")
print(f"Iterations: {passes}")The result is approximately 37.50 of interest and 437.50 of closing debt.
Convergence and common errors
Convergence means that repeated calculation produces a stable answer. The key diagnostic is the change between successive interest values:
\[ \text{Change} = |\text{New interest} - \text{Old interest}| \]
The iteration usually converges when the rate is moderate and the formulas are smooth. It may converge slowly when the rate is high. It may fail to converge when formulas contain sharp switches, inconsistent signs, or other circular dependencies.
Check these conditions:
- Interest expense has the correct sign.
- Repayment cannot exceed opening debt.
- Repayment does not become negative.
- The iteration limit is high enough.
- The maximum change is small enough for the model's scale.
- A check confirms that closing debt equals opening debt minus repayment.
A circuit breaker makes debugging safer:
Circ_Switch: 0
Interest: =IF(Circ_Switch=1, Rate*AVERAGE(Debt_Open, Debt_Close), Rate*Debt_Open)Set the switch to 0 before editing formulas or clearing errors. This replaces average-balance interest with opening-balance interest and breaks the loop. After the schedule works, set the switch back to 1 and confirm that the circular result converges.
Exercise
What does Excel's Maximum Change setting control in an iterative debt schedule?
Show answer
It controls the largest allowed difference between successive calculation passes. Excel stops when the change falls below that tolerance.