Created
December 14, 2023 10:58
-
-
Save gtors/644587cc2d244facd6929adf14be7bda to your computer and use it in GitHub Desktop.
Раcсчет аннуительного платежа
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
def calculate_monthly_payment( | |
*, | |
loan: float | int | str | Decimal, | |
annual_interest_rate: float | str | Decimal, | |
years: int | None = None, | |
months: int | None = None, | |
): | |
""" | |
Calculates the annuity monthly mortgage payment | |
An example of a loan in the amount of 9M at 11% per annum for 15 years: | |
>>> calculate_monthly_payment(loan=9_000_000, annual_interest_rate="0.11", years=15) | |
""" | |
s = Decimal(loan) | |
p = Decimal(annual_interest_rate) | |
n = 12 * years if years else months | |
return s * p / 12 * (1 + p / 12) ** n / ((1 + p / 12) ** n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment