Home

Math Functions: The Number of Periods of an Investment

     

Introduction

The NumberOfPeriods() function calculates the number of periodic payments of an investment. Here is an example  of calling this function:

//---------------------------------------------------------------------------

#include <vcl.h>
#include <math.hpp>
#pragma hdrstop

#include "Exercise.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnCalculateClick(TObject *Sender)
{
	Extended Present, Future, Rate, Payments, NPeriod;

	Present = StrToFloat(edtPresentValue->Text);
	Future = StrToFloat(edtFutureValue->Text);
	Payments = StrToFloat(edtMonthlyPayment->Text);
	Rate = StrToFloat(edtInterestRate->Text);

	// Apply the function
	NPeriod = NumberOfPeriods(Rate / 100, -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
	edtPeriods->Text = FloatToStr(Actual);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnCloseClick(TObject *Sender)
{
	PostQuitMessage(0);
}
//---------------------------------------------------------------------------
Number of Periods
   

 

 
 
     
 

Home Copyright © 2010-2011 FunctionX, Inc.