Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# Net Present Value Function

Posted on 2006-11-19
Medium Priority
1,152 Views
Is there a math function in C# for computing the Net Present Value?
0
Question by:Hojoformo
[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
• 2

LVL 30

Accepted Solution

anarki_jimbel earned 2000 total points
ID: 17975827
See Financial.NPV method (static)

It's in the Microsoft.VisualBasic namespace, however can be used in C#
0

LVL 12

Expert Comment

ID: 17975844

There is a .net class you can use, Microsoft.VisualBasic.Financial, which has a static method named NPV.
0

LVL 12

Expert Comment

ID: 17975866
ok, sorry for my double posting.
0

LVL 64

Expert Comment

ID: 17975900
Hi Hojoformo;

Visual C# does not have the function but as the other post state you can import the function from Visual Basic. The function in C# would look like this:

Microsoft.VisualBasic.Financial.NPV(FixedRetRate, ref values);

You must add a reference to the above function by going to the Windows Explorer and right click on References and select Add References and locate Microsoft.VisualBasic and add it to your project.

Here is some sample code to test the function.

// Define money format.
string MoneyFmt = "###,##0.00";
// Define percentage format.
string PercentFmt = "#0.00";

double[] values = new double[5];
values[0] = -70000;
// Positive cash flows reflecting income for four successive years.
values[1] = 22000;
values[2] = 25000;
values[3] = 28000;
values[4] = 31000;

// Use the NPV function to calculate the net present value.
// Set fixed internal rate.
double FixedRetRate = 0.0625;
// Calculate net present value.
double NetPVal = Microsoft.VisualBasic.Financial.NPV(
FixedRetRate, ref values);
string Msg = "The net present value of these cash flows is ";
Msg = Msg + NetPVal.ToString(MoneyFmt);
MessageBox.Show(Msg);       // Display net present value.

The above code came from Microsoft documentation at http://msdn2.microsoft.com/en-us/library/4k3y7xeh.aspx.

Fernando
0

## Featured Post

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
###### Suggested Courses
Course of the Month10 days, 4 hours left to enroll