fix: correct hedge equity math at downside scenarios

This commit is contained in:
Bu5hm4nn
2026-03-24 19:31:13 +01:00
parent ff4e565ee6
commit 98ecfb735e
4 changed files with 57 additions and 19 deletions

View File

@@ -35,19 +35,20 @@ def _waterfall_options(metrics: dict) -> dict:
steps = metrics["waterfall_steps"]
running = 0.0
base: list[float] = []
values: list[float] = []
for index, (_, amount) in enumerate(steps):
values: list[dict[str, object]] = []
for index, (label, amount) in enumerate(steps):
if index == 0:
base.append(0)
values.append(amount)
running = amount
elif index == len(steps) - 1:
base.append(0)
values.append(amount)
else:
base.append(running)
values.append(amount)
running += amount
color = "#0ea5e9" if label == "Net equity" else ("#22c55e" if amount >= 0 else "#ef4444")
values.append({"value": amount, "itemStyle": {"color": color}})
return {
"tooltip": {"trigger": "axis", "axisPointer": {"type": "shadow"}},
"xAxis": {"type": "category", "data": [label for label, _ in steps]},
@@ -58,14 +59,12 @@ def _waterfall_options(metrics: dict) -> dict:
"stack": "total",
"data": base,
"itemStyle": {"color": "rgba(0,0,0,0)"},
"tooltip": {"show": False},
},
{
"type": "bar",
"stack": "total",
"data": values,
"itemStyle": {
"color": "#22c55e",
},
},
],
}