Skip to content

Commit df4838f

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 639344e commit df4838f

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

financial/amortization.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ def level_payment(principal, annual_rate_pct, years, payments_per_year=12):
1111
return principal * (r * factor) / (factor - 1)
1212

1313

14-
def amortization_schedule(principal, annual_rate_pct, years, payments_per_year=12, print_annual_summary=False, eps=1e-9):
14+
def amortization_schedule(
15+
principal,
16+
annual_rate_pct,
17+
years,
18+
payments_per_year=12,
19+
print_annual_summary=False,
20+
eps=1e-9,
21+
):
1522
pmt = level_payment(principal, annual_rate_pct, years, payments_per_year)
1623
r = (annual_rate_pct / 100.0) / payments_per_year
1724
n = years * payments_per_year
@@ -20,7 +27,9 @@ def amortization_schedule(principal, annual_rate_pct, years, payments_per_year=1
2027
schedule = []
2128

2229
if print_annual_summary:
23-
print(f"{'Year':<6}{'Months Pd':<12}{'Tenure Left':<13}{'Payment/Period':<16}{'Outstanding':<14}")
30+
print(
31+
f"{'Year':<6}{'Months Pd':<12}{'Tenure Left':<13}{'Payment/Period':<16}{'Outstanding':<14}"
32+
)
2433

2534
for period in range(1, n + 1):
2635
interest = balance * r
@@ -33,7 +42,9 @@ def amortization_schedule(principal, annual_rate_pct, years, payments_per_year=1
3342
else:
3443
payment_made = pmt
3544

36-
if principal_component < 0 and principal_component > -eps: # clamp tiny negatives
45+
if (
46+
principal_component < 0 and principal_component > -eps
47+
): # clamp tiny negatives
3748
principal_component = 0.0
3849

3950
balance = max(0.0, balance - principal_component)
@@ -44,7 +55,9 @@ def amortization_schedule(principal, annual_rate_pct, years, payments_per_year=1
4455

4556
if print_annual_summary and (months_elapsed % 12 == 0 or balance <= eps):
4657
tenure_left_periods = n - period
47-
print(f"{months_elapsed // 12:<6}{months_elapsed:<12}{tenure_left_periods:<13}{pmt:<16.2f}{balance:<14.2f}")
58+
print(
59+
f"{months_elapsed // 12:<6}{months_elapsed:<12}{tenure_left_periods:<13}{pmt:<16.2f}{balance:<14.2f}"
60+
)
4861

4962
if balance <= eps:
5063
break
@@ -56,5 +69,7 @@ def amortization_schedule(principal, annual_rate_pct, years, payments_per_year=1
5669
return round(pmt, 4), schedule
5770

5871

59-
pmt, sched = amortization_schedule(10000, 5.5, 15, payments_per_year=12, print_annual_summary=True)
60-
print(pmt)
72+
pmt, sched = amortization_schedule(
73+
10000, 5.5, 15, payments_per_year=12, print_annual_summary=True
74+
)
75+
print(pmt)

0 commit comments

Comments
 (0)