diff options
Diffstat (limited to 'finance/income.py')
-rw-r--r-- | finance/income.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/finance/income.py b/finance/income.py index 12d5d4e..94759ff 100644 --- a/finance/income.py +++ b/finance/income.py @@ -1,10 +1,32 @@ import dataclasses +from datetime import datetime @dataclasses.dataclass(kw_only=True, frozen=True) class Income: + """Income models financial income paid on the first day of a month""" amount: float - def integrate(self, delta_t: int) -> float: - return delta_t * self.amount + def integrate(self, start: datetime, end: datetime) -> float: + """Integrate the income from a start to an end date""" + + retval = 0.0 + + current = datetime(start.year, start.month, 1) + + if start == current: + retval += self.amount + + while True: + if current.month == 12: + current = datetime(current.year + 1, 1, 1) + else: + current = datetime(current.year, current.month + 1, 1) + + if current <= end: + retval += self.amount + else: + break + + return retval |