Q(uick)BASIC Function: NPV#
Quick View
NPV#
A function that returns the net present value of an investment based on a series of periodic cash flows and on a discount rate
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- NPV# (rate#, valuearray#(), valuecount%, status%)
Description/Parameter(s)
- The argument rate# is the interest rate per period. For example, if you get a car loan at a 10% annual interest rate and make monthly payments, the rate per period would be .10/12, or .0083.
- The argument valuearray#() must contain at least one negative value (a payment) and one positive value (a receipt).
- 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
- The net present value of an investment is today's value of a future series of payments (negative values) and receipts (positive values).
- The cash flow values must be equally spaced in time and occur at the end of each period.
- NPV# uses the order of values within the array to interpret the order of cash flows. Be sure to enter your payment and receipt values in the correct sequence.
- The NPV# investment begins one period before the date of the first cash flow value and ends with the last cash flow in the list.
- The NPV# calculation is based on future cash flows. If your first cash flow occurs at the beginning of the first period, the first value must be added to the NPV# result, not included in the cash flow values of valuearray#().
- The formula for NPV# is found in the BASIC Language Reference manual.
Important
- To use NPV# in the QBX environment, use the FINANCER.QLB Quick library. To use NPV# 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 NPV#.
- For more information on using libraries, see "Creating and Using Quick Libraries" and "Using LINK and LIB" in the BASIC Programmer's Guide.
Important
- The differences between NPV# and PV# are:
PV# cash flows NPV# cash flows - Begin at the end or the beginning of the period
- Occur at the end of the period
- Are constant throughout the investment
- Are variable
Example
This example uses the IRR# function to determine the internal rate of return for a series of periodic cash flows represented in an array of values. It then uses the NPV# function to determine the net present value for the same periodic cash flows used to determine the internal rate of return.
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 DOLLARFORMAT$ = "$#,###.##"
CONST PERCENTFORMAT$ = "##.##"
DEFDBL A-Z
DIM Status AS INTEGER, NumFlows AS INTEGER
NumFlows% = 6
DIM Values(NumFlows%) AS DOUBLE
Guess = .1
'Read cash flows into Values# array.
FOR I = 1 TO NumFlows%
READ Values#(I)
NEXT I
'Calculate the internal rate of return.
ReturnRate = IRR#(Values#(), NumFlows%, Guess, Status%)
'Examine Status% to determine success or failure of IRR.
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 "You're starting a printing business. You estimate that it will"
PRINT "cost you $70,000.00 in start-up costs. Your net annual income "
PRINT "for the next five years is expected to be $12,000, $15,000, "
PRINT "$18,000, $21,000, and $26000, respectively."
PRINT
PRINT "The internal rate of return for these cash flow figures is";
PRINT USING PERCENTFORMAT$; ReturnRate * 100;
PRINT "%."
PRINT
'Calculate the net present value.
NetPresentValue = NPV#(ReturnRate, Values#(), NumFlows%, Status%)
IF Status% THEN
PRINT "There was an error in calculating the net present value."
ELSE
PRINT "The net present value of the cash flows used to calculate"
PRINT "the internal rate of return is effectively ";
PRINT USING DOLLARFORMAT$; NetPresentValue;
PRINT "."
END IF
END IF
'Estimated cost of starting up a printing business (Negative cash flow).
DATA -70000
'Net income each year for 5 successive years (Positive cash flow).
DATA 12000,15000,18000,21000,26000