Microsoft KB Archive/52070

= Example of PPMT and PMT Financial Functions in Basic =

Article ID: 52070

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q52070



SUMMARY
This program demonstrates how to use the PMT and PPMT financial functions. PMT returns the periodic payment for an investment. In the case of a loan, PMT returns the amount of the constant monthly payment (the sum of principal plus interest) for the loan, based upon a constant interest rate, the total number of payments, and the amount (present value) of the loan.

PPMT is the payment on the principal for an investment at a specified period. (PMT minus PPMT is the payment on the interest at a specified period.) The sum of all PPMT values returned over the life of the loan equals the loan amount.



MORE INFORMATION
Listed below is an analysis of the finances for buying and selling a house. The program returns average equity gain per month after the house has been bought and sold. You can change the initial parameters (such as houseval, down, rate1, sellper, apprec, etc.) to explore different scenarios, including a simplified inflation effect. Negative net equity gain per month is outgoing money; positive net equity gain per month is income.

You can choose the period of time at which you sell the house and compare the net income or outgo per month to that of your current housing situation.

Code Example
' To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program.

' To run this program in the environment, you must invoke the ' environment with the /L switch to load the default Quick library: '   VBDOS.EXE /L FINANCE.QLB         for Visual Basic 1.0 for MS-DOS '   QBX /L FINANCER.QLB              for Basic PDS 7.0 for MS-DOS ' To run outside the QBX.EXE environment, you must link with the ' appropriate library (FINANCER.LIB, FINANCAR.LIB, FINANCEP.LIB, or ' FINANCAP.LIB).

REM $INCLUDE: 'FINANCE.BI'

DEFDBL A-Z

' Initialize variables: CLS houseval = 110000#    ' Purchase price of house (median for Seattle). apprec = 1.07#        ' Assumed yearly appreciation rate of house. sellper = 10# * 12#   ' Period (month) at which you choose to sell. down = .1#            ' Fraction of houseval paid as down payment. equity = down * houseval ' Initial equity in house (10% down payment). pv1 = (1 - down) * houseval 'Present value of loan = 90% of houseval. rate1 = .1025# / 12 ' Loan interest rate (10.25%) divided by 12 months. pool = 0 ' Pool of money, if any, to earn interest & subtract payments. poolint = 1.0057# ' Monthly interest earned on pool to get 7% yearly. pointsbuy = .02# ' Assumed fees to buy loan, as fraction of houseval. pointsell = .07# ' Selling fees (points) as fraction of selling price. per = 0#          ' Month (period) counter. nper1 = 360#      ' # periods in loan. 30-year loan has 360 months. ptype% = 0#       ' 0 means payment due at end of each period. fv1 = 0#          ' Future value (the goal) of a loan is always zero. ptot1 = 0#        ' Current total of principal paid towards loan. in = .95#         ' 1 minus the inflation rate. proptax = -130#   ' Property taxes per month (tax deductible). fire = -25#       ' Fire/house insurance per month. roommate = 400#  ' Rent income from roommate (0 if none) after taxes. roominflate = 1.02 ' Yearly rate you increase your roommate's rent. tax = .8#      ' 1 minus your average yearly Tax rate (as a fraction). initial = pool + equity PRINT &quot;Purchase price =&quot;; houseval; PRINT &quot; // Initial pool + equity = &quot;; initial upfront = equity + (pointsbuy * houseval) PRINT &quot;Up front cost (down payment + loan fees) =&quot;; upfront

' Calculate monthly (principal+interest) payment: payment1 = Pmt(rate1, nper1, pv1, fv1, ptype%, Status%) IF down < .2# THEN minsure = .03 * payment1 ' Monthly mortgage insurance rate (3% of ELSE              ' principal+interest payment). You usually must pay minsure = 0#   ' mortgage insurance if you paid < 20% down. END IF PRINT &quot;monthly payment= &quot; PRINT payment1; &quot;+&quot;; fire; &quot;+&quot;; proptax; &quot;+&quot;; minsure; &quot;= &quot;; PRINT payment1 + fire + proptax + minsure PRINT &quot;not counting tax savings (&quot;; 1 - tax; &quot;factor ) &quot;; PRINT &quot;or roommate income (&quot;; roommate; &quot;)&quot;; PRINT &quot;**************************************************&quot;

' Add up numbers until the period (month) where you sell (sellper): FOR j = 1 TO sellper per = j  ' Yearly rent increase: IF j MOD 12 = 0 THEN roommate = roominflate * roommate

' Calculate principal and interest amounts paid: principal1 = PPmt(rate1, per, nper1, pv1, fv1, ptype%, Status%)

ptot1 = ptot1 + principal1  ' Total accumulated principal to date. interest1 = payment1 - principal1 itot1 = itot1 + interest1 'Total accumulated interest paid to date. ' Outaftertax1 and outgo values are negative: outaftertax1 = ((interest1 + proptax) * tax) + principal1 + fire + minsure pool = pool + outaftertax1 + roommate ' (outaftertax is negative). ' Pool earns interest if positive (no interest charged if negative,  ' assuming you make monthly house payments without borrowing): IF pool > 0 THEN pool = pool * poolint equity = equity + ABS(principal1) ' Monthly principal builds equity. NEXT

' Calculate final appreciation and closing costs; and print out: years = sellper / 12#  ' Number of years after which you sold. aphouseval = houseval * (apprec ^ years) ' Appreciated house value. closecost = -(pointsbuy * houseval) - (pointsell * aphouseval) naphouseval = aphouseval - houseval ' Net appreciation on house value. final = pool + equity + naphouseval + closecost in1989 = final * (in ^ years) ' In 1989 dollars (inflation adjusted). PRINT PRINT &quot;After&quot;; years; &quot; years, buy+sell closecost =&quot;; closecost PRINT &quot;total principal paid=&quot;; ptot1 + ptot2 PRINT &quot;total interest paid=&quot;; itot1 + itot2 PRINT &quot;Appreciated value of house = &quot;; aphouseval PRINT &quot;final pool+equity+apprec-close=&quot;; final PRINT &quot;or&quot;; in1989; &quot; in 1989 dollars with&quot;; 1 - in; &quot;yearly inflation&quot; PRINT &quot;(which is a&quot;; CSNG(in ^ years); &quot; overall inflation factor)&quot; PRINT PRINT &quot;Net ave. equity increase per month=&quot;; (final - initial) / sellper PRINT &quot;(or with inflation=&quot;; (in1989 - initial) / sellper;     &quot;in 1989 dollars)&quot;

Additional query words: VBmsdos BasicCom 1.00 7.00 7.10

Keywords: KB52070

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.