Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extra_principle_payments for monthly_payment_schedule #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 22 additions & 7 deletions mortgage.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,37 @@ def total_value(self, m_payment):
def annual_payment(self):
return self.monthly_payment() * MONTHS_IN_YEAR

def total_payout(self):
return self.monthly_payment() * self.loan_months()

def monthly_payment_schedule(self):
def total_payout(self, extra_principle_payments=[]):
if extra_principle_payments == []:
# should use sum([sum(m) for m in monthly_payments]) but i m too lazy
return self.monthly_payment() * self.loan_months()
else:
monthly_payments = list(self.monthly_payment_schedule(extra_principle_payments=extra_principle_payments))
return sum([sum(m) for m in monthly_payments])

def monthly_payment_schedule(self, extra_principle_payments=[]):
monthly = self.monthly_payment()
balance = dollar(self.amount())
rate = decimal.Decimal(str(self.rate())).quantize(decimal.Decimal('.000001'))
epps = [dollar(e) for e in extra_principle_payments]
while True:
try:
extra_principle = epps.pop(0)
except IndexError as e:
extra_principle = dollar(0)

interest_unrounded = balance * rate * decimal.Decimal(1)/MONTHS_IN_YEAR
interest = dollar(interest_unrounded, round=decimal.ROUND_HALF_UP)

if monthly >= balance + interest:
yield balance, interest
# should add warning
# reset the extra_principle = 0 since there is no point to pay
yield balance, interest, extra_principle
break

principle = monthly - interest
yield principle, interest
balance -= principle
yield principle, interest, extra_principle
balance = balance - principle - extra_principle

def print_summary(m):
print('{0:>25s}: {1:>12.6f}'.format('Rate', m.rate()))
Expand Down