MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / apr_interest

Function apr_interest

financial/interest.py:80–114  ·  view source on GitHub ↗

>>> 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_y

(
    principal: float,
    nominal_annual_percentage_rate: float,
    number_of_years: float,
)

Source from the content-addressed store, hash-verified

78
79
80def apr_interest(
81 principal: float,
82 nominal_annual_percentage_rate: float,
83 number_of_years: float,
84) -> float:
85 """
86 >>> apr_interest(10000.0, 0.05, 3)
87 1618.223072263547
88 >>> apr_interest(10000.0, 0.05, 1)
89 512.6749646744732
90 >>> apr_interest(0.5, 0.05, 3)
91 0.08091115361317736
92 >>> apr_interest(10000.0, 0.06, -4)
93 Traceback (most recent call last):
94 ...
95 ValueError: number_of_years must be > 0
96 >>> apr_interest(10000.0, -3.5, 3.0)
97 Traceback (most recent call last):
98 ...
99 ValueError: nominal_annual_percentage_rate must be >= 0
100 >>> apr_interest(-5500.0, 0.01, 5)
101 Traceback (most recent call last):
102 ...
103 ValueError: principal must be > 0
104 """
105 if number_of_years <= 0:
106 raise ValueError("number_of_years must be > 0")
107 if nominal_annual_percentage_rate < 0:
108 raise ValueError("nominal_annual_percentage_rate must be >= 0")
109 if principal <= 0:
110 raise ValueError("principal must be > 0")
111
112 return compound_interest(
113 principal, nominal_annual_percentage_rate / 365, number_of_years * 365
114 )
115
116
117if __name__ == "__main__":

Callers

nothing calls this directly

Calls 1

compound_interestFunction · 0.85

Tested by

no test coverage detected