You can only use while loops for iteration (no range loops or for loops this time). Also, data structures that we have not covered yet (e.g. Lists, Dictionaries, Tuples, etc.) are
python question
For this homework, you can only use while loops for iteration (no range loops or for loops this time). Also, data structures that we have not covered yet (e.g. Lists, Dictionaries, Tuples, etc.) are off-limits for this assignment. Do not use them.
File names: mortgage_payments.py, test_mortgage_payments.py
Most people take a mortgage loan in order to purchase a house, and then pay it over a period of time. The loan is in terms of principal (the amount of money you initially borrow), the annual interest rate (in percentage) and the duration of the loan (e.g. 30 years). A mortgage payment is due every month for the duration of the loan. There are other nuances (such as making extra payments, purchasing points, etc.) that we will ignore in this problem.
Given the principal amount P, monthly interest rate ‘r’ and the duration of the loan ‘n’ in months, the monthly mortgage payment M is calculated by the formula:
Part of each monthly payment goes towards the interest, and the remaining part goes towards reducing the principle (for example, if one pays $500 per month, $100 may go towards the principal and $400 towards the interest). This is done by computing the interest owed on a monthly basis, depending on the remaining principle in that month. Let us take an example.
Suppose our principal is $600000, borrowed at an annual rate of 6% over 30 years (360 months). By the above formula, the monthly payment is $3597.3.
Month 1:
Remaining principal: $600000
Monthly interest rate: 0.5% (6/12)
Interest due on the principal this month = 0.005*600000 = $3000
Part of payment that goes towards interest: $3000
Part of payment that goes towards principal = 3597.3 – 3000 = $597.3
Month 2:
Remaining principal: 600000-597.3 = $599402.70
Monthly interest rate: 0.5% (6/12)
Interest due on the principal this month = 0.005*599402.7 = $2997.01
Part of payment that goes towards interest: $2997.01
Part of payment that goes towards principal = 3597.3-2997.01 = $600.29
Month 3:
Remaining principal = 599402.7 – 600.29 = $598,802.41
…
(Notice how at the end of two months, despite paying almost $7200, our principal went down only by about $1200! We can see how our most of our payments in the initial years go towards interest, and the principal goes down slowly).
It is useful to answer this forward-looking question: Given the principal, annual interest rate and duration of the loan, how much principal will be remaining at the end of a certain month? In the above example: given a principal of $600000 borrowed at an annual interest rate of 6% over 30 years, the principal remaining at the end of month 2 is $598,802.41.
In this programming assignment, you will write a function principal_remaining_by(principal,annual_interest_rate,duration_in_months,by_month):
principal is the initial amount borrowed
annual_interest_rate is in percentage (e.g. 6%), but just as a number (i.e. no % sign)
duration_in_months is the duration of the loan in months
by_month is the month number (starting from 1) at the end of which, you have to return the remaining principal
This function should return the principal owed at the end of the specified month, as a number. You may make the following assumptions:
All the inputs are validated before calling this function (i.e. all parameters are positive numbers, the two month parameters are integers, the by_month is less than or equal to duration_in_months)
You should also write tests for this function. All tests should be in the test_mortgage_payments.py file. You may use this mortgage payment calculator to create your examples: https://www.investopedia.com/amortization-calculator-5086959Links to an external site.
Do not only use very short loan durations and check for the first or second month! You are expected to write at least 5 tests (the more, the better!)
Hints and tips:
Notice that you must perform the same computations for several months, starting from the first month.
Carefully solve the problem on paper first. Take care to observe which quantities you need to maintain in order to eventually get to the answer you seek. For example, each of the numbers you see in the example above are necessary to get to the final answer.
Requirements: none
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.