In
[1]:
import pandas as pd
import numpy as np
import numpy_financial as npf
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style="darkgrid")
C:\ProgramData\Anaconda\lib\site-packages\statsmodels\tools\_testing.py:19: FutureWarning: pandas.ut
il.testing is deprecated. Use the functions in the public API at pandas.testing instead.
import pandas.util.testing as tm
In [2]:
def amortization_schedule(int_rate, mortgage_amount, time_years):
Total_amount = -(mortgage_amount) # converts the amount to negative to signify a cash ouflow
Monthly_rate = (int_rate/100)/12
periods = time_years*12
n_per = np.arange(time_years * 12) + 1
Repayment_amount = npf.ipmt(Monthly_rate, n_per, periods, Total_amount)
Principal_amount = npf.ppmt(Monthly_rate, n_per, periods, Total_amount)
# Joining the data
df1 = list(zip(n_per, Repayment_amount, Principal_amount))
df_Loan_Amortization = pd.DataFrame(df1, columns=['Period','Interest','Principal'])
df_Loan_Amortization['Monthly_Payment'] = df_Loan_Amortization['Interest'] + df_Loan_Amortization['Principal'
]
#Cummulative sum of the monthly paymsnts
df_Loan_Amortization['Outstanding_balance'] = df_Loan_Amortization['Monthly_Payment'].cumsum()
# Reversing
df_Loan_Amortization.Outstanding_balance = df_Loan_Amortization.Outstanding_balance.values[::-1]
return(df_Loan_Amortization)
1.1 The 20-Year Fixed Rate Mortgage
In [3]:
Twenty_Yr_Loan = 1000000
Time_Years = 20
Twenty_Year_Fixed_Mortgage = amortization_schedule(2.50, Twenty_Yr_Loan, Time_Years)
In [4]:
Twenty_Year_Fixed_Mortgage
Out[4]:
Period Interest Principal Monthly_Payment Outstanding_balance
0 1 2083.333333 3215.695597 5299.02893 1.271767e+06
1 2 2076.633968 3222.394963 5299.02893 1.266468e+06
2 3 2069.920645 3229.108286 5299.02893 1.261169e+06
3 4 2063.193336 3235.835595 5299.02893 1.255870e+06
4 5 2056.452012 3242.576919 5299.02893 1.250571e+06
... ... ... ... ... ...
235 236 54.854899 5244.174031 5299.02893 2.649514e+04
236 237 43.929537 5255.099394 5299.02893 2.119612e+04
237 238 32.981413 5266.047517 5299.02893 1.589709e+04
238 239 22.010481 5277.018450 5299.02893 1.059806e+04
239 240 11.016692 5288.012238 5299.02893 5.299029e+03
240 rows × 5 columns
In [5]:
Sum_Interest = round(Twenty_Year_Fixed_Mortgage['Interest'].sum(),0)
format (Sum_Interest, ",")
Out[5]:
'271,767.0'
In [6]:
Sum_Principal = round(Twenty_Year_Fixed_Mortgage['Principal'].sum(),0)
format (Sum_Principal, ",")
Out[6]:
'1,000,000.0'
2.2 The 30-Year Fixed Rate Mortgage
In [7]:
Thirty_Yr_Loan = 1000000
Time_Years_2 = 30
Thirty_Year_Fixed_Mortgage = amortization_schedule(4.00, Thirty_Yr_Loan, Time_Years_2)
In [8]:
Thirty_Year_Fixed_Mortgage
Out[8]:
Period Interest Principal Monthly_Payment Outstanding_balance
0 1 3333.333333 1440.819621 4774.152955 1.718695e+06
1 2 3328.530601 1445.622353 4774.152955 1.713921e+06
2 3 3323.711860 1450.441095 4774.152955 1.709147e+06
3 4 3318.877056 1455.275898 4774.152955 1.704373e+06
4 5 3314.026137 1460.126818 4774.152955 1.699598e+06
... ... ... ... ... ...
355 356 78.779671 4695.373283 4774.152955 2.387076e+04
356 357 63.128427 4711.024527 4774.152955 1.909661e+04
357 358 47.425012 4726.727943 4774.152955 1.432246e+04
358 359 31.669252 4742.483702 4774.152955 9.548306e+03
359 360 15.860973 4758.291981 4774.152955 4.774153e+03
360 rows × 5 columns
In [9]:
Sum_Interest2 = round(Thirty_Year_Fixed_Mortgage['Interest'].sum(),0)
format (Sum_Interest2, ",")
Out[9]:
'718,695.0'
In [10]:
Sum_Principal2 = round(Thirty_Year_Fixed_Mortgage['Principal'].sum(),0)
format (Sum_Principal2, ",")
Out[10]:
'1,000,000.0'