fix: correct hedge equity math at downside scenarios
This commit is contained in:
@@ -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",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user