From be4e3fef8a205dbb1b97de067e183456800b1c37 Mon Sep 17 00:00:00 2001 From: crackCodeLogn Date: Mon, 5 Aug 2019 09:53:28 +0530 Subject: [PATCH] Changing the month wise calc to day-wise calc --- Deposit.py | 52 ++++++++++++++++++++++++++++++++---------------- core/DayRow.py | 37 ++++++++++++++++++++++++++++++++++ core/MonthRow.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 17 deletions(-) create mode 100644 core/DayRow.py create mode 100644 core/MonthRow.py diff --git a/Deposit.py b/Deposit.py index 1bbd306..4e2b592 100644 --- a/Deposit.py +++ b/Deposit.py @@ -2,7 +2,10 @@ # @version 1.0 # @since 27-07-2019 # The entry point! +from datetime import datetime +from datetime import timedelta +from core.DayRow import Row as day from core.DepositRow import Row from html.HtmlGenerator import HtmlGenerator @@ -11,9 +14,10 @@ class DepositInterestCalc: - def __init__(self, monthly_installment, roi_annual, months): + def __init__(self, monthly_installment, roi_annual, start_date, months): self.monthly_inst = monthly_installment self.roi = roi_annual / 100.0 + self.start_date = start_date self.months = months self.compounding_freq = 4 @@ -51,33 +55,47 @@ def trigger_rd_calc(self): def trigger_fd_calc(self): constant_part = (1 + self.roi / self.compounding_freq) - fd_list = [] - start_date = '01-01-2019' + fd_days_list = [] + date = datetime.strptime(self.start_date, '%d-%m-%Y') for month in range(1, self.months + 1, 1): - fd_list.append(Row(self.monthly_inst, - self.roi, - start_date, - constant_part, - month, - month / 3, # the number of quarters completed - True)) + fd_days_list.append(day(self.monthly_inst, + self.roi, + date, + constant_part, + month, + True)) + date = date + timedelta(days=1) + + fd_month_wise_day_list = {} + for entry in fd_days_list: + fd_month_wise_day_list[entry.marker] = entry + + for entry in fd_month_wise_day_list: + month_start_date = '' + marker = fd_month_wise_day_list[entry].marker + for inner in fd_days_list: + if inner.marker == marker: + month_start_date = inner.date_display + break + fd_month_wise_day_list[entry].date_display = month_start_date + print(fd_month_wise_day_list[entry]) total_interest = 0.0 maturity = 0.0 - for fd in fd_list: - print(fd) + for fd in fd_days_list: + # print(fd) total_interest = fd.get_interest_earned() maturity = fd.get_amount_accumulated() total_interest = round(total_interest, 2) maturity = round(maturity, 2) - HtmlGenerator("FD_" + str(self.monthly_inst)).generate_html(self.headers, fd_list, self.monthly_inst, - total_interest, maturity) + # HtmlGenerator("FD_" + str(self.monthly_inst)).generate_html(self.headers, fd_list, self.monthly_inst, + # total_interest, maturity) if __name__ == '__main__': - rd = DepositInterestCalc(60000, 7.25, 12) - rd.trigger_rd_calc() + # rd = DepositInterestCalc(60000, 7.25, 12) + # rd.trigger_rd_calc() - fd = DepositInterestCalc(150000, 7.25, 22) + fd = DepositInterestCalc(150000, 7.25, '05-08-2019', 31) fd.trigger_fd_calc() diff --git a/core/DayRow.py b/core/DayRow.py new file mode 100644 index 0000000..8a57b15 --- /dev/null +++ b/core/DayRow.py @@ -0,0 +1,37 @@ +# @author Vivek +# @version 1.0 +# @since 05-08-2019 + + +class Row: + def __init__(self, base, roi, date, constant, days_completed, hide_base_if_month_more_1): + self.base = base + self.roi = roi + self.date_display = date.strftime('%d-%m-%Y') # 'dd-MM-yyyy' format + self.constant = constant + self.days_completed = days_completed + self.exponent = 4 * days_completed / 365 + + self.multiplier = pow(constant, self.exponent) + self.amount = base * self.multiplier + self.interest = self.amount - base + + self.marker = date.strftime('%m-%Y') # for grouping + + def get_amount_accumulated(self): + return self.amount + + def get_interest_earned(self): + return self.interest + + def __repr__(self): + return "{days_covered}. {date} {mark} {base} : {roi} : {multiplier} => {int} :: {amount}".format( + days_covered=self.days_completed, + date=self.date_display, + mark=self.marker, + base=self.base, + roi=self.roi, + multiplier=self.multiplier, + int=self.interest, + amount=self.amount + ) diff --git a/core/MonthRow.py b/core/MonthRow.py new file mode 100644 index 0000000..b714cda --- /dev/null +++ b/core/MonthRow.py @@ -0,0 +1,50 @@ +# @author Vivek +# @version 1.0 +# @since 05-08-2019 + +from datetime import datetime + + +class Row: + def __init__(self, base, roi, date, constant, days_completed, hide_base_if_month_more_1): + self.base = base + self.roi = roi + self.date = date # 'dd-MM-yyyy format + self.constant = constant + self.days_completed = days_completed + self.exponent = 4 * days_completed / 365 + + self.multiplier = pow(constant, self.exponent) + self.amount = base * self.multiplier + self.interest = self.amount - base + + dt = datetime.strptime(date, '%d-%m-%Y') + self.marker = dt.strftime('%m-%Y') # for grouping + + self.enrich_values(hide_base_if_month_more_1) + + def enrich_values(self, hide_base_if_month_more_1): + self.base = round(self.base, 2) + if hide_base_if_month_more_1: + if self.days_completed > 1: self.base = "" + + self.roi = round(self.roi * 100, 6) + self.interest = round(self.interest, 2) + self.amount = round(self.amount, 2) + + def get_amount_accumulated(self): + return self.amount + + def get_interest_earned(self): + return self.interest + + def __repr__(self): + return "{days_covered}. {date} {base} : {roi} : {multiplier} => {int} :: {amount}".format( + days_covered=self.days_completed, + date=self.date, + base=self.base, + roi=self.roi, + multiplier=self.multiplier, + int=self.interest, + amount=self.amount + )