How to write a code for dynamic NPV()
Hi, i'm new to vb.net and trying to use the present value function for my own use accounting application: PV = FV / (1 + x) ^ t. The FV will take place between 3 to 10 years investment and each year will be given a different amount of cash by the user. This PV later will be used to calculate the Net Present Value by substracting the initial cost amount given with the PV . I'm not familiar with array yet, so this is what i have wrote:
Static valarray(5) As Double
Dim rate, NPer, pmt, dblNetPresentValue As Double
Dim dblPvResult, dblNPV As Double
valarray(0) = Convert.ToDouble(nudOutlay.Value)
valarray(1) = Convert.ToDouble(txtYearOne.Text)
valarray(2) = Convert.ToDouble(txtYearTwo.Text)
valarray(3) = Convert.ToDouble(txtYearThree.Text)
valarray(4) = Convert.ToDouble(txtYearFour.Text)
valarray(5) = Convert.ToDouble(txtYearFive.Text)
rate = Convert.ToDouble(txtDiscountRate.Text)
'NPer(4) = valarray(4)
pmt = nudOutlay.Value
dblPresentValue = NPV(rate, valarray())
dblPvResult = dblNetPresentValue
FV(rate, NPer, pmt)
dblNPV = dblNetPresentValue - pmt
lblDisplayNPV.Text = Convert.ToString(dblNPV)
and i'm getting confused with all the PV(), NPV(), and FV() functions.
Thank you for the help guys.