?
Solved

Net Present Value Function

Posted on 2006-11-19
4
Medium Priority
?
1,129 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 63

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

770 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