summaryrefslogtreecommitdiff
path: root/finance/flow.py
diff options
context:
space:
mode:
Diffstat (limited to 'finance/flow.py')
-rw-r--r--finance/flow.py22
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)