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
4
Medium Priority
?
1,152 Views
Last Modified: 2012-06-27
Is there a math function in C# for computing the Net Present Value?  
0
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 30

Accepted Solution

by:
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

by:sumix
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

by:sumix
ID: 17975866
ok, sorry for my double posting.
0
 
LVL 64

Expert Comment

by:Fernando Soto
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];
            // Business start-up costs.
            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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Video by: ITPro.TV
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…

610 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