Showing posts with label qualifying amount. Show all posts
Showing posts with label qualifying amount. Show all posts

Sunday, May 15, 2022

Python: Financial Functions (2nd Edition)

Python:  Financial Functions (2nd Edition)


This is an update to the python file, which I first released on May 17, 2020:


https://edspi31415.blogspot.com/2020/05/numworkscasio-micropythonpython.html


I am able to transfer and test the python file to a Numworks calculator through the online editor, and TI-84 Plus CE Python through the TI Connect CE.  Because only the math module is used, the python file can be run in most, if not all calculators with Python, as well as Python 3.  


What is included?


*  time value of money calculations

*  net present value and internal rate of return

*  net present value (xnpv) and internal rate of return (xirr) when periods between flows are not consistent, a 365 day-year is assumed

*  simple interest:  calculating interest, total, and solving for principal

*  profit calculations: cost-sell-markup

*  adding sales tax

*  percent change

*  present and future value uniform stream factors

*  compound interest calculations of a single stream:  solve for present value, future value, number of periods, and periodic interest

*  days between dates

*  specific applications:  monthly payment, PITI, qualifying loan amount, sinking fund, expressing a list of amounts as a percent of the sum, prorating an amount among a list of flows


Download the Python file and the instructions (pdf file) here:

https://drive.google.com/file/d/1l7Xg9dM-RHfekKkU7A1Wjay76-yVc56S/view?usp=sharing


Size: about 3,800 bytes.  


Eddie


All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 


Sunday, May 17, 2020

Numworks/Casio MicroPython/Python: Financial Functions

Numworks/Casio MicroPython/Python:  Financial Functions 

My first python script for the Numworks calculator:  finance.py

Great calculator and glad I finally have one. 

Introduction

The following scripts creates the user functions for the following financial functions:

pchg(old, new):  Returns the percent change between two numbers
Example:  pchg(1400,2600) returns 85.71

taxlplus(amt, tax): Adds the tax rate to an amount. amt + tax%.  Results are rounded up to 2 decimal places.
Example:  taxplus(59,9.5) returns 64.6

uspv(n,i):  Takes n (number of payments) and i (periodic interest rate) and calculates the uniform present value factor.  PV = PMT * USPV.  Future value is assumed to be 0.
Example:  n = 36 payments, i = 0.25%.  uspv(36,0.25) returns 34.39

usfv(n,i):  Takes n (number of payments) and i (periodic interest rate) and calculates the uniform future value factor.  FV = PMT * USFV.  Present value is assumed to be 0.
Example:  n = 36 payments, i = 0.25%.  usfv(36,0.25) returns 37.62

mopmt(yrs,rate,loan):  Calculates the monthly payment of a loan with monthly payments.  Payments are assumed to be due at the end of each month.   Results are rounded to up to 2 decimal places. 
Example:  Loan of $238,000 for 30 years at 4.28% annual rate.  mompt(30,4.28,238000) returns 1175.0

annrate(ppy,cpy,rate):  Calculates the equivalent annual rate given ppy (payments per year), cpy (compounding payments per year), rate (estimated periodic rate).
Example:  ppy = 12, cpy = 2, periodic rate = 0.74%.   annrate(12,2,0.74) returns 9.0459

Source for annrate:
Roger F. Farish and The Staff of the Texas Instruments Learning Center.  Calculator Analysis for Business and Finance.  Texas Instruments, Inc.  1977.  ISBN 0-89512-015-1

sinkfund(yrs,rate,pymt):  Calculates the balance of a sink fund (savings account)  of monthly deposits.   Number of years and the annual interest rate are needed.  Deposits are assumed to be due at the end of each month.   Results are rounded to up to 2 decimal places. 
Example:  Monthly deposits of $400.00 for 5 years, at a rate of 2.9%.  sinkfund(5,2.9,400) returns 25793.77

piti(yrs,rate,loan,tax,insur):   Calculates the monthly payment of a mortgage given:  the term of the loan in years (yrs), the annual interest rate (rate), the mortgage (loan), the annual property tax (tax), and the annual property insurance (insur).  Payments are assumed to be due at the end of each month.  Results are rounded to up to 2 decimal places.
Example:  piti(30,3.3,160000,1349,240) returns 833.15

qualinc(inc,debt,taxins,rate,yrs):  Calculates the qualifying amount given the following parameters:  monthly income (inc), monthly debt payments (debt), monthly proper taxes and insurance (taxins), interest rate (rate), and term of the mortgage in years (yrs).   Mortgage payments are assumed to be due at the end of each month.   The standard debt:income ratio of 28:36 is used.  Results are rounded to up to 2 decimal places.
Example:  qualinc(4485,375,126.83,5.30) returns 207288.6


Python Script: finance.py

# 2020-04-12 EWS

from math import *

# percent change
def pchg(old,new):
  pch=(new-old)/old*100
  return pch

# add sales tax  
def taxplus(amt,tax):
  total=amt*(1+0.01*tax)
  return round(total,2)

# uniform pv factor pv=pmt*uspv
def uspv(n,i):
  factor=(1-(1+0.01*i)**(-n))/(0.01*i)
  return factor

# uniform fv factor fv=pmt*usfv
def usfv(n,i):
  factor=((1+0.01*i)**n-1)/(0.01*i)
  return factor
  
# monthly payment
def mopmt(yrs,rate,loan):
  pymt=loan/uspv(yrs*12,rate/12)
  return round(pymt,2)
  
# equivalent annual rate
def annrate(ppy,cpy,rate):
  irate=cpy*100*((1+0.01*rate)**(ppy/cpy)-1)
  return irate
  
# sinking fund
def sinkfund(yrs,rate,pymt):
  sink=pymt*usfv(yrs*12,rate/12)
  return round(sink,2)

# piti
def piti(yrs,rate,loan,tax,insur):
  pymt=loan/uspv(yrs*12,rate/12)+(tax+insur)/12
  return round(pymt,2)

# qualifying income 28:36 ratio
def qualinc(inc,debt,taxins,rate,yrs):
  a=min(inc*0.36-debt,inc*0.28)-taxins
  qual=a*uspv(yrs*12,rate/12)
  return round(qual,2)

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

HP 20S: Acoustics Programs

HP 20S: Acoustics Programs Program A: Speed of Sound in Dry Air cs = 20.05 × √(273.15 + T°C) Code: 01: 61, 41, A: LBL A 02: ...