Q(uick)BASIC Function: MIRR#
Quick View
MIRR#
A function that returns the modified internal rate of return for a series of periodic cash flows (payments and receipts)
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- MIRR# (valuearray#(), valuecount%, fin-rate#, reinv-rate#, status%)
Description/Parameter(s)
valuearray#() | An array of cash flow values. |
valuecount% | The total number of items in the cash flow array. |
fin-rate# | The interest rate paid as the cost of financing. |
reinv-rate# | The interest rate received on gains from cashreinvestment. |
status% | A variable that returns a value indicating calculation failure or success: 0 = success; 1 = failure. |
- The argument valuearray#() must contain at least one negative value (a payment) and one positive value (a receipt).
- The arguments fin-rate# and reinv-rate# are percentages expressed as decimal values (for example, 12% is expressed as .12).
- The argument status% can be any variable that returns information about the success or failure of the calculation. The value of status% will be 0 if the calculation was successful, and 1 if it was not.
Usage Notes
- MIRR# returns the modified internal rate of return. MIRR# considers both the cost of the investment (finrate#) and the interest received on reinvestment of cash (reinv-rate#).
- MIRR# uses the order of values within the array to interpret the order of payments and receipts. Be sure to enter your payment and receipt values in the correct sequence.
- The formula for MIRR# is found in the BASIC Language Reference manual.
Important
- To use MIRR# in the QBX environment, use the FINANCER.QLB Quick library. To use MIRR# outside the QBX environment, link your program with the appropriate FINANCxx.LIB file. Depending on the compiler options you chose when you installed BASIC, one or more of the following files will be available:
Filename | Compiler options |
FINANCER.LIB | 80x87 or emulator math; DOS or OS/2 real mode |
FINANCAR.LIB | Alternate math; DOS or OS/2 real mode |
FINANCEP.LIB | 80x87 or emulator math; OS/2 protected mode |
FINANCAP.LIB | Alternate math; OS/2 protected mode |
- The FINANC.BI header file contains the necessary function declarations for MIRR#.
- For more information on using libraries, see "Creating and Using Quick Libraries" and "Using LINK and LIB" in the BASIC Programmer's Guide.
Example
This example uses the MIRR# function to determine the modified internal rate of return for a series of periodic cash flows represented in an array of values.
Note: To run this example you must use a Quick library that includes the procedures contained in one of the financial function library files. The following include file must also be present.
'$INCLUDE: 'FINANC.BI'
OPTION BASE 1
CONST PERCENTFORMAT$ = "##.##"
DEFDBL A-Z
DIM Status AS INTEGER, NumFlows AS INTEGER
NumFlows% = 6
DIM Values(NumFlows%) AS DOUBLE
LoanAPR = .1
InvestAPR = .12
'Read cash flows into Values# array.
FOR I = 1 TO NumFlows%
READ Values#(I)
NEXT I
CLS
'Calculate the internal rate of return.
ReturnRate = MIRR#(Values#(), NumFlows%, LoanAPR, InvestAPR, Status%)
'Examine Status% to determine success or failure of MIRR#.
IF Status% THEN
'If unsuccessful, announce a problem.
PRINT "There was an error in calculating the internal rate of return."
ELSE
'Display the internal rate of return.
PRINT "Suppose you're a commercial fisherman and you've just completed"
PRINT "your fifth year of operation. When you started your business,"
PRINT "you borrowed $120,000 at 10% annual interest to buy a boat."
PRINT
PRINT "Your catch yielded $39,000, $30,000, $21,000, 37,000, and $46,000"
PRINT "for each of the first five years. During the first 5 years you"
PRINT "reinvested your profits, earning 12% annually."
PRINT
PRINT "The modified internal rate of return for these cash flow figures"
PRINT "is ";
PRINT USING PERCENTFORMAT$; ReturnRate * 100;
PRINT "%."
PRINT
END IF
'Cost of buying a commercial fishing boat (Negative cash flow).
DATA -120000
'Net income each year for 5 successive years (Positive cash flow).
DATA 39000,30000,21000,37000,46000