Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat function does .NET NPV() use? Doesn't match manual calculations
    primarykey
    data
    text
    <p>I am using the NPV() function in VB.NET to get NPV for a set of cash flows.</p> <p>However, the result of NPV() is not consistent with my results performing the calculation manually (nor the Investopedia NPV calc... which matches my manual results)</p> <p>My correct manual results and the NPV() results are close, within 5%.. but not the same...</p> <p>Manually, using the NPV formula: NPV = C0 + C1/(1+r)^1 + C2/(1+r)^2 + C3/(1+r)^3 + .... + Cn/(1+r)^n</p> <p>The manual result is stored in RunningTotal With rate r = 0.04 and period n = 10</p> <p>Here is my relevant code:</p> <p>EDIT: Do I have OBOB somewhere?</p> <pre><code> YearCashOutFlow = CDbl(TxtAnnualCashOut.Text) YearCashInFlow = CDbl(TxtTotalCostSave.Text) YearCount = 1 PAmount = -1 * (CDbl(TxtPartsCost.Text) + CDbl(TxtInstallCost.Text)) RunningTotal = PAmount YearNPValue = PAmount AnnualRateIncrease = CDbl(TxtUtilRateInc.Text) While AnnualRateIncrease &gt; 1 AnnualRateIncrease = AnnualRateIncrease / 100 End While AnnualRateIncrease = 1 + AnnualRateIncrease ' ZERO YEAR ENTRIES ListBoxNPV.Items.Add(Format(PAmount, "currency")) ListBoxCostSave.Items.Add("$0.00") ListBoxIRR.Items.Add("-100") ListBoxNPVCum.Items.Add(Format(PAmount, "currency")) CashFlows(0) = PAmount '''' Do While YearCount &lt;= CInt(TxtLifeOfProject.Text) ReDim Preserve CashFlows(YearCount) CashFlows(YearCount) = Math.Round(YearCashInFlow - YearCashOutFlow, 2) If CashFlows(YearCount) &gt; 0 Then OnePos = True YearNPValue = CashFlows(YearCount) / (1 + DiscountRate) ^ YearCount RunningTotal = RunningTotal + YearNPValue ListBoxNPVCum.Items.Add(Format(Math.Round(RunningTotal, 2), "currency")) ListBoxCostSave.Items.Add(Format(YearCashInFlow, "currency")) If OnePos Then ListBoxIRR.Items.Add((IRR(CashFlows, 0.1)).ToString) ListBoxNPV.Items.Add(Format(NPV(DiscountRate, CashFlows), "currency")) Else ListBoxIRR.Items.Add("-100") ListBoxNPV.Items.Add(Format(RunningTotal, "currency")) End If YearCount = YearCount + 1 YearCashInFlow = AnnualRateIncrease * YearCashInFlow Loop </code></pre> <p>EDIT: Using the following values: Discount Rate = 4% Life of Project = 10 years Cash Flow 0 = -78110.00 Cash Flow 1 = 28963.23 Cash Flow 2 = 30701.06 Cash Flow 3 = 32543.12 Cash Flow 4 = 34495.71 Cash Flow 5 = 36565.45 Cash Flow 6 = 38759.38 Cash Flow 7 = 41084.94 Cash Flow 8 = 43550.03 Cash Flow 9 = 46163.04 Cash Flow 10 = 48932.82</p> <p>Using the calculator at <a href="http://www.investopedia.com/calculator/NetPresentValue.aspx" rel="nofollow noreferrer">http://www.investopedia.com/calculator/NetPresentValue.aspx</a> And following the manual "textbook" formula I arrive at the same result:</p> <p>Net Present Value: $225,761.70</p> <p>I cannot seem to get NPV() to replicate this result... it spits out $217,078.59</p> <p>I iterate it manually using the example same value... so they must be using a different function than I am...</p> <p>The MSDN page example clearly states that the initial expense should be included in the cash flows list.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload