Home

Math Functions: The Net Present Value

     

Introduction

The NetPresentValue() function uses a series of cash flows to calculate the present value of an investment. Its syntax is:

Extended __fastcall NetPresentValue(const Extended Rate,
                                    const double * CashFlows,
                                    const int CashFlows_Size,
                                    TPaymentTime PaymentTime);

The CashFlows is an array of payments made on an investment. Because it uses a series of payments, any payment made in the past should have a positive value (because it was made already). Any future payment should have a negative value (because it has not been made yet). The CashFlows should be passed as an array. The CashFlows_Size is the number of payments – 1, which is also the dimension of the array –1.

The Rate is the rate of discount during one period of the investment.

The PaymentTime specifies whether the payment occurs at the beginning or end of the period. It uses the TPaymentTime enumerator.

//---------------------------------------------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
	double Goal;
	double Month1, Month2, Month3, Month4, Month5, Month6;
	Extended Rate;
	int Periods;

	// Retrieve the estimate financial goal to achieve
	Goal = edtGoal->Text.ToDouble();
	// Retrieve the monthly investments
	Month1 = edtMonth1->Text.ToDouble();
	Month2 = edtMonth2->Text.ToDouble();
	Month3 = edtMonth3->Text.ToDouble();
	Month4 = edtMonth4->Text.ToDouble();
	Month5 = edtMonth5->Text.ToDouble();
	Month6 = edtMonth6->Text.ToDouble();
	Rate = StrToFloat(edtRate->Text) / 100;

	double Months[] = { Month1, Month2, Month3, Month4, Month5, Month6 };
	Periods = (sizeof(Months) / sizeof(double)) - 1;
	double NPV = NetPresentValue(Rate,
				     Months,
				     Periods,
				     ptEndOfPeriod) - Goal;

	// Format the number to display as currency
	edtNPV->Text = FloatToStrF(NPV, ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------

Here is an example:

Net Present Value
   

 

 
 
     
 

Home Copyright © 2010-2011 FunctionX, Inc.