Question

%%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should...

%%Python Question%%

get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the term of the mortgage, in years (should be a positive integer; default value: 30) ◦ the number of payments per year (should be a positive integer; default value: 12) • Functionality ◦ Compute the minimum mortgage payment. Should use the formula A= Pr(1+r) n (1+r) n−1 where ▪ A is the minimum payment amount ▪ P is the principal amount ▪ r is the interest rate per payment (the annual interest rate divided by the number of payments per year) ▪ n is the total number of payments (the term of the mortgage in years × the number of payments per year) ◦ Use math.ceil() to raise the minimum payment you calculated to the next highest integer, and return this integer. ▪ You will need to import math in order to do this. Remember, import statements belong at the top of your script, right after your script docstring. interest_due() • Parameters ◦ the balance of the mortgage (the part of the principal that has not been paid back yet; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the number of payments per year (should be a positive integer; default value: 12) • Functionality ◦ Compute and return the amount of interest due in the next payment according to the formula i = br, where ▪ i is the amount of interest due in the next payment ▪ b is the balance of the mortgage ▪ r is the interest rate per payment (the annual interest rate divided by the number of payments per year) remaining_payments() • Parameters ◦ the balance of the mortgage (the part of the principal that has not been paid back yet; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the payment amount (the amount the user wants to pay per payment; should be a positive number) ◦ the number of payments per year (should be a positive integer; default value: 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 broken 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 (i.e., the principal; should be a positive number) ◦ the annual interest rate (should be a float between 0 and 1) ◦ the term of the mortgage, in years (should be a positive integer; default value: 30) ◦ the number of payments per year (should be a positive integer; default value: 12) ◦ the user's target payment (the amount the user wishes to pay per payment; should be a positive number or None; default value: 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 user ◦ 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 $, you will pay off the mortgage in payments."; replace the angle brackets with the appropriate values) parse_args() • Parameters ◦ a list of strings containing the command line arguments for the program (when you call this program, you will pass sys.argv[1:] as the argument for this parameter) • Functionality ◦ Create an instance of the ArgumentParser class from the argparse module ◦ Use the add_argument() method of your ArgumentParser instance to add the following arguments: ▪ Required arguments (i.e., the user can't run the program without specifying these): • the total amount of the mortgage (as a float) • the annual interest rate (as a float; should be between 0 and 1) ▪ Optional arguments (i.e., the user can choose to specify these or omit them and use the default values): • the term of the mortgage in years (as an integer; default value: 30) • the number of payments per year (as an integer; default value: 12) • the target payment amount (as a float; default value: None) ◦ Use the parse_args() method of your ArgumentParser instance to parse the list of strings that was passed to your function; this will result in a namespace object, which you should return • Note ◦ You will need to import argparse and sys, or at least parts of these modules, in order for this function to work properly. Remember, import statements belong at the top of your script, right after the script docstring. After your function definitions, you should have an if __name__ == "__main__": statement in which you do the following: • pass sys.argv[1:] to parse_args() and store the result in a variable • call the main() function; pass in the total amount of the mortgage, the annual interest rate, the term of the mortgage, the number of payments per year, and the target payment amount using the values extracted from the command line arguments by your parse_args() function

0 0
Add a comment Improve this question Transcribed image text
Answer #1

from math import ceil

#function to compute the minimum mortgage payment

#parameters:

#P - the total amount of the mortgage

#annual_interest_rate - the annual interest rate

#years - the term of the mortgage in years

#payments_per_year - the number of payments per year

def get_min_payment(P, annual_interest_rate, years=30, payments_per_year=12):

r=annual_interest_rate/payments_per_year

N=years*payments_per_year

min_payment=(r*P*((1+r)**N))/(((1+r)**N)-1)

return ceil(min_payment)

#testing the function

print('Loan details:')

print('Total Mortgage Amount: $%.2f' %(200000))

print('Annual Interest Rate: %.2f%%' %(6.5))

print('Mortgage Term in Years: %d' %(30))

print('Number of Payments per Year: %d' %(12))

print('Minimum payment: $%.2f'%(get_min_payment(200000, 0.065)))

output:

Add a comment
Know the answer?
Add Answer to:
%%Python Question%% get_min_payment() • Parameters ◦ the total amount of the mortgage (called the principal; should...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a program that calculate the amount of a mortgage payment. Refer to the appropriate video...

    Create a program that calculate the amount of a mortgage payment. Refer to the appropriate video or any online source for how the mathematics of the calculation works. If given these three things: The amount of the loan in whole dollars The number of payments (e.g. 360 for 30-year) The interest rate per payment period in percent ( a positive floating-point number) The program should print out the correct value (in dollars and cents) of the per-period payment of principal...

  • The program is in python :) Write a code program to calculate the mortgage payment. The...

    The program is in python :) Write a code program to calculate the mortgage payment. The equation for calculating the mortgage payment is: M = P (1+r)n (1+r)n-1 Where: M is your monthly payment P is your principal r is your monthly interest rate, calculated by dividing your annual interest rate by 12. n is your number of payments (the number of months you will be paying the loan) Example: You have a $100,000 mortgage loan with 6 percent annual...

  • A 30-year mortgage has an annual interest rate of 5.25 percent and a loan amount of...

    A 30-year mortgage has an annual interest rate of 5.25 percent and a loan amount of $175,000. What are the monthly mortgage payments? (Round your answer to 2 decimal places.) Payment A 30-year mortgage has an annual interest rate of 4.65 percent and a loan amount of $225,000. (Hint: Use the "IPMT" and "PPMT" functions in Excel.) What are the interest and principal for the 84th payment? (Round your answers to 2 decimal places.) Interest Principal A 20-year mortgage has...

  • Determine the monthly principal and interest payment for a 20-year mortgage when the amount financed is $255,000 and...

    Determine the monthly principal and interest payment for a 20-year mortgage when the amount financed is $255,000 and the annual percentage rate (APR) is 40%. The monthly principal and interest payment is $ (Round to the nearest cent as needed) Determine the monthly principal and interest payment for a 20-year mortgage when the amount financed is $255,000 and the annual percentage rate (APR) is 40%. The monthly principal and interest payment is $ (Round to the nearest cent as needed)

  • Mortgage Amortization Complete the loan amortization schedule for a Mortgage that will be repaid over 360...

    Mortgage Amortization Complete the loan amortization schedule for a Mortgage that will be repaid over 360 months and answer the following questions (The details about the loan are shown below): Correct Answers 1. What is your monthly payment? 2. What is the total $ amount of payments made over the life of the loan Enter Answers Here. 3. How many months will it take to pay off the loan if you pay an extra $465.71 per month? Note: Enter the...

  • All the below are true or false: a) The principal part of a fixed mortgage loan...

    All the below are true or false: a) The principal part of a fixed mortgage loan payment can be found by multiplying the periodic interest rate by the ending balance for a given period. b) For​ fixed-rate fully amortized mortgage​ loans, more of the fixed payment goes towards principal as we approach the end of the loan term. c) We can find the amount needed to pay off a​ fixed-rate fully amortized mortgage loan at any point in time by...

  • Determine the monthly principal and interest payment for a 15-year mortgage when the amount financed is...

    Determine the monthly principal and interest payment for a 15-year mortgage when the amount financed is $95.000 and the annual percentage rate (APR) is 7.0%. The monthly principal and interest payment is $| (Round to the nearest cent as needed.) Monthly Principal and Interest Payment per $1000 of Mortgage 20 Rate % 4.0 4.5 5.0 5.5 6.0 6.5 7.0 7.5 8.0 8.5 9.0 9.5 10.0 10.5 10 $10.12451 10.36384 10.60655 10.85263 11.10205 11.35480 11.61085 11.87018 12.13276 12.39857 12.66758 12.93976 13.21507...

  • An amortization table reports the amount of interest and principal contained within each regularly scheduled payment...

    An amortization table reports the amount of interest and principal contained within each regularly scheduled payment used to repay an amortized loan. Example Amortization Schedule Payment Interest Repayment of Principal Year Beginning Amount Ending Balance 1 2 3 Consider the amount of the interest payments included in each of the payments of an amortized loan. Which of the following statements regarding the pattern of the interest payments is true? The portion of the payment going toward interest is smaller in...

  • Fulton Corporation purchases new manufacturing facilities and assumes a 10 year mortgage of $2 million. The...

    Fulton Corporation purchases new manufacturing facilities and assumes a 10 year mortgage of $2 million. The annual interest rate on the mortgage is 5.5% and payments are due at the end of each year. a. Determine the mortgage payment that Fulton Corporation must make each year. Round to the nearest dollar. b. Use Excel to prepare a mortgage amortization schedule for the 10 years. c. At the end of the first year, what amount will Fulton include as "current maturities...

  • On December 1, 2018, Driscoll, Inc. signed a 20 year mortgage in the amount of $300,000...

    On December 1, 2018, Driscoll, Inc. signed a 20 year mortgage in the amount of $300,000 in conjunction with the purchase of an office building. This note is payable in equal monthly installments of $1,980 which include interest computed at an annual rate of 5%. The first annual payment is made on December 31, 2018. Prepare an amortization table for the first two payments. How much of the first payment made on December 31, 2018, is allocated to repayment of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT