summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdemo4
-rw-r--r--finance/flow.py4
-rw-r--r--finance/test_flow.py19
-rw-r--r--finance/visualize.py6
4 files changed, 14 insertions, 19 deletions
diff --git a/demo b/demo
index db48ea7..bb9cb98 100755
--- a/demo
+++ b/demo
@@ -16,11 +16,11 @@ DESCRIPTION = "Demo application plotting financial data with finance-py"
def main() -> None:
argparse.ArgumentParser(description=DESCRIPTION).parse_args()
- measured = (
+ measured = [
(datetime(2024, 1, 1), Decimal(105.0)),
(datetime(2024, 2, 1), Decimal(207.0)),
(datetime(2024, 3, 1), Decimal(334.0)),
- )
+ ]
flows = (
Flow(amount=Decimal(100.0), since=None, until=None),
diff --git a/finance/flow.py b/finance/flow.py
index 4cf68db..c6b28c0 100644
--- a/finance/flow.py
+++ b/finance/flow.py
@@ -46,7 +46,7 @@ def monthly_candidates(start: datetime) -> Generator[datetime, None, None]:
def simulate(
start: datetime, end: datetime, flows: tuple[Flow, ...]
-) -> tuple[list[datetime], list[Decimal]]:
+) -> list[tuple[datetime, Decimal]]:
dates: list[datetime] = []
values: list[Decimal] = []
@@ -63,4 +63,4 @@ def simulate(
value += flow.integrate(start, date)
values.append(value)
- return (dates, values)
+ return [(date, values[index]) for index, date in enumerate(dates)]
diff --git a/finance/test_flow.py b/finance/test_flow.py
index db1b695..91d189b 100644
--- a/finance/test_flow.py
+++ b/finance/test_flow.py
@@ -31,22 +31,17 @@ def test_flow_integration() -> None:
def test_simulate() -> None:
flows = (Flow(amount=Decimal(100.0), since=None, until=None),)
- dates, values = simulate(
+ simulated = simulate(
start=datetime(2024, 1, 1),
end=datetime(2024, 4, 1),
flows=flows,
)
- assert dates == [
- datetime(2024, 1, 1),
- datetime(2024, 2, 1),
- datetime(2024, 3, 1),
- datetime(2024, 4, 1),
+ expected = [
+ (datetime(2024, 1, 1), Decimal(100.0)),
+ (datetime(2024, 2, 1), Decimal(200.0)),
+ (datetime(2024, 3, 1), Decimal(300.0)),
+ (datetime(2024, 4, 1), Decimal(400.0)),
]
- assert values == [
- Decimal(100.0),
- Decimal(200.0),
- Decimal(300.0),
- Decimal(400.0),
- ]
+ assert simulated == expected
diff --git a/finance/visualize.py b/finance/visualize.py
index c7a7c60..66943c7 100644
--- a/finance/visualize.py
+++ b/finance/visualize.py
@@ -5,12 +5,12 @@ import matplotlib.pyplot
def display(
- simulated: tuple[list[datetime], list[Decimal]],
+ simulated: list[tuple[datetime, Decimal]],
measured: list[tuple[datetime, Decimal]],
) -> None:
matplotlib.pyplot.plot(
- list(simulated[0]), # type: ignore
- [float(i) for i in simulated[1]],
+ [i[0] for i in simulated], # type: ignore
+ [float(i[1]) for i in simulated],
label="Simulated",
)
matplotlib.pyplot.plot(