From 4b2eb9a8dc1fed5f2dbd3be40a21e30dbf9bb1e2 Mon Sep 17 00:00:00 2001 From: Scott Turro Date: Wed, 2 Mar 2022 15:31:35 -0600 Subject: [PATCH 1/5] Added apr_interest function to financial --- financial/interest.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/financial/interest.py b/financial/interest.py index c69c730457d9..3815f0a2e15d 100644 --- a/financial/interest.py +++ b/financial/interest.py @@ -77,6 +77,43 @@ def compound_interest( ) +def apr_interest( + principal: float, + nominal_annual_percentage_rate: float, + number_of_years: float, +) -> float: + """ + >>> apr_interest(10000.0, 0.05, 3) + 1618.223072263547 + >>> apr_interest(10000.0, 0.05, 1) + 512.6749646744732 + >>> apr_interest(0.5, 0.05, 3) + 0.08091115361317736 + >>> apr_interest(10000.0, 0.06, -4) + Traceback (most recent call last): + ... + ValueError: number_of_years must be > 0 + >>> apr_interest(10000.0, -3.5, 3.0) + Traceback (most recent call last): + ... + ValueError: nominal_annual_percentage_rate must be >= 0 + >>> apr_interest(-5500.0, 0.01, 5) + Traceback (most recent call last): + ... + ValueError: principal must be > 0 + """ + if number_of_years <= 0: + raise ValueError("number_of_years must be > 0") + if nominal_annual_percentage_rate < 0: + raise ValueError("nominal_annual_percentage_rate must be >= 0") + if principal <= 0: + raise ValueError("principal must be > 0") + + return compound_interest(principal, + nominal_annual_percentage_rate/365, + number_of_years*365) + + if __name__ == "__main__": import doctest From 43f8b2dd61a58cad4b6ee4a55d587331f98be01c Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Jun 2023 17:47:42 +0200 Subject: [PATCH 2/5] Update interest.py --- financial/interest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/financial/interest.py b/financial/interest.py index 3815f0a2e15d..44a74e769d6a 100644 --- a/financial/interest.py +++ b/financial/interest.py @@ -115,6 +115,6 @@ def apr_interest( if __name__ == "__main__": - import doctest + import doctest doctest.testmod() From e97bcb459ed81f0a497f373a636b483946d3d5a1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 18 Jun 2023 15:49:10 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- financial/interest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/financial/interest.py b/financial/interest.py index 44a74e769d6a..48ec20b0995f 100644 --- a/financial/interest.py +++ b/financial/interest.py @@ -109,12 +109,12 @@ def apr_interest( if principal <= 0: raise ValueError("principal must be > 0") - return compound_interest(principal, - nominal_annual_percentage_rate/365, - number_of_years*365) + return compound_interest( + principal, nominal_annual_percentage_rate / 365, number_of_years * 365 + ) if __name__ == "__main__": - import doctest + import doctest doctest.testmod() From 66c2b85c9cb3b31ed66aa625b9adaad89bbf2fe0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 18 Jun 2023 23:06:54 +0200 Subject: [PATCH 4/5] Update financial/interest.py --- financial/interest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/financial/interest.py b/financial/interest.py index 48ec20b0995f..d326123ad58c 100644 --- a/financial/interest.py +++ b/financial/interest.py @@ -110,7 +110,7 @@ def apr_interest( raise ValueError("principal must be > 0") return compound_interest( - principal, nominal_annual_percentage_rate / 365, number_of_years * 365 + principal, nominal_annual_percentage_rate / 365, number_of_years * 365.0 ) From 8f26ba8c6e8acb2f5fc005f0e5423a136cf689d1 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Mon, 19 Jun 2023 13:06:37 +0200 Subject: [PATCH 5/5] float --- financial/interest.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/financial/interest.py b/financial/interest.py index d326123ad58c..33d02e27ccb3 100644 --- a/financial/interest.py +++ b/financial/interest.py @@ -4,7 +4,7 @@ def simple_interest( - principal: float, daily_interest_rate: float, days_between_payments: int + principal: float, daily_interest_rate: float, days_between_payments: float ) -> float: """ >>> simple_interest(18000.0, 0.06, 3) @@ -42,7 +42,7 @@ def simple_interest( def compound_interest( principal: float, nominal_annual_interest_rate_percentage: float, - number_of_compounding_periods: int, + number_of_compounding_periods: float, ) -> float: """ >>> compound_interest(10000.0, 0.05, 3) @@ -110,7 +110,7 @@ def apr_interest( raise ValueError("principal must be > 0") return compound_interest( - principal, nominal_annual_percentage_rate / 365, number_of_years * 365.0 + principal, nominal_annual_percentage_rate / 365, number_of_years * 365 )