Answered by:
Function PMT in C#

Hello,
There is a function PMT in Excel and in Microsoft.VisualBasic for calculating the payment for loan based on the constant payment and constant interest rate. Is there a similar function in C# or can i use the one from Microsoft.VisualBasic? What do i use to get this value?
thanks
Question
Answers
All replies


Hi Philippe,
I am trying to call pmt function of Financial class as mentioned in above trail forum.
Although after including Microsoft.VisualBasic namespace, I dont see any class named Financial.
Please guide,
Thanks in Advance,
Rupali Kothawade
Rupali Kothawade Vana Solutions www.vanasolutions.com 
You need to add reference in your Project to "Microsoft.VisualBasic".
This reference usually points to:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.dll
Pierre Assis Noronha Proposed as answer by Pierre Assis Noronha Thursday, February 03, 2011 6:13 PM

Besides making use of a built in function, you can create your own UDF for PMT in C#
Excel and other spreadsheet programs make use of a mathematical equation to calculate the 5 related time value of money functions. These 5 TVM functions include PV, FV, PMT, NPER and RATE
The equation used is as follows
PV (1+RATE)^NPER + PMT (1 + RATE * TYPE ) [{(1+RATE)^NPER  1}/RATE] + FV = 0
TYPE is 0 for an ordinary annuity where payments are made or are due at the end of period (loan payments)
TYPE is 1 for an annuity due where payments are made or are due at the start of period (rent payments)
So by manipulating the equation you can write PMT function with code such as
PMT = RATE * ( FV + PV * Math.pow(1+RATE,NPER)) / ((Math.pow(1+RATE,NPER)1)*(1+RATE*TYPE));
 Edited by FinancialEngineer Saturday, August 11, 2012 10:29 PM fixed typo