Q(uick)BASIC Function: PPmt#

Quick View

PPmt#

A function that returns the payment on the principal for a given period of an annuity based on periodic, constant payments and a constant interest rate

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • PPmt# (rate#, per#, nper#, pv#, fv#, type%, status%)
Description/Parameter(s)
rate# The interest rate per period (for example, .12).
per# The payment period: must be in the range from 1 to nper#.
nper# The number of payment periods in the annuity.
pv# The present value.
fv# The future value.
type% An integer expression:
  • 0 = end-of-period payment;
  • 1 = beginning-of-period payment.
status% A variable that returns a value indicating calculation failure or success:
  • 0 = success;
  • 1 = failure.
  • 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 nper# is the total number of payment periods in an annuity. For example, if you get a 4-year car loan and make monthly payments, your loan has a total number of 4x12, or 48 payment periods.
  • The arguments rate# and nper# must use consistent units. For example:
rate nper Loan description
.10/12 4*12 Monthly payment, 4-year loan, 10% annual interest
.10 4 Annual payment, 4-year loan, 10% annual interest
  • The argument per# must be between 1 and nper#, inclusive. If it is outside that range, BASIC generates the error message, "Overflow."
  • The argument pv# is the present value, or lump sum that a series of payments to be paid in the future is worth now. For example, when you borrow money to buy a car, the loan amount is the present value to the lender of the monthly car payments you will make.
  • The argument fv# is the future value, or cash balance sometime in the future after the final payment is made. The future value of a loan, for example, is 0. As another example, if you think you will need $50,000 in 18 years to pay for your child's education, then $50,000 is the future value.
  • 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

  • An annuity is a series of constant cash payments made over a continuous period of time. An annuity can be a loan (such as a home mortgage), or an investment (such as a monthly savings plan).
  • For all arguments, cash you pay out, such as deposits to savings, is represented by negative numbers; cash you receive, such as dividend checks, is represented by positive numbers.

Important

  • To use PPmt# in the QBX environment, use the FINANCER.QLB Quick library. To use PPmt# 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 PPmt#.
  • 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 Pmt# function to determine the payment for a loan over a prescribed period, at a fixed annual percentage rate. It also uses the PPmt# function to determine what part of the payment is principal. The program subtracts the principal payment from the monthly payment to determine the interest part of the payment.
Note: To run this example you must use a Quick library that includes the procedures contained in the financial function library file. The following include file must also be present.

'$INCLUDE: 'FINANC.BI' CONST ENDPER = 0 CONST BEGINPER = 1 CONST DOLLARFORMAT$ = "$#,###.## " CONST PERCENTFORMAT$ = "##.##" FutrVal = 0 DEFDBL A-Z DIM St AS INTEGER CLS INPUT "Enter the annual percentage rate of your loan"; APR PRINT INPUT "What is the principal amount of your loan"; PresVal PRINT INPUT "How many monthly payments is your loan set up for"; Periods PRINT DO WHILE PaymentTypeString$ <> "B" AND PaymentTypeString$ <> "E" PRINT "Are your payments due at the beginning or end of the month? "; PaymentTypeString$ = UCASE$(INPUT$(1)) LOOP 'Set up the correct payment type. IF PaymentTypeString$ = "B" THEN PaymtType = BEGINPER PRINT "Beginning" ELSE PaymtType = ENDPER PRINT "End" END IF PRINT 'Calculate and format the monthly payment. 'Put APR in proper form. IF APR > 1 THEN APR = APR / 100 Payment = ABS(-Pmt#(APR / 12, Periods, PresVal, FutrVal, PaymtType, St)) 'Examine St to determine success of failure of any financial function. IF St THEN 'If unsuccessful, announce a problem. PRINT "There was an error in calculating the monthly payment." ELSE 'Display the calculate monthly payment. PRINT "Your monthly payment is "; PRINT USING DOLLARFORMAT$; Payment PRINT PRINT "Would you like a breakdown of the principal and interest by" PRINT "month for the entire period of the loan? "; DO WHILE Answer$ <> "Y" AND Answer$ <> "N" Answer$ = UCASE$(INPUT$(1)) LOOP PRINT Answer$ PRINT IF Answer$ = "Y" THEN CLS PRINT "Month", "Payment", "Principal", "Interest" PRINT FOR Per = 1 TO Periods 'Calculate the principal part of the payment. PrPmt = ABS(-PPmt#(APR / 12, Per, Periods, -PresVal, FutrVal, PaymtType, St)) 'Properly round the result. PrPmt = (INT((PrPmt + .005) * 100) / 100) 'Calculate the interest part of the payment. IntPmt = Payment - PrPmt 'Properly round the result. IntPmt = (INT((IntPmt + .005) * 100) / 100) 'Examine St to determine success or failure. IF St THEN 'If unsuccessful, announce a problem. PRINT "There was an error in calculating the interest or" PRINT "principal for period"; Per; "of your loan." END ELSE PRINT USING "###"; Per; PRINT TAB(15); PRINT USING DOLLARFORMAT$; Payment; PrPmt; IntPmt END IF NEXT Per END IF END IF