function calculateNPV() {
var initialInvInput = document.getElementById('initialInvestment').value;
var discountRateInput = document.getElementById('discountRate').value;
var cf1Input = document.getElementById('cf1').value;
var cf2Input = document.getElementById('cf2').value;
var cf3Input = document.getElementById('cf3').value;
var cf4Input = document.getElementById('cf4').value;
var cf5Input = document.getElementById('cf5').value;
var resultDiv = document.getElementById('result');
resultDiv.style.display = 'block';
if (initialInvInput === " || discountRateInput === ") {
resultDiv.innerHTML = 'Please enter at least the Initial Investment and Discount Rate.';
return;
}
var investment = parseFloat(initialInvInput);
var ratePercent = parseFloat(discountRateInput);
var rate = ratePercent / 100;
var cf1 = cf1Input === " ? 0 : parseFloat(cf1Input);
var cf2 = cf2Input === " ? 0 : parseFloat(cf2Input);
var cf3 = cf3Input === " ? 0 : parseFloat(cf3Input);
var cf4 = cf4Input === " ? 0 : parseFloat(cf4Input);
var cf5 = cf5Input === " ? 0 : parseFloat(cf5Input);
// Calculate NPV
// Formula: Sum(CF / (1+r)^t) – Initial Investment
var pv1 = cf1 / Math.pow(1 + rate, 1);
var pv2 = cf2 / Math.pow(1 + rate, 2);
var pv3 = cf3 / Math.pow(1 + rate, 3);
var pv4 = cf4 / Math.pow(1 + rate, 4);
var pv5 = cf5 / Math.pow(1 + rate, 5);
var totalPV = pv1 + pv2 + pv3 + pv4 + pv5;
var npv = totalPV – investment;
// Calculate Approx IRR (Newton-Raphson method)
// Function f(r) = -Investment + CF1/(1+r) + … + CF5/(1+r)^5
var guessRate = 0.1; // Initial guess 10%
var maxIterations = 50;
var tolerance = 0.000001;
var irr = null;
for (var i = 0; i < maxIterations; i++) {
var fValue = -investment +
(cf1 / Math.pow(1 + guessRate, 1)) +
(cf2 / Math.pow(1 + guessRate, 2)) +
(cf3 / Math.pow(1 + guessRate, 3)) +
(cf4 / Math.pow(1 + guessRate, 4)) +
(cf5 / Math.pow(1 + guessRate, 5));
var fDerivative = -1 * (cf1 / Math.pow(1 + guessRate, 2)) –
2 * (cf2 / Math.pow(1 + guessRate, 3)) –
3 * (cf3 / Math.pow(1 + guessRate, 4)) –
4 * (cf4 / Math.pow(1 + guessRate, 5)) –
5 * (cf5 / Math.pow(1 + guessRate, 6));
var newRate = guessRate – (fValue / fDerivative);
if (Math.abs(newRate – guessRate) -0.99 && irr = 0 ? "#28a745" : "#dc3545";
var statusText = npv >= 0 ? "Profitable (Accept)" : "Unprofitable (Reject)";
resultDiv.innerHTML =
'
Total Present Value of Cash Flows:' + pvFormatted + '
' +
'
Initial Investment:-' + invFormatted + '
' +
'' +
'
Net Present Value (NPV):' + npvFormatted + '
' +
'
Project Status:' + statusText + '
' +
'
Implied Internal Rate of Return (IRR):' + irrDisplay + '
';
}
How to Calculate NPV and Understand Discount Rates
Net Present Value (NPV) is a core financial metric used to evaluate the profitability of an investment or project. It represents the difference between the present value of cash inflows and the present value of cash outflows over a period of time. Central to this calculation is the Discount Rate, which determines how much future money is worth today.
What is the Discount Rate in NPV?
The discount rate is the percentage rate used to discount future cash flows back to their present value. It reflects the time value of money and the risk associated with the investment. Essentially, receiving $100 today is worth more than receiving $100 next year because you could invest today's money and earn a return.
Choosing the correct discount rate is critical:
Higher Discount Rate: Implies higher risk or higher opportunity cost. This lowers the present value of future cash flows, making the NPV lower.
Lower Discount Rate: Implies lower risk. This increases the present value of future cash flows, making the NPV higher.
How to Determine the Discount Rate
While the calculator above requires you to input a discount rate, determining this number requires analysis of the specific investment context. Common methods include:
WACC (Weighted Average Cost of Capital): For corporate projects, WACC is the standard. It represents the average rate a company expects to pay to finance its assets (through debt and equity).
Opportunity Cost: The return you could earn on an alternative investment with similar risk. If you can get 5% in a savings account, your discount rate for a risky project should be significantly higher than 5%.
Risk-Free Rate + Risk Premium: A theoretical approach where you start with a safe rate (like government bonds) and add a percentage based on the specific risks of the project.
The NPV Formula
The mathematical formula for Net Present Value is:
NPV = ∑ [CFₜ / (1 + r)ᵗ] – Initial Investment
Where:
CFₜ = Cash flow in time period t
r = Discount rate (expressed as a decimal, e.g., 0.10 for 10%)
t = Time period (year 1, year 2, etc.)
Example Calculation
Imagine you invest 10,000 in a project (Year 0). The project generates 3,000 per year for 5 years. You use a discount rate of 10%.
Year 1 PV: 3,000 / (1.10)¹ = 2,727.27
Year 2 PV: 3,000 / (1.10)² = 2,479.34
Year 3 PV: 3,000 / (1.10)³ = 2,253.94
Year 4 PV: 3,000 / (1.10)⁴ = 2,049.04
Year 5 PV: 3,000 / (1.10)⁵ = 1,862.76
Total PV of Cash Flows: 11,372.35 Less Initial Investment: -10,000 NPV: 1,372.35
Since the NPV is positive, the project is theoretically profitable at a 10% discount rate.