Created
February 21, 2017 20:51
-
-
Save getglad/b3dbd097d539c5b03da81bb164ca69e6 to your computer and use it in GitHub Desktop.
Calculate Floating Rate Amortization Table with optional Balloon Payment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
def amort_table(principal, rate, annual_periods, term, future_value): | |
rate /= 100 | |
per = np.arange(annual_periods * term) + 1 | |
ipmt = np.ipmt(rate=rate/12, per=per, nper=annual_periods * term, pv=principal, fv=-future_value) | |
ppmt = np.ppmt(rate=rate/12, per=per, nper=annual_periods * term, pv=principal, fv=-future_value) | |
# pmt = np.pmt(rate / 12, num_period * term, principal, fv=-future_value) | |
pv_list = [] | |
for payment in per: | |
index = payment - 1 | |
principal = principal + ppmt[index] | |
pv_list.append(principal) | |
return pd.DataFrame({'ppmt': ppmt, 'ipmt': ipmt, 'principal': pv_list}) | |
if __name__ == "__main__": | |
o_principal = 350000 | |
o_rate = 5 | |
o_rate_increase = 0.25 | |
o_term = 5 | |
o_period = 1 | |
o_num_period = 12 | |
o_future_value = 150000 | |
final_amort_table = None | |
for period in np.arange(0, o_term + 1): | |
if period == 0: | |
temp_amort_table = amort_table( | |
principal=o_principal, | |
rate=o_rate, | |
term=o_term, | |
annual_periods=o_period * o_num_period, | |
future_value=o_future_value | |
) | |
final_amort_table = temp_amort_table.ix[0:11] | |
else: | |
o_rate += o_rate_increase | |
temp_amort_table = amort_table( | |
principal=final_amort_table.tail(1)['principal'].values[0], | |
rate=o_rate, | |
term=o_term-period, | |
annual_periods=o_period * o_num_period, | |
future_value=o_future_value | |
) | |
final_amort_table = final_amort_table.append(temp_amort_table.ix[0:11], ignore_index=True) | |
print(final_amort_table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment