summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2024-09-08 12:36:43 +0200
committerxengineering <me@xengineering.eu>2024-09-08 17:21:32 +0200
commit4e8d17c8d0b7d5406d3a9df8c320b5cbabb9d330 (patch)
tree396355130c6b50f5bd1bd41521ab23f3834b690e
parent2560d862d5019db1b103a6e6a9c14dfa66afe78d (diff)
downloadfinance-py-4e8d17c8d0b7d5406d3a9df8c320b5cbabb9d330.tar
finance-py-4e8d17c8d0b7d5406d3a9df8c320b5cbabb9d330.tar.zst
finance-py-4e8d17c8d0b7d5406d3a9df8c320b5cbabb9d330.zip
Add measured values
-rwxr-xr-xdemo13
-rw-r--r--finance/visualize.py19
2 files changed, 26 insertions, 6 deletions
diff --git a/demo b/demo
index 1ab3a18..db48ea7 100755
--- a/demo
+++ b/demo
@@ -16,6 +16,12 @@ DESCRIPTION = "Demo application plotting financial data with finance-py"
def main() -> None:
argparse.ArgumentParser(description=DESCRIPTION).parse_args()
+ 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),
Flow(
@@ -25,13 +31,16 @@ def main() -> None:
),
)
- data = simulate(
+ simulated = simulate(
start=datetime(2024, 1, 1),
end=datetime(2030, 1, 1),
flows=flows,
)
- display(data)
+ display(
+ simulated=simulated,
+ measured=measured,
+ )
if __name__ == "__main__":
diff --git a/finance/visualize.py b/finance/visualize.py
index e6d609a..c7a7c60 100644
--- a/finance/visualize.py
+++ b/finance/visualize.py
@@ -4,13 +4,24 @@ from decimal import Decimal
import matplotlib.pyplot
-def display(data: tuple[list[datetime], list[Decimal]]) -> None:
+def display(
+ simulated: tuple[list[datetime], list[Decimal]],
+ measured: list[tuple[datetime, Decimal]],
+) -> None:
matplotlib.pyplot.plot(
- list(data[0]), # type: ignore
- [float(i) for i in data[1]],
- label="Money",
+ list(simulated[0]), # type: ignore
+ [float(i) for i in simulated[1]],
+ label="Simulated",
+ )
+ matplotlib.pyplot.plot(
+ [i[0] for i in measured], # type: ignore
+ [float(i[1]) for i in measured],
+ label="Measured",
+ marker="x",
+ linestyle="None",
)
matplotlib.pyplot.xlabel("Time")
+ matplotlib.pyplot.ylabel("Money")
matplotlib.pyplot.legend()
matplotlib.pyplot.xticks(rotation=45)
matplotlib.pyplot.show()