From acef33ea6c3e8f74add78adae6b0c2a197c2cd61 Mon Sep 17 00:00:00 2001 From: cardosofede Date: Mon, 11 Dec 2023 21:58:51 -0300 Subject: [PATCH] (feat) improve add candles graph --- quants_lab/strategy/strategy_analysis.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/quants_lab/strategy/strategy_analysis.py b/quants_lab/strategy/strategy_analysis.py index c95c8d8..bd4ca0b 100644 --- a/quants_lab/strategy/strategy_analysis.py +++ b/quants_lab/strategy/strategy_analysis.py @@ -23,7 +23,7 @@ class StrategyAnalysis: self.base_figure = make_subplots(rows=rows, cols=1, shared_xaxes=True, vertical_spacing=0.01, row_heights=heights, specs=specs) if candlestick: - self.add_candles_graph() + self.add_candles_graph(row=1, col=1) if volume: self.add_volume() if positions: @@ -81,17 +81,17 @@ class StrategyAnalysis: def figure(self): return self.base_figure - def add_candles_graph(self): + def add_candles_graph(self, row, col, name_suffix='', timeframe_suffix=''): self.base_figure.add_trace( go.Candlestick( - x=self.candles_df["timestamp"], - open=self.candles_df["open"], - high=self.candles_df["high"], - low=self.candles_df["low"], - close=self.candles_df["close"], - name="OHLC" + x=self.candles_df[f"timestamp{timeframe_suffix}"], + open=self.candles_df[f"open{timeframe_suffix}"], + high=self.candles_df[f"high{timeframe_suffix}"], + low=self.candles_df[f"low{timeframe_suffix}"], + close=self.candles_df[f"close{timeframe_suffix}"], + name=f"OHLC_{name_suffix}" ), - row=1, col=1, + row=row, col=col, ) def add_volume(self): @@ -185,7 +185,7 @@ class StrategyAnalysis: return returns.mean() / returns.std() def profit_factor(self): - total_won = self.win_signals().loc[:, "net_pnl_quote"].sum() + total_won = self.win_signals().loc[:, "net_pnl_quote"].sum() total_loss = - self.loss_signals().loc[:, "net_pnl_quote"].sum() return total_won / total_loss @@ -231,4 +231,4 @@ Strategy Performance Report: xaxis_title="N° Position", yaxis=dict(title="Net PnL USD", side="left", showgrid=False), ) - return fig \ No newline at end of file + return fig