Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Calculate EMI for given Principal, Interest, Tenure
- Author: T K Sourab<sourabhtk37@gmail.com>
- """
- # todo: implement extra payments
- class EmiCalc:
- """ Implements Equated Monthly Instalment (EMI)
- """
- def __init__(self, principal_amt, interest_rt, tenure_period):
- self.principal_amt = principal_amt
- self.interest_rt = interest_rt / (12 * 100) # monthly interest
- self.tenure_period = tenure_period
- @property
- def monthly_emi(self):
- """Returns monthly EMI amount to be paid
- EMI = (p * r * pow(1 + r, t)) / (pow(1 + r, t) - 1)
- """
- return (
- self.principal_amt * self.interest_rt * pow(1 + self.interest_rt,
- self.tenure_period)) / (pow(1 + self.interest_rt,
- self.tenure_period) - 1)
- def print_monthly_breakdown(self):
- """Provides breakdown of monthly interest, principal,EMI,
- opening and closing balance.
- """
- begin_bal = self.principal_amt
- end_bal = 0
- monthly_interest = 0
- monthly_principal = 0
- print("Month \t Beginning Balance \t EMI \t\t Interest Amount"
- " \t Principal Amount \t Ending Balance")
- for month in range(1, self.tenure_period + 1):
- monthly_interest = self.interest_rt * begin_bal
- monthly_principal = self.monthly_emi - monthly_interest
- end_bal = begin_bal - monthly_principal
- # todo: seperate function/class for formatter
- format_tuple = (month, begin_bal,
- self.monthly_emi,
- monthly_interest,
- monthly_principal,
- abs(end_bal))
- formatted_out = """{0} \t {1:.3f} \t\t {2:.3f} \t {3:.3f} \t\t {4:.3f} \t\t {5:.3f}
- """.format(*format_tuple)
- print(formatted_out)
- begin_bal = end_bal # next month opening balance updation
- if __name__ == '__main__':
- loan_user = EmiCalc(25000, 10, 4)
- print("The monthly EMI to be paid is %s" % loan_user.monthly_emi)
- loan_user.print_monthly_breakdown()
Add Comment
Please, Sign In to add comment