?
Solved

PMT options in C#

Posted on 2004-08-20
3
Medium Priority
?
2,391 Views
Last Modified: 2007-12-19
THis is my question i am converting some old vb6 project to C#. One uses the pmt function. I know that if i Microsoft.VisualBasic as a reference i can use this same function. Most people are not happy with me using this.
so here is the function i found

present value = 10000, financial period is 119 months and interest rate is = .129
public  Double calculate_Amount(double presentValue,  double                    
                   financingPeriod,
double interestRatePerYear)
            {
try
{
   double a, b, x,g;
   double monthlyPayment;
   double vbMnthlyPayment;
   a = (1 + interestRatePerYear / 12);
   b = financingPeriod;
   x =   Math.Pow(a, b);
   x = 1 / x;
   x = 1 - x;
//this is the C# way i get a value of  149.33
  monthlyPayment = (presentValue ) * (interestRatePerYear / 12) / x;
// this is the vb way      i get a value of 150.94            
vbMnthlyPayment = Microsoft.VisualBasic.Financial.Pmt(interestRatePerYear/12,financingPeriod,-(presentValue*(1+interestRatePerYear/12)),0,0);
return(monthlyPayment);

The vb reference  is that amount that i need to keep conistent but i dont know how to change the C# function to return the same answer

please help!!
0
Comment
Question by:Steege
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 10

Accepted Solution

by:
eternal_21 earned 1000 total points
ID: 11856567
Multiply your result by

  (1 + (interestRatePerYear / 12))

And your numbers will match.

The reason for this is that the Microsoft.VisualBasic.Financial.Pmt method can calculate the interest BEFORE the payment or AFTER the payment is made each month.  As you have described it the Due parameter (the last one) is 0.  0 tells the Pmt method to calculate interest before the payment, and a 1 tells the Pmt method to calculate the payment before the interest.

So, your formula is fine if you are making your payment at the start of the month, but if you are paying at the end (and interest has accrued), then you need to multiple your result by (1 + (interestRatePerYear / 12)). (The actual math is a little more complex, but if you expanded the whole amortization formula, you would find that it all works out nice and neat in the end!)
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11856751
And here it is in a nice little method.  Keep in mind that rate is the rate per period (compound), so interestRatePerYear / 12:

  double Payment(double rate, double period, double presentValue)
  {
    return presentValue*rate/(1 - 1/Math.Pow(1 + rate, period))*(1 + rate);
  }

Payment(0.01075d, 119d, 10000d) = 150.942458894686
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 11860267
I don't understand why you are using this as the parameter for "present value":

  presentValue*(1+interestRatePerYear/12)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

777 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