Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 35 additions & 17 deletions Deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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()
37 changes: 37 additions & 0 deletions core/DayRow.py
Original file line number Diff line number Diff line change
@@ -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
)
50 changes: 50 additions & 0 deletions core/MonthRow.py
Original file line number Diff line number Diff line change
@@ -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
)