Solved

Net Present Value Function

Posted on 2006-11-19
4
1,035 Views
Last Modified: 2012-06-27
Is there a math function in C# for computing the Net Present Value?  
0
Comment
Question by:Hojoformo
  • 2
4 Comments
 
LVL 29

Accepted Solution

by:
anarki_jimbel earned 500 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 62

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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now