# Total Interest over Life of Loan

```
import pandas as pd
import numpy as np
import numpy_financial as npf
```

Calculate the total interest and payment for a $10K loan over 60 months at a 3% annual interest rate.

```
annual_interest_rate = 0.03
monthly_interest_rate = annual_interest_rate / 12
n_periods = 60
periods = np.arange(n_periods) + 1
loan_amount = 10000.
monthly_payment = (npf.pmt(monthly_interest_rate,
n_periods,
loan_amount)
.round(2) * -1 )
interest_per_month = (npf.ipmt(monthly_interest_rate,
periods,
n_periods,
loan_amount)
.round(2) * -1 )
total_interest = interest_per_month.sum()
loan_amount, annual_interest_rate, n_periods, total_interest, monthly_payment
```

```
(10000.0, 0.03, 60, 781.23, 179.69)
```

Now, parametrize and calculate the same for loan amounts from \$10K to \$45K.

```
loans = []
annual_interest_rate = 0.03
monthly_interest_rate = annual_interest_rate / 12
n_periods = 60
periods = np.arange(n_periods) + 1
for loan_amount in np.arange(10000, 46000, 1000):
monthly_payment = (npf.pmt(monthly_interest_rate,
n_periods,
loan_amount)
.round(2) * -1 )
interest_per_month = (npf.ipmt(monthly_interest_rate,
periods,
n_periods,
loan_amount)
.round(2) * -1 )
total_interest = interest_per_month.sum()
loans.append((loan_amount, total_interest, monthly_payment, annual_interest_rate, n_periods))
loans = (pd.DataFrame(loans,
columns=['loan_amount', 'total_interest', 'monthly_payment',
'annual_interest_rate', 'n_periods'])
.set_index('loan_amount'))
loans
```

total_interest | monthly_payment | annual_interest_rate | n_periods | |
---|---|---|---|---|

loan_amount | ||||

10000 | 781.23 | 179.69 | 0.03 | 60 |

11000 | 859.30 | 197.66 | 0.03 | 60 |

12000 | 937.47 | 215.62 | 0.03 | 60 |

13000 | 1015.58 | 233.59 | 0.03 | 60 |

14000 | 1093.72 | 251.56 | 0.03 | 60 |

15000 | 1171.85 | 269.53 | 0.03 | 60 |

16000 | 1249.99 | 287.50 | 0.03 | 60 |

17000 | 1328.02 | 305.47 | 0.03 | 60 |

18000 | 1406.16 | 323.44 | 0.03 | 60 |

19000 | 1484.33 | 341.41 | 0.03 | 60 |

20000 | 1562.46 | 359.37 | 0.03 | 60 |

21000 | 1640.57 | 377.34 | 0.03 | 60 |

22000 | 1718.64 | 395.31 | 0.03 | 60 |

23000 | 1796.80 | 413.28 | 0.03 | 60 |

24000 | 1874.88 | 431.25 | 0.03 | 60 |

25000 | 1952.99 | 449.22 | 0.03 | 60 |

26000 | 2031.19 | 467.19 | 0.03 | 60 |

27000 | 2109.30 | 485.15 | 0.03 | 60 |

28000 | 2187.37 | 503.12 | 0.03 | 60 |

29000 | 2265.57 | 521.09 | 0.03 | 60 |

30000 | 2343.67 | 539.06 | 0.03 | 60 |

31000 | 2421.80 | 557.03 | 0.03 | 60 |

32000 | 2499.85 | 575.00 | 0.03 | 60 |

33000 | 2577.97 | 592.97 | 0.03 | 60 |

34000 | 2656.12 | 610.94 | 0.03 | 60 |

35000 | 2734.26 | 628.90 | 0.03 | 60 |

36000 | 2812.30 | 646.87 | 0.03 | 60 |

37000 | 2890.46 | 664.84 | 0.03 | 60 |

38000 | 2968.65 | 682.81 | 0.03 | 60 |

39000 | 3046.72 | 700.78 | 0.03 | 60 |

40000 | 3124.87 | 718.75 | 0.03 | 60 |

41000 | 3202.99 | 736.72 | 0.03 | 60 |

42000 | 3281.13 | 754.69 | 0.03 | 60 |

43000 | 3359.23 | 772.65 | 0.03 | 60 |

44000 | 3437.38 | 790.62 | 0.03 | 60 |

45000 | 3515.49 | 808.59 | 0.03 | 60 |