|
Finance Functions:
The Future Value of an Investment |
The FutureValue() function is used to calculate the future value of an investment. The syntax of this function is:
Extended __fastcall FutureValue(Extended Rate, int NPeriods, Extended Payment, Extended PresentValue, TPaymentTime PaymentTime);
Here is an example:
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCalculateClick(TObject *Sender) { Extended Present, Future, Payment, TheRate; int Period; Present = StrToFloat(edtPresent->Text); Payment = StrToFloat(edtPayment->Text); Period = StrToInt(edtPeriod->Text); TheRate = StrToFloat(edtRate->Text) / 12; double Rate = TheRate /100; Future = FutureValue(Rate, Period, Payment, Present, ptEndOfPeriod); edtFuture->Text = FloatToStrF(Future, ffCurrency, 8, 2); } //--------------------------------------------------------------------------- void __fastcall TForm1::btnExitClick(TObject *Sender) { Close(); } //---------------------------------------------------------------------------
|
Finance Functions:
The Number of Periods of an Investment |
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCalculateClick(TObject *Sender) { Extended Present, Future, TheRate, Payments, NPeriod; Present = StrToFloat(edtLoan->Text); Future = StrToFloat(edtFuture->Text); Payments = StrToFloat(edtPayments->Text); TheRate = StrToFloat(edtRate->Text) / 12; double Rate = TheRate / 100; // Apply the function NPeriod = NumberOfPeriods(Rate, -Payments, -Present, Future, ptStartOfPeriod); // Since the number of periods is really an integer, find its ceiling Extended Actual = Ceil(NPeriod); // Display the number of periods edtNPeriods->Text = FloatToStr(Actual); } //--------------------------------------------------------------------------- void __fastcall TForm1::btnExitClick(TObject *Sender) { PostQuitMessage(0); } //---------------------------------------------------------------------------
|
Finance Functions:
Making an Investment or Paying a Loan |
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCalculateClick(TObject *Sender) { Extended Present, Future, TheRate, Payments, NPeriod; Present = StrToFloat(edtLoan->Text); Future = StrToFloat(edtFuture->Text); TheRate = StrToFloat(edtRate->Text) / 12; NPeriod = StrToFloat(edtNPeriods->Text); double Rate = TheRate / 100; // Apply the function Payments = Payment(Rate, NPeriod, -Present, Future, ptStartOfPeriod); // Display the payments edtPayments->Text = FloatToStrF(Payments, ffCurrency, 8, 2); } //---------------------------------------------------------------------------
|
Finance Functions:
The Amount Paid as Principal |
While the InterestPayment() function calculates the amount paid as interest for a loan, the
PeriodPayment() function calculates the actual amount that
applies to the balance of the loan. This is referred to as the
principal. Its syntax is:
Extended __fastcall PeriodPayment(constExtended Rate, int Period, int NPeriods, const Extended PresentValue, const Extended FutureValue, TPaymentTime PaymentTime);
Here is an example:
|
//--------------------------------------------------------------------------- void __fastcall TForm1::btnCalculateClick(TObject *Sender) { Extended Present, Future, TheRate, PPayment; int Periods, NPeriod; Present = StrToFloat(edtLoan->Text); Future = StrToFloat(edtFuture->Text); TheRate = StrToFloat(edtRate->Text) / 12; Periods = StrToInt(edtPeriod->Text); NPeriod = StrToInt(edtNPeriods->Text); double Rate = TheRate / 100; // Apply the function PPayment = PeriodPayment(Rate, Periods, NPeriod, -Present, Future, ptStartOfPeriod); // Display the payment edtPPMT->Text = FloatToStrF(PPayment, ffCurrency, 8, 2); } //---------------------------------------------------------------------------
0 comments:
Post a Comment