Sep-13-2017, 11:26 PM
(This post was last modified: Sep-13-2017, 11:26 PM by IamSirAskAlot.)
So, I will be starting a graduate program in Data Science in Spring 2018 and I am trying to get acquainted with Python before then, but I am having some difficulty with a problem I am working on to force myself to better understand how this works.
Here is the exact description of the problem:
In this problem, you will create a mortgage calculator that takes as input the principal loan amount, interest rate, and monthly payment. As output, your calculator should generate an amortization table, and compute how many years and months it took to pay off the mortgage, and report the total amount of payments over that time.
In a mortgage, the bank lends you a certain amount of principal to purchase a house at a certain interest rate. Every month, the amount you owe (the balance) first increases due to interest: 1/12 of the interest rate times the current balance. Then the balance decreases due to your monthly payment. For example, suppose you borrow $100,000 at 5% annual interest, with $500 monthly payments. In the first month, the interest increases the balance by $416.67, and then your payment reduces it by $500, for a remaining balance of $99,916.67. In the second month, the interest charge is $416.32, and the remaining balance is $99,832.99.
If you continue this process, you get an amortization table like this:
Expected Mortgage Amortization Table Outcome
You can also compute the total amount of time and money to pay off the mortgage. In this example, it takes 35 years and 11 months, and the total amount paid is approximately $215,458.84.
Here are some things to consider when implementing the calculator:
For dollar values, only display two digits of precision after the decimal point. (You can assume that the banke will not round internally).
The final payment will almost certainly be smaller than the others, so be careful to check for that case so you don’t end up with a negative balance.
If the monthly payment is too small, the balance will go up every month! If this happens, the program should stop and display an appropriate error message.
If you accidentally create an infinite loop, try to interrupt or restart the kernel.
Use the modulus % operator to separate the years and months.
Your program should only display the columns requested, and the rows should be formatted to appear under the appropriate heading.
Here is the code I have so far:
My Mortgage Amortization Table
I need each value in the Interest and Balance columns to decrease rather than have the same values and this is what I need help with.
Any support here from you gurus would be MUCH appreciated.
Thank you all.
Here is the exact description of the problem:
In this problem, you will create a mortgage calculator that takes as input the principal loan amount, interest rate, and monthly payment. As output, your calculator should generate an amortization table, and compute how many years and months it took to pay off the mortgage, and report the total amount of payments over that time.
In a mortgage, the bank lends you a certain amount of principal to purchase a house at a certain interest rate. Every month, the amount you owe (the balance) first increases due to interest: 1/12 of the interest rate times the current balance. Then the balance decreases due to your monthly payment. For example, suppose you borrow $100,000 at 5% annual interest, with $500 monthly payments. In the first month, the interest increases the balance by $416.67, and then your payment reduces it by $500, for a remaining balance of $99,916.67. In the second month, the interest charge is $416.32, and the remaining balance is $99,832.99.
If you continue this process, you get an amortization table like this:
Expected Mortgage Amortization Table Outcome
You can also compute the total amount of time and money to pay off the mortgage. In this example, it takes 35 years and 11 months, and the total amount paid is approximately $215,458.84.
Here are some things to consider when implementing the calculator:
For dollar values, only display two digits of precision after the decimal point. (You can assume that the banke will not round internally).
The final payment will almost certainly be smaller than the others, so be careful to check for that case so you don’t end up with a negative balance.
If the monthly payment is too small, the balance will go up every month! If this happens, the program should stop and display an appropriate error message.
If you accidentally create an infinite loop, try to interrupt or restart the kernel.
Use the modulus % operator to separate the years and months.
Your program should only display the columns requested, and the rows should be formatted to appear under the appropriate heading.
Here is the code I have so far:
loanamount = 100000 interestrate = 5 monthlypayment = 500 monthlyinterest = round((loanamount * interestrate/100/12),2) monthlybalance = float(loanamount - (monthlypayment - monthlyinterest)) print ("Month", "\t\t", "Payment", "\t\t", "Interest", "\t\t\t", "Balance") print ("-----", "\t\t", "-------", "\t\t", "--------", "\t\t\t", "-------") month = 0 while monthlybalance > 0 : month += 1 ##### This is where I am completely stuck and I think I need a “for” loop in here, but this is where I am LOST ##### print (month, "\t\t", monthlypayment, "\t\t\t", interest, "\t\t\t", balance)Here is the Mortgage Amortization Table that is being created using my existing code above, but obviously this looks nothing like the Mortgage Amortization Table above for rows 2 and on:
My Mortgage Amortization Table
I need each value in the Interest and Balance columns to decrease rather than have the same values and this is what I need help with.
Any support here from you gurus would be MUCH appreciated.
Thank you all.