-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Option to set frequency - 🔥 Drop Python 3.7 - ⬆️ Update dependencies * Fix annotations
- Loading branch information
1 parent
eea7a69
commit 7a08162
Showing
10 changed files
with
185 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
def calculate_amortization_amount(principal: float, interest_rate: float, period: int) -> float: | ||
from amortization.enums import PaymentFrequency | ||
|
||
|
||
def calculate_amortization_amount( | ||
principal: float, interest_rate: float, period: int, payment_frequency: PaymentFrequency = PaymentFrequency.MONTHLY | ||
) -> float: | ||
""" | ||
Calculates Amortization Amount per period | ||
>>> calculate_amortization_amount(150000, 0.1, 36) | ||
4840.08 | ||
>>> calculate_amortization_amount(150000, 0.1, 36, PaymentFrequency.SEMIMONTHLY) | ||
4495.63 | ||
:param principal: Principal amount | ||
:param interest_rate: Interest rate per period | ||
:param interest_rate: Interest rate per year | ||
:param period: Total number of period | ||
:param payment_frequency: Payment frequency per year | ||
:return: Amortization amount per period | ||
""" | ||
adjusted_interest = interest_rate / 12 | ||
adjusted_interest = interest_rate / payment_frequency.value | ||
x = (1 + adjusted_interest) ** period | ||
return round(principal * (adjusted_interest * x) / (x - 1), 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from enum import Enum | ||
|
||
|
||
class PaymentFrequency(Enum): | ||
DAILY = 365 | ||
BIWEEKLY = 104 | ||
WEEKLY = 52 | ||
SEMIMONTHLY = 24 | ||
MONTHLY = 12 | ||
QUARTERLY = 4 | ||
SEMIYEARLY = 2 | ||
YEARLY = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
from math import log | ||
|
||
from amortization.enums import PaymentFrequency | ||
|
||
def calculate_amortization_period(principal: float, interest_rate: float, amount: float) -> int: | ||
|
||
def calculate_amortization_period( | ||
principal: float, | ||
interest_rate: float, | ||
amount: float, | ||
payment_frequency: PaymentFrequency = PaymentFrequency.MONTHLY, | ||
) -> int: | ||
""" | ||
Calculates the number of period needed for a given amortization amount | ||
>>> calculate_amortization_period(150000, 0.1, 4840.08) | ||
36 | ||
>>> calculate_amortization_period(150000, 0.1, 4500, PaymentFrequency.WEEKLY) | ||
34 | ||
:param principal: Principal amount | ||
:param interest_rate: Interest rate per period | ||
:param interest_rate: Interest rate per year | ||
:param amount: Amortization amount per period | ||
:param payment_frequency: Payment frequency per year | ||
:return: Total number of period | ||
""" | ||
adjusted_interest = interest_rate / 12 | ||
adjusted_interest = interest_rate / payment_frequency.value | ||
return round(log(amount / (amount - adjusted_interest * principal), 1 + adjusted_interest)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.