Math 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(const Extended 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.


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

#include "Exercise.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TfrmExercise *frmExercise;
__fastcall TfrmExercise::TfrmExercise(TComponent* Owner)
	: TForm(Owner)
void __fastcall TfrmExercise::btnCalculateClick(TObject *Sender)
	double Goal;
	double Month1, Month2, Month3, Month4, Month5, Month6;
	Extended InterestGuess;
	int Periods;

	// Retrieve the estimate financial goal to achieve
	Goal = edtInvestmentGoal->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
	UnicodeString Value = FloatToStrF(IRR, ffGeneral, 3, 2);
	// Display the result with a percent sign
	edtIRR->Text = Value + L"%";
void __fastcall TForm1::btnCloseClick(TObject *Sender)

Here is an example:

Internal Rate of Return



Home Copyright © 2010-2016, FunctionX