diff options
author | xengineering <me@xengineering.eu> | 2024-09-08 10:02:58 +0200 |
---|---|---|
committer | xengineering <me@xengineering.eu> | 2024-09-08 17:21:32 +0200 |
commit | fb479fcd7a477959157bdeb9543f11c8b9e8870c (patch) | |
tree | 5a6aedfcd7b708ec51e994e4e923d495ef03a006 /finance/flow.py | |
parent | 56219157290495bf58b05a060a2d2afedea735ad (diff) | |
download | finance-py-fb479fcd7a477959157bdeb9543f11c8b9e8870c.tar finance-py-fb479fcd7a477959157bdeb9543f11c8b9e8870c.tar.zst finance-py-fb479fcd7a477959157bdeb9543f11c8b9e8870c.zip |
Implement finance.flow.simulate()
Diffstat (limited to 'finance/flow.py')
-rw-r--r-- | finance/flow.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/finance/flow.py b/finance/flow.py index 9ea72c8..836c137 100644 --- a/finance/flow.py +++ b/finance/flow.py @@ -42,3 +42,25 @@ def monthly_candidates(start: datetime) -> Generator[datetime, None, None]: current = datetime(current.year + 1, 1, 1) else: current = datetime(current.year, current.month + 1, 1) + + +def simulate( + start: datetime, end: datetime, flows: tuple[Flow] +) -> tuple[list[datetime], list[Decimal]]: + dates: list[datetime] = [] + values: list[Decimal] = [] + + for candidate in monthly_candidates(start): + if start <= candidate <= end: + dates.append(candidate) + + if candidate > end: + break + + for date in dates: + value = Decimal(0.0) + for flow in flows: + value += flow.integrate(start, date) + values.append(value) + + return (dates, values) |