This is a simple C++ program to compute Net Present Value ( NPV ) for a imaginary project. The NPV is computed to analyses an investment taking into account its discounted cash inflows for a specific period of time.
The program is intended for both beginners and intermediate learners of C++ programming. Dev-C++ is used for compiling the program. You may use any standard C++ compiler like Turbo C++ and the program will still work. You first try the program on your own and then look at the program code and verified output to compare the results. In this way, you will learn effectively.
Problem Definition
The purpose of NPV is to evaluate the profitability of an investment. Before you try to understand the Net Present Value (NPV) of an investment, you must understand a few terminologies.These terms are used in the NPV calculations.
Future Value (FV)
If you invest $100 at a rate of 10% per annum. After 1 year you will receive $110 and this is called the Future Value (FV). To compute FV use the following formula.
where
= initial investment
= interest rate (in percentage)
= number of periods ( Note: period can be monthly, quarterly, or yearly)
Present Value (PV)
Suppose you are getting an amount of $120 for an investment at rate of 10% per annum. The find the Present Value(PV) of $120 use the following formula.
where
= future Value
= interest rate ( here it called a discount rate)
= number of periods ( Note: period can be monthly, quarterly, or yearly)
You can see that there is an inverse relationship between PV and FV for an investment.
Net Present Value (NPV)
Business transactions are not as simple as given in the above examples. In an accounting period, there can be numerous cash flows for a business. The Net Present Value calculation takes into account each type of cash flow – incoming and outgoing, take the Present Value (PV) of each cash flow, and add the incoming, or subtract the outgoing cash flow to determine the NPV of an investment business.
To compute the NPV use the following formula,
+ * + * + … + *
where
= initial investment
= future incoming cash flow at a specific period.
= discount rate
= number of periods.
Example
Consider the following example, where an investor wants to find the NPV of a project called Project-I. The initial investment of the project is $100,000, the discount rate is 10% and the investment is for 5 years. He receives a regular cash flow at the end of every period and the discounted cash flow is calculated accordingly.
The following program uses the above data as input values and computes the NPV and the net profit for the business. The NPV is given by following formula.
NPV = Total Discounted Cash Flow (DCF) – Initial Investment (C)
NPV = $620.9213231
Net Profit = Total Cash Flow (TCF) – Initial Investment (C)
Net Profit = $50000
Both the figures are given in the above table. Based on the NPV value, you can decide whether to accept the proposal or reject it.
Program Code – Program to Compute NPV
Find the program source code for Net Present Value (NPV ) in C++. The input for the program is given in the previous section.
/* Program to compute the Net Present Value of a Project*/
#include <iostream.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
int main()
{
double NPV,initial,cashflow[100],dcf[100],year,discount_rate;
double discount_factor[100],temp,d,total,Net_Profit;
int i;
NPV = 0.0;
Net_Profit = 0.0;
cout << "Enter Discount Rate:";
cin >> discount_rate;
cout << "Enter Year:";
cin >> year;
cout << "Enter Initial Investment:";
cin >> initial;
cout << "Enter Year wise cashflow" << endl;
for(i=1;i <= year;i++)
{
cout << "Year\t" << i << "\t" << ":";
cin >> cashflow[i];
}
//Compute the discount Factor
for(i=1;i <= year;i++)
{
temp = discount_rate/100;
d = temp + 1 ;
discount_factor[i] = 1/(pow(d,i));
dcf[i] = cashflow[i] * discount_factor[i];
}
for(i=1;i <= year;i++)
{
NPV = NPV + dcf[i];
total = total + cashflow[i];
}
Net_Profit = total - initial;
NPV = NPV - initial;
cout << endl;
for(i=1;i <= year;i++)
{
cout << discount_factor[i] << "\t" << dcf[i] << endl;
}
cout << endl;
cout << "NPV=" << NPV << endl;
cout << "Net Profit=" << Net_Profit << endl;
getch();
return 0;
}
Output – NPV Program
The output from the above program is given below. The output is same as given in the table from the earlier section. If you cannot find the correct answer, then check the input values.