Sulphy Sulphy - 3 years ago 319
C# Question

Amortization schedule calculation with differing results

I'm attempting to build a small program to generate a string output which will tell me the total repayable amount for a loan (compound interest on a monthly basis). I'm using two online calculators to validate my workings, however both differ to one another.

  • Loan amount: 1000

  • Rate: 7%

  • Duration:36 months

  • Monthly repayable: 30.78

  • Total repayable: £1108.04 (this is close to the result I'm

The above is validated via the following online calculator:

However, on pretty much every other online calculator I get:

  • Monthly repayable: 30.88

  • Total repayable: £1,111.53


Furthermore in my own code I get 1,111.53. So I'm a bit confused as to which end value is correct. I'd like to get closer to the first amount of 1,108.04 as thats the value I've been asked to find, but not sure what I'm missing here.

public void CompoundCalculator(double lenderRate, double loanPeriodInMonths, double desiredLoanAmount){
var repaymentAmount = PMT(7, 36, 1000);
var balance = desiredLoanAmount;
var totalInterest = 0.00;

for (var i = 0; i < loanPeriodInMonths;i++)

var monthlyInterest = Math.Round(balance * ( (lenderRate / 1200) ),2);

balance -= Math.Round(repaymentAmount - monthlyInterest,2) ;
totalInterest += monthlyInterest;

//do something here later with totalInterest variable


public static double PMT(double yearlyInterestRate, int totalNumberOfMonths, double loanAmount)
var rate = (double)yearlyInterestRate / 100 / 12;
var denominator = Math.Pow((1 + rate), totalNumberOfMonths) - 1;
return (rate + (rate / denominator)) * loanAmount;

Answer Source

Your problem is that you use the wrong rate : you make as if the monthly rate was yearlyrate/12 while it is in fact (1+yearlyrate)^(1/12)-1 (which is the rate that gives yearlyrate when you compound it 12 times.

For example, for a 7% rate, the monthly rate is ~0.5654% and not 0.5833% like your computation finds.

replace your formula from (double)yearlyInterestRate / 100 / 12 to

Math.Pow(1+(yearlyInterestRate / 100),1.0/12)-1

should give you the correct result (~30.7789$ per month)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download