Write a python function to generate amortization schedule given initial loan amount, interest rate, annual payments and tenure.


Topic: Write a python function to generate amortization schedule given initial loan amount, interest rate, annual payments and tenure.

Solution

import itertools
def loan_schedule(principal, interest_rate, annual_payment, tenure):
    if(tenure <= 0):
        print("Invalid tenure",tenure)
        raise ValueError
    if(interest_rate > 1 or interest_rate < 0):
        print("Invalid interest rate",interest_rate," Expected between 0 and 1")
        raise ValueError
    cashflows = [principal, *list(itertools.repeat(-annual_payment, tenure))]
    effective_interest_rate = 1+interest_rate
    return [ val for val in list(itertools.accumulate(cashflows, lambda bal, pmt: (bal*effective_interest_rate + pmt))) if val > 0]



List all Python Programs