Solved

Auto Loan Calculator Formula

Posted on 2013-10-25
13
739 Views
Last Modified: 2013-10-30
Hi there,

I found this formula online, but when I use it, and compare the result to other auto loan calculators out there, my results are usually slightly lower, so I assume mine are incorrect. Here is the formula I'm using:

 
        [HttpPost]
        public ViewResult Index(double amount, double? payment, double apr, int term)
        {
            var months = term * 12;
            var pc = apr / 100;

            double dAPR = pc;
            Int32 iNumberOfPayments = months;
            double dLoanAmount = amount;

            var end = (Financial.Pmt((dAPR / 100) / 12, iNumberOfPayments, dLoanAmount, 0,  DueDate.EndOfPeriod) * -1);
            var final = String.Format("{0:00}", end);

            ViewBag.result = final;
            return View();

        }

Can someone help me out?

Thanks!
0
Comment
Question by:DonHoddinott2
  • 5
  • 4
  • 4
13 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39602284
Are the others using a daily (you use monthly) method to calculate the interest due?
0
 

Author Comment

by:DonHoddinott2
ID: 39606018
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39606042
Where do you see the formula they use on that page ?
0
 

Author Comment

by:DonHoddinott2
ID: 39606085
I don't see their formula, I see that the label of the text box states that the result is monthly. Maybe if I knew why you were asking, I could help answer your question, so that you may answer my original question.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39606249
because if the interest is calculated daily it will result in a different (higher) value than if calculated monthly.  (You experience a lower value than other web pages).

It is how compound interest behaves.
0
 

Author Comment

by:DonHoddinott2
ID: 39606643
Can you confirm my formula is correct?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 total points
ID: 39607665
Can you explain why you're dividing the rate by 100 twice?

i.e.

var pc = apr / 100;
var dAPR = pc;

then in the function call

var end = (Financial.Pmt((dAPR / 100) / 12,

i believe you only need to do it the once so that it should be (to get the rate per month):

var end = (Financial.Pmt((dAPR) / 12,
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39607692
Ok I've confirmed this in Excel for simplicity and testing against the inbuilt PMT function:

using VBA:

Public Function MyIndex(amount As Double, apr As Double, term As Integer)
    months = term * 12
    pc = apr / 100

    dAPR = pc
    Dim iNumberOfPayments As Double
    iNumberOfPayments = months
    dLoanAmount = amount
    Dim result As Double
    
    result = Financial.Pmt(dAPR / 12, iNumberOfPayments, dLoanAmount)
    
    Debug.Print result
    
    MyIndex = result

End Function

Public Sub Test()
    MyIndex 100000, 7, 30
End Sub

Open in new window


Gives $665.30, which is exactly what the Excel formula PMT gives.  I'm guessing you were just dividing the rate by 100 one too many times :)
Please see the VBA code in the attached spreadsheet as it is a migration from your C# code but still should be the same.
PMT.xlsm
0
 

Author Closing Comment

by:DonHoddinott2
ID: 39609800
Tagit not only answered my question in a direct manner, he also followed up with a source. I very much appreciate considerate responses like his, so thank you Tagit, very much.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39610833
Huh.
OK, my fault. I assumed when you said you had found the formula on line that you had not modified it so I didn't check the code.  Especially as you did explicitly say slightly lower results.  That should result in significantly lower results.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39610846
Using a loan of 100,000 using a rate of 7%, 30 years and monthly repayments.

Instead of being $665 it was $280 so is that slightly lower or significantly lower?
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39610877
Just an addendum.
You don't seem to understand what I was asking about.  Not understanding what you are doing is very bad - you end up with no idea of what you have coded is actually giving realistic results or just plain garbage.


On a loan of 1000 for one year at 5% the monthly payment differs by a fraction of a percent (slightly different) when having the interest accrued monthly or daily.
0
 
LVL 42

Expert Comment

by:Rob Jurd, EE MVE
ID: 39611114
I agree and I do understand what you're saying.  :) It's a good point.  I should've said before that the important thing to note here was the the payments differed - it's irrelevant by how much when you're using a mathematical function.

When I'm unsure about something I go back to something I know and trust, which is why I used Excel.  I had a reference to use when comparing the code from DonHoddinott2.
As you've also said, it is important to know what the PMT function expects as arguments and work through and review the variables you're passing to it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now