Sub topic 9
Removing the Loop with Algebra
Prerequisites and the simple loop
This chapter assumes you can build a debt schedule, calculate cash flow available for debt service (CFADS), and use spreadsheet functions such as IF, MIN, MAX, and AVERAGE. You should also understand that repayment reduces debt and that interest reduces the cash available for repayment.
Average-balance interest creates a circular reference:
- Interest depends on the average of opening and closing debt.
- Closing debt depends on repayment.
- Repayment depends on CFADS after interest.
- Interest is needed again to calculate repayment.
For a simple cash sweep with no repayment cap, define:
Oas opening debt.Cas closing debt.Fas CFADS before interest and repayment.Ias interest expense.ras the interest rate.
The debt schedule is:
I = r × (O + C) / 2
C = O - (F - I)The second equation says that repayment equals F - I. Rearranging it gives:
C = O - F + ISubstitute this expression for C into the interest formula:
I = r × (O + O - F + I) / 2
I = r × (2O - F + I) / 2Now collect the terms containing I:
I = r × (2O - F) / 2 + rI / 2
I - rI / 2 = r × (2O - F) / 2
I × (1 - r / 2) = r × (2O - F) / 2Therefore, the closed-form solution is:
I = [r × (2O - F) / 2] / (1 - r / 2)
C = O - F + IA closed-form solution is a formula that calculates the answer directly. It removes the need for spreadsheet iteration because interest no longer refers indirectly to itself.
Worked example
Suppose opening debt is 500, CFADS is 100, and the annual interest rate is 8%:
I = [0.08 × (2 × 500 - 100) / 2] / (1 - 0.08 / 2)
I = 37.5
C = 500 - 100 + 37.5
C = 437.5The result satisfies the original average-balance formula:
8% × (500 + 437.5) / 2 = 37.5You can implement the calculation directly in a spreadsheet:
Interest = Rate*(2*Debt_Open-CFADS)/2/(1-Rate/2)
Debt_Close = Debt_Open-CFADS+InterestThe formula assumes that all CFADS after interest is used for repayment. It also assumes that repayment is not limited by the outstanding debt and does not include a minimum cash balance.
Verify the algebra with Python
This complete example calculates the result and checks it against the original interest definition:
def solve_interest_algebraically(opening, cfads, rate):
interest = rate * (2 * opening - cfads) / 2 / (1 - rate / 2)
closing = opening - cfads + interest
return interest, closing
interest, closing = solve_interest_algebraically(500.0, 100.0, 0.08)
print(f"Interest: {interest:.2f}")
print(f"Closing debt: {closing:.2f}")
expected_interest = 0.08 * (500.0 + closing) / 2
assert abs(interest - expected_interest) < 1e-12The assertion is a validation check. It confirms that the direct formula produces an answer consistent with the original circular relationship.
Where the closed form stops working
The algebra changes when the schedule contains conditional repayment logic. For example:
Repayment = MIN(Debt_Open, MAX(0, CFADS - Interest))MAX prevents repayment when post-interest CFADS is negative. MIN prevents repayment from exceeding opening debt. If either limit is active, the relationship between closing debt and interest is no longer the same linear equation.
You can still use algebra by solving each possible case separately:
- No repayment:
Repayment = 0. - Partial repayment:
Repayment = CFADS - Interest. - Full repayment:
Repayment = Debt_Open.
Calculate the candidate result for a case, then test whether its assumptions hold. If a partial-repayment result produces repayment greater than opening debt, that case is invalid. Select the case whose conditions are satisfied.
Choosing algebra over iteration
Algebra is attractive when the loop is small, linear, and stable. It gives a reproducible result without workbook-level iterative settings. It is also easier to test in a unit test or an independent calculation.
Use iterative calculation when the model contains several linked schedules, nonlinear limits, taxes, or multiple debt instruments. Use opening-balance interest when transparency and simplicity matter more than intra-period precision. A copy-paste macro can handle more complex nonlinear schedules, but it adds automation, control, and audit requirements.
Exercise
With opening debt of 800, CFADS of 160, and an interest rate of 10%, what are interest and closing debt under the unrestricted average-balance formula?
Show answer
Interest is 75.68, calculated as [0.10 × (2 × 800 - 160) / 2] / (1 - 0.10 / 2). Closing debt is 715.68, calculated as 800 - 160 + 75.68.