Financial algorithms and Developer Data - ProDebtCalc

This section briefly describes the finance algorithms used by the Professional Debt Calculator.

If you're interested in this kind of stuff, then you may be interested in the article "A primer on financial engineering and structured finance" that I wrote in 2008, during the financial crisis. This article goes into the financial calculations to show how criminal bankers caused the global financial crisis by "slicing and dicing" subprime mortgage loans to create defective synthetic securities, such as collateralized debt obligations (CDOs) or credit default swaps (CDSs), that they then sold to millions of investors.

Future value of money, present value of a future payment

If you're going to receive $1000 a year from now, how much is that $1000 worth today?

That depends on the market interest rate. For simplicity, we'll assume that the nominal interest rate is 6%.

Computing present value of a future payment with simple interest

So, if I deposit $5000 in a bank that pays 6% (simple) interest per year, then at the end of a year I'll have $5000*(1+6%) = $5000*(1.06) = $5300. (Of course, this computation will have to amended for compound interest.)

Now, turn the computation upside down. If I'm going to receive $1000 a year from now, then the "present value" of that $1000 is $1000/(1+6%) = $1000/(1.06) = $943.40.

That's a "present value" computation for future payment. In other words, if you're going to receive $1,000 a year from now, then that money is only worth $943.40 today.

Compound Interest and Present Value

Let's modify the previous example to use compound interest.

Suppose that you deposit $5000 in a bank, at 6% annual interest compounded monthly. (Note that when you're talking about monthly compounding, you still give the annual interest rate, unless specifically stated otherwise.)

During the first month, you'll earn $5000*(6%/12) = $5000*(0.005) = $25. At the end of the first month you'll have $5000*(1+6%/12) = $5000*(1.005) = $5025 at the end of the first month.

At the end of the second month, you'll have $5000*(1 + 6%/12)*(1 + 6%/12) = $5000*1.005*1.005 = $5050.125. (Note that we're getting into fractions of a penny here.)

We can rewrite the last formula using "**" to indicate exponentiation. So at the end of the second month, you'll have $5000*(1+6%/12)**2 = $5000*(1.005**2) = $5050.125.

Continuing in this way, the amount you'll have after 12 months will be $5000*(1+6%/12)**12 = $5000*(1.005**12) = $5308.39. That's $8.39 more than you would have received with simple interest.

Now, turn the computation upside down. If I'm going to receive $1000 a year from now, then the "present value" of that $1000 is $1000/(1+6%/12) = $1000/(1.005**12) = $941.91. That's $1.50 less with compound interest than you would have received with simple interest.

Formulas for compound interest and present value

Let's now give the general formulas for compound interest and present value. We're not going to assume that interest is compounded monthly, since the Professional Debt Calculator lets you specify that interest is to be compounded in an arbitrary period -- every C days, weeks, half-months, months, quarters or years.

If you deposit amount PV (present value) in the bank, at annual interest I, compounded periodically, where there are P periods per year, then the future value (FV) of that amount A at the end of N periods will be:

FV = PV * (1 + I / P) ** N

So if the interest rate is 6%, and the period is 1 month, so P=12, and N=12 after a year, then the formula becomes FV=PV*(1+6%/12)**12, which is the formula used in the previous example.

Now turn the computation upside down. If you're going to receive an amount FV (future value) at the end of N periods, then the present value (PV) is:

PV = FV / (1 + I / P) ** N

Amortizing a debt

If you look up amortization on the internet, you'll get a definition like, "Amortization is paying off a debt over time in equal installments. Part of each payment goes toward the loan principal, and part goes toward interest."

However, this definition does not apply to all debts. For example, credit card debts are somewhat different. Typically, you pay off the debt by making a monthly payment, but the payment amount is different each month. Some financial counselors recommend that you make two or three payments per month in order to pay off your credit card debt more quickly, so the payments may occur at unequal intervals.

It's true that each payment goes towards principal and interest, but it's more complicated in the case of a credit card. In that case, interest is assessed according to a billing cycle, usually a date that may occur any time during the month, and rarely the same date that a payment is made. So in the case of a credit card, an interest assessment adds to the current balance due, and a payment reduces the current balance due. There's no direct connection between the payment and interest assessment.

Furthermore, in the case of a credit card, there may be additional purchases during a given month, increasing the balance at arbitrary times. This means that the amount of interest that can be assessed is complicated, and there are different formulas used by different banks -- interest based on balance at beginning of billing cycle, interest based on balance at end of billing cycle, interest computed and compounded daily, for example.

Even "ordinary" loans can have complications in the form of different recurring income/advance streams or payment streams or fees.

So PDC takes a very general approach. A transaction consists of four types of clauses:

Each clause in the transaction generates an event schedule. For example, a recurring payment might generate a schedule with payment events on the 23rd of each month.

All the event schedules for all of the clauses are combined into a total event schedule. Then the events in the combined schedule are processed, one at a time, to produce an amortization table.

Calculating monthly payments and other values

The Professional Debt Calculator is capable of computing a value necessary to balance the transaction. This might be the amount of a recurring payment or advance, or it might be the number of periods necessary to pay off a loan.

Although these calculations can be complicated, the overall algorithm is as following:

A problem with the above algorithm applied blindly is that there can sometimes be performance problems. It's desirable that PDC amortize a transaction with two or three seconds, but if multiple iterations are required and/or there are very many schedule events, then the amortization loop can take 10, 20 or 30 seconds. So a lot of work has been done to find ways to improve performance, usually by being a lot more clever about reducing the number of iterations.

Annual Percentage Rate (APR) Calculation

A debt transaction can be quite complex, involving multiple periods, multiple interest rates, various one-time or recurring fees, and so forth. However, federal regulations specify rules for calculating the Annual Percentage Rate (APR). The rules can be found in the Federal Truth In Lending Regulations (Regulation Z).

The APR is an interest rate that can be evaluated as possible: Computing the present value of all the events in the schedule, and add together all the present values. The total present value must be zero for the APR to be valid.

The algorithm to compute the APR is similar to the algorithm to compute other values: Try low and high guesses, compute the total value in each case, interpolate or extrapolate to get a new guess, and repeat until successive total present value differences are within tolerance.

Developer Data

&&2 Dummy End

Xenakis Professional Debt Calculator Copyright © 2002-2016 by John J. Xenakis