From b973f33eb31dd3d397ed6a062897cc37434d2a5c Mon Sep 17 00:00:00 2001 From: drupman Date: Tue, 19 Sep 2023 20:49:56 -0300 Subject: [PATCH] (feat) change radar chart: volume vs realized_pnl --- pages/strategy_performance/app.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/pages/strategy_performance/app.py b/pages/strategy_performance/app.py index b23da35..7ddccf8 100644 --- a/pages/strategy_performance/app.py +++ b/pages/strategy_performance/app.py @@ -173,22 +173,27 @@ def intraday_performance(df: pd.DataFrame): return hr_str + suffix df["hour"] = df["timestamp"].dt.hour - profits = df[df["realized_pnl"] >= 0] - losses = df[df["realized_pnl"] < 0] - polar_profits = profits.groupby("hour")["realized_pnl"].sum().reset_index() - polar_losses = losses.groupby("hour")["realized_pnl"].sum().reset_index() - polar_losses["realized_pnl"] = abs(polar_losses["realized_pnl"]) + realized_pnl_per_hour = df.groupby("hour")[["realized_pnl", "quote_volume"]].sum().reset_index() fig = go.Figure() fig.add_trace(go.Barpolar( name="Profits", - r=polar_profits["realized_pnl"], - theta=polar_profits["hour"] * 15, - marker_color=BULLISH_COLOR)) - fig.add_trace(go.Barpolar( - name="Losses", - r=polar_losses["realized_pnl"], - theta=polar_losses["hour"] * 15, - marker_color=BEARISH_COLOR)) + r=realized_pnl_per_hour["quote_volume"], + theta=realized_pnl_per_hour["hour"] * 15, + marker=dict( + color=realized_pnl_per_hour["realized_pnl"], + colorscale="RdYlGn", + cmin=-(abs(realized_pnl_per_hour["realized_pnl"]).max()), + cmid=0.0, + cmax=(abs(realized_pnl_per_hour["realized_pnl"]).max()), + colorbar=dict( + title='Realized PnL', + x=0, + y=-0.5, + xanchor='left', + yanchor='bottom', + orientation='h' + ) + ))) fig.update_layout( polar=dict( radialaxis=dict(