- Questions & Answers
- Accounting
- Computer Science
- Automata or Computationing
- Computer Architecture
- Computer Graphics and Multimedia Applications
- Computer Network Security
- Data Structures
- Database Management System
- Design and Analysis of Algorithms
- Information Technology
- Linux Environment
- Networking
- Operating System
- Software Engineering
- Big Data
- Android
- iOS
- Matlab

- Economics
- Engineering
- Finance
- Thesis
- Management
- Science/Math
- Statistics
- Writing
- Dissertations
- Essays
- Programming
- Healthcare
- Law

- Log in | Sign up

Mortgage Calculations

Table of Contents

Instructions

· get_min_payment()

· interest_due()

· remaining_payments()

· main()

· Template

· Running your program

· Testing

Instructions

For this homework you will write a script to do some useful calculations for fixed-rate mortgages. Use the template provided below. At a minimum, your script should contain the functions get_min_payment(), interest_due(), remaining_payments(), and main(), each of which is described below. Be sure to include a docstring in each function.

get_min_payment()

Parameters

· The total amount of the mortgage (called the principal; you can assume this is a positive number)

· The annual interest rate (you can assume this is a float between 0 and 1; for example, an interest rate of 3.5% would be expressed as 0.035)

· The term of the mortgage in years (you can assume this is a positive integer; assign this parameter a default value of 30)

· The number of payments per year (you can assume this is a positive integer; assign this parameter a default value of 12)

Functionality

1. Compute the minimum mortgage payment (AA). You should use the formula A=Pr(1+r)n(1+r)n−1A=Pr(1+r)n(1+r)n-1 where

· PP is the principal amount

·

is the interest rate per payment (the annual interest rate divided by the number of payments per year)

· nn is the total number of payments (the term of the mortgage in years × the number of payments per year)

2. Use math.ceil() to raise the minimum payment you calculated in step 1 to the next highest integer; return this integer.

· You will need to import math in order to do this. import statements belong at the top of your script, right after your script docstring.

NOTE

This function takes into account only principal and interest, which are typically the two largest components in a mortgage payment. In the real world, mortgage payments often also cover other expenses like property taxes, home insurance, and private mortgage insurance.

interest_due()

Parameters

· The balance of the mortgage (the part of the principal that has not been paid back yet; you can assume this is a positive number)

· The annual interest rate (you can assume this is a float between 0 and 1; for example, an interest rate of 3.5% would be expressed as 0.035)

· The number of payments per year (you can assume this is a positive integer; assign this parameter a default value of 12)

Functionality

· Compute and return ii, the amount of interest due in the next payment according to the formula i=

i=

, where

·

is the the balance of the mortgage

·

is the interest rate per payment (the annual interest rate divided by the number of payments per year)

emaining_payments()

Parameters

· The balance of the mortgage (the part of the principal that has not been paid back yet; you can assume this is a positive number)

· The annual interest rate (you can assume this is a float between 0 and 1; for example, an interest rate of 3.5% would be expressed as 0.035)

· The target payment (the amount the user wants to pay per payment; you can assume this is a positive number)

· The number of payments per year (you can assume this is a positive integer; assign this parameter a default value of 12)

Functionality

Compute and return the number of payments required to pay off the mortgage. We will do this by simulating payments one at a time until the balance of the mortgage reaches zero, assuming fixed payments (in other words, assume that each payment is the same amount of money as the previous one).

Note that a mortgage payment is

oken down into two parts: an interest payment, and a part that pays down the balance of the mortgage. The interest payment is calculated as described under interest_due(); the rest of the payment goes toward the balance of the mortgage. The percentage of the payment that goes toward interest decreases with every payment because it depends on the balance of the mortgage, which also decreases with every payment.

Here is an algorithm for simulating payments until the mortgage is paid off:

· Initialize a counter with a value of zero; this counter represents the number of payments to be made.

· As long as the balance of the mortgage is positive, do the following:

· Use the interest_due() function to determine what portion of the next payment will be interest. The total payment minus interest due is the amount that will go toward paying the balance of the principal. Remember, these amounts will change with every payment.

· Reduce the balance by the part of the payment that goes toward paying the balance.

· Increase the counter.

· When the balance of the mortgage is no longer positive, the value of the counter is the number of payments required. Return this value.

main()

Parameters

· The total amount of the mortgage (called the principal; you can assume this is a positive number)

· The annual interest rate (you can assume this is a float between 0 and 1; for example, an interest rate of 3.5% would be expressed as 0.035)

· The term of the mortgage in years (you can assume this is a positive integer; assign this parameter a default value of 30)

· The number of payments per year (you can assume this is a positive integer; assign this parameter a default value of 12)

· The user’s target payment (the amount the user wishes to pay per payment; you can assume this is a positive number or None; assign this parameter a default value of None)

· A value of None indicates that the user wishes to use the minimum payment

Functionality

· Compute the minimum payment using the get_min_payment() function

· Display the minimum payment to the use

· If the user’s target payment is None, set the target payment to the minimum payment

· If the user’s target payment is less than the minimum payment, print a message to the user (e.g., "Your target payment is less than the minimum payment for this mortgage"); otherwise:

· Use remaining_payments() to figure out the total number of payments required (hint: at the beginning of a mortgage, the balance is equal to the total mortgage amount)

· Display this number to the user (e.g., "If you make payments of $< target payment >, you will pay off the mortgage in < total payments > payments."; replace the angle

ackets with the appropriate values)

Template

"""Perform fixed-rate mortgage calculations."""

from argparse import ArgumentParse

import math

import sys

# replace this comment with your implementation of get_min_payment(),

# interest_due(), remaining_payments(), and main()

def parse_args(arglist):

"""Parse and validate command-line arguments.

Args:

XXXXXXXXXXarglist (list of str): list of command-line arguments.

Returns:

XXXXXXXXXXnamespace: the parsed arguments (see argparse documentation fo

XXXXXXXXXXmore information)

Raises:

XXXXXXXXXXValueE

or: encountered an invalid argument.

"""

# set up argument parse

parser = ArgumentParser()

parser.add_argument("mortgage_amount", type=float,

XXXXXXXXXXhelp="the total amount of the mortgage")

parser.add_argument("annual_interest_rate", type=float,

XXXXXXXXXXhelp="the annual interest rate, as a float"

" between 0 and 1")

parser.add_argument("-y", "--years", type=int, default=30,

XXXXXXXXXXhelp="the term of the mortgage in years (default: 30)")

parser.add_argument("-n", "--num_annual_payments", type=int, default=12,

XXXXXXXXXXhelp="the number of payments per year (default: 12)")

parser.add_argument("-p", "--target_payment", type=float,

XXXXXXXXXXhelp="the amount you want to pay per payment"

" (default: the minimum payment)")

# parse and validate arguments

args = parser.parse_args()

if args.mortgage_amount < 0:

XXXXXXXXXXraise ValueE

or("mortgage amount must be positive")

if not 0 <= args.annual_interest_rate <= 1:

XXXXXXXXXXraise ValueE

or("annual interest rate must be between 0 and 1")

if args.years < 1:

XXXXXXXXXXraise ValueE

or("years must be positive")

if args.num_annual_payments < 0:

XXXXXXXXXXraise ValueE

or("number of payments per year must be positive")

if args.target_payment and args.target_payment < 0:

XXXXXXXXXXraise ValueE

or("target payment must be positive")

return args

if __name__ == "__main__":

try:

XXXXXXXXXXargs = parse_args(sys.argv[1:])

except ValueE

or as e:

XXXXXXXXXXsys.exit(str(e))

main(args.mortgage_amount, args.annual_interest_rate, args.years,

XXXXXXXXXXargs.num_annual_payments, args.target_payment)

Running your program

Your program is designed to run from the terminal. To run it, open a terminal and ensure you are in the directory where your script is saved.

The program takes two required command-line arguments: a mortgage amount and an interest rate (expressed as a float between 0 and 1). It also allows the following optional arguments: -y (the term of the mortgage in years), -n (the number of annual payments), and -p (the target payment). Below are some examples of how to use the program. The examples assume you are using macOS and your program is called mortgage.py. If you are using Windows, replace python3 with python. If your program has a different name, replace mortgage.py with the name of your program.

Basic usage

python3 mortgage.py XXXXXXXXXX

With one optional paramete

python3 mortgage.py XXXXXXXXXXy 15

With multiple optional parameters

python3 mortgage.py XXXXXXXXXXy 15 -p 4000

Testing

You can use the script test_mortgage.py to test your solution. Make sure you have Pytest installed (see https:

docs.pytest.org/en/latest/getting-started.html#install-pytest (Links to an external site.)) and that your script and test_mortgage.py are in the same directory on your computer. Edit line 4 of test_mortgage.py so that it contains the name of your script (withou the .py ending).

To use the test script, open a terminal and navigate to the directory containing your script and test_mortgage.py. Then type the following at the command prompt:

pytest test_mortgage.py

Answered 3 days AfterApr 07, 2022

SOLUTION.PDF## Answer To This Question Is Available To Download

- EAI6010 - Module 5: Robotic AI Applications Assignment (Mini-Project) Wavefront planner is a search algorithm for robot navigation in a domain that may have obstacles. It’s closely related to the...SolvedMay 15, 2022
- ASSESSMENT GUIDE Unit Code: ITEC203 Introduction to Data Science and Machine Learning, Study Period, S1 2022 Assessment number (2) Assessment Artefact: Python Codes and Comments Weighting [30%] Why...SolvedMay 14, 2022
- Hi, I need a Python code that solves the following problem by(Fibonacci Variation) using recursion and I want visualization as well the problem is: A single pair of rabbits (male and female) is born...SolvedMay 11, 2022
- Modify the skeleton .py file to translate words from English to Pig Latin. Please do not import anything other than what is already in the skeleton .py file. I've also attached the lecture slides...SolvedMay 11, 2022
- 1 Week 8 Deliverables Overview: This week, you have studied Web application vulnerabilities, password complexity, logs and cryptographic algorithms. The Lab for this week demonstrates your knowledge...SolvedMay 10, 2022
- deep learning assignmentSolvedMay 09, 2022
- Task Summary You will be provided with a Microsoft excel .csv file. This file contains a large volume of data. You must develop an executable that respects the permissions and rules that the file has...SolvedMay 08, 2022
- CAP 6635: Artificial Intelligence (2022 Spring) Course Report Instruction (For students participating final exam) (10 points) Due date [May 6 2022, Firm] This instruction only applies to students who...SolvedMay 03, 2022
- 1 Week 7 Deliverables Overview: This week, you studied additional Flask functionality for creating a secure login form and associated files for a web site. The Lab for this week demonstrates your...SolvedMay 03, 2022
- Course Project 1. The goal of the project is to predict the following from images of the faces provided in the dataset: i. Age: is an integer from 0 to 116 ii. Gender: is either 0 (male) or 1 (female)...SolvedMay 01, 2022

Copy and Paste Your Assignment Here

About Us | Contact Us | Help | Privacy Policy | Revision and Refund Policy | Terms & Conditions | Honor Code

Copyright © 2022. All rights reserved.