Need this for a c# app, can't find the formula anywhere nor can I wrap my head around it. Any Algebra gurus out there in overflow land? Basically, I need to calculate a fixed payment amount for a loan term that has two different interest rates based on how long the loan has been open.
Loan contracts are very complex. If you don't want to dive into the complexity you have to make some simplifying assumptions. Here are some of the variables you need to consider:
- What is the base rate? Does the loan float over Prime? Libor? CMT?
- What is the margin above the base rate?
- How often does the base rate reset?
- What happens if the reset date falls on a holiday? A weekend?
- Are there ceilings or floors on the base rate?
- Is there an initial period at which the base rate is fixed before the first reset? How long is that period?
- Is there an initial discount on the margin that is later adjusted (a teaser rate)?
- What's the term of the mortgage?
- Is it a negative-amortization mortgate? What's the stop period on the negative-amortizing payments?
- Is it a fully-amortizing mortgage?
- Is it a balloon mortgage?
- Is the interest simple interest or compounded interest? If the latter, what's the compounding frequency?
As you can see, if you haven't specified enough about the problem that you are trying to solve to even begin to come up with a solution.
If you're not a domain expert on ARMs or financial products in general I strongly encourage you to find someone who is.
The pmt function is based on this math: Payment = Loan Amount at current time / ( 1 - ( 1 / ( 1+ current rate)^numperiods remaining ) )
Figuring out the loan amount at the current time (i.e. after five years of making a payment at a different rate) is the tough part.
This is a pretty complicated calculation that is usually part of a company's intellectual property. So I doubt anyone is going to post code. I've been down this road and it requires huge amounts of testing depending on how far you decide to go with it.
You might want to check out the following document. It has a lot of math on how to get there.
Constructing an Amortization Schedule
edit:
Just to add couple things. When performing the calculations in code it is critical that you use a data type such as Decimal instead of the floating point types like double. Decimal was explicitly created for these types of money calculations. Floating point types will cause many rounding errors, making the calculated values be off by unacceptable amounts.
Next, mortgage calculators that you find online are of highly varying quality. When testing your method it will be useful to see what the online calculators come up with, but by no means consider them more accurate than yours. Generally they are good to see if you are in the right ballpark, but they could be off by as much as .1% per year of the loan term.
Final note
Okay, this is the last edit. You might consider purchasing a library from a company like Math Corp instead of rolling your own. I'm pretty sure it'll be accurate AND much cheaper than the dev / qa time to get yours right.
This gets a little ugly, so please bear with me.
Define:
- g1 = Initial monthly rate (For 3%, g=0.03/12.)
- g2 = Second monthly rate.
- T1 = Term for the initial rate (T1 = 3 for 3 months).
- T2 = Term for the subsequent rate.
- u1 = 1 / (1 + g1)
- u2 = 1 / (1 + g2)
Then:
- payment = g1 * g2 / (g1 * u1^T1 * (1 - u2^T2) + g2 * (1 - u1^T1))
Of course, I may have made a mistake, but that seems right.