Subscribe:

Sunday, January 1, 2012


Home
Finance Functions:
The Present Value of an Investment

 
The PresentValue() function calculates the total amount that future investments are worth currently. Its syntax is:
Extended __fastcall PresentValue(constExtended Rate,
                                                       int NPeriods,
                                                       const Extended Payment,
                                                       const Extended FutureValue,
                                                       TPaymentTime PaymentTime);
Here is an example:

//-------------------------------------
--------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
 Extended Present, Future, TheRate, Payments;
 int NPeriod;

 Future = StrToFloat(edtFuture->Text);
 Payments = StrToFloat(edtPayments->Text);
 TheRate = StrToFloat(edtRate->Text) / 12;
 NPeriod = StrToInt(edtNPeriods->Text);

 double Rate = TheRate / 100;
 // Apply the function
 Present = PresentValue(Rate, NPeriod,
 -Payments, -Future, ptStartOfPeriod);
 // Display the payment
 edtPresent->Text = FloatToStrF(Present, ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------
Home
Finance Functions:
The Amount Paid as Interest

 
The InterestPayment() function is used to calculate the amount paid as interest for a loan. Its syntax is:
Extended __fastcall InterestPayment(const Extended Rate,
        int Period,
        int NPeriods,
        const Extended PresentValue,
        const Extended FutureValue,
        TPaymentTime PaymentTime);
The PresentValue parameter is the current value of the item. It could be the marked value of the car, the current mortgage value of a house, or the cash amount that a bank is lending. The NPeriods is the number of periods that occur during a yearly cycle of the loan. The Rate argument is a fixed percent value applied during the life of the loan. The Period argument represents the payment period. The FutureValue is the total amount that the customer will have paid when the loan is paid off. The PaymentTime specifies whether the periodic (such as monthly) payment of the loan is made at the beginning or end of the period.
Here is an example:




//---------------------------------------------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
 Extended Present, Future, Payment, TheRate;
 int Periods, NPeriod;
 
 Present = StrToFloat(edtPresent->Text);
 Future = StrToFloat(edtFuture->Text);
 Periods = StrToInt(edtPeriod->Text);
 NPeriod = StrToInt(edtNPeriods->Text);
 TheRate = StrToFloat(edtRate->Text) / 12;
 double Rate = TheRate /100;
 
 Payment = InterestPayment(Rate, Periods, NPeriod, Present, Future, ptEndOfPeriod);
 edtPayments->Text = FloatToStrF(Payment, ffCurrency, 8, 2);
}
//---------------------------------------------------------------------------
Home
Finance Functions:
The Interest Rate

 
The InterestRate() function is used to find the interest applied to a loan. Its syntax is:
Extended __fastcall InterestRate(int NPeriods,
                                 constExtended Payment,
                                 const Extended PresentValue,
                                 const Extended FutureValue,
                                 TPaymentTime PaymentTime);
All of the arguments are the same as described for the InterestPayment() function. Here is an example:




//---------------------------------------------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
 Extended Present, Future, Payments, Rate;
 int NPeriod;
 Present = StrToFloat(edtPresent->Text);
 Future = StrToFloat(edtFuture->Text);
 Payments = StrToFloat(edtPayments->Text);
 NPeriod = StrToInt(edtNPeriods->Text);
 
 Rate = InterestRate(NPeriod, Payments, Present, Future, ptEndOfPeriod) * 12 * 100;
 AnsiString Value = FloatToStrF(Rate, ffGeneral, 3, 2);
 edtRate->Text = Value + "%";
}
//---------------------------------------------------------------------------
Home
Finance Functions:
The Internal Rate of Return

 
The InternalRateOfReturn() function is used to calculate an internal rate of return based on a series of investments. Its syntax is:
Extended __fastcall InternalRateOfReturn(constExtended Guess,
                                         const double * CashFlows,
                                         const int CashFlows_Size);
The CashFlows is an array of cash amounts that a customer has made on an investment. For example, a customer could make monthly deposits in a savings or credit union accounts. Another customer could be running a business and receiving different amounts of money as the business is flowing (or losing money). The cash flows do not have to be the same at different intervals but they should (or must) occur at regular intervals such as weekly (amount cut from a paycheck), bi-weekly (401k directly cut from paycheck, monthly (regular investment), or yearly (income). The CashFlows argument must be passed as an array and not an amount; otherwise you would receive an error.
The Guess is an estimate interest rate of return of the investment.
The CashFlow_Size is the dimension of the array – 1.
Here is an example:




//---------------------------------------------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
 double Goal;
 double Month1, Month2, Month3, Month4, Month5, Month6;
 Extended InterestGuess;
 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();
 // Guess how much percentage
 InterestGuess = StrToFloat(edtGuess->Text) / 100;

 double Months[] = {-Goal,Month1,Month2,Month3,Month4,Month5,Month6};
 Periods = (sizeof(Months) / sizeof(double)) - 1;
 double IRR = InternalRateOfReturn(-InterestGuess, Months, Periods) * 100;

 // Format the number to display only two decimals
 AnsiString Value = FloatToStrF(IRR, ffGeneral, 3, 2);
 // Display the result with a percent sign
 edtIRR->Text = Value + "%";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnExitClick(TObject *Sender)
{
 exit(0);
}
//---------------------------------------------------------------------------
Home
Finance Functions:
The Net Present Value

 
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.
Here is an example:




//---------------------------------------------------------------------------
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);
}
//---------------------------------------------------------------------------

 

0 comments:

Post a Comment