From 1a12e7203c0fb406539820ba169238d4783437e3 Mon Sep 17 00:00:00 2001 From: drupman Date: Tue, 19 Sep 2023 22:55:52 -0300 Subject: [PATCH] (feat) isolate candles_graph and panel metrics --- pages/strategy_performance/app.py | 43 +++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/pages/strategy_performance/app.py b/pages/strategy_performance/app.py index 912a917c..a74f73e5 100644 --- a/pages/strategy_performance/app.py +++ b/pages/strategy_performance/app.py @@ -261,6 +261,15 @@ def returns_histogram(df: pd.DataFrame): return fig +def candles_graph(candles: pd.DataFrame, strat_data, show_volume=False, extra_rows=2): + cg = CandlesGraph(candles, show_volume=show_volume, extra_rows=extra_rows) + cg.add_buy_trades(strat_data.buys) + cg.add_sell_trades(strat_data.sells) + cg.add_pnl(strategy_data, row=2) + cg.add_quote_inventory_change(strat_data, row=3) + return cg.figure() + + style_metric_cards() st.subheader("🔫 Data source") with st.expander("⬆️ Upload"): @@ -344,12 +353,15 @@ def returns_histogram(df: pd.DataFrame): st.subheader("💱 Market activity") if "Error" not in selected_db.status["market_data"] and strategy_data_filtered.market_data is not None: - col1, col2, col3 = st.columns([1, 1, 2]) + col1, col2, col3, col4 = st.columns(4) with col1: interval = st.selectbox("Candles Interval:", intervals.keys(), index=2) with col2: rows_per_page = st.number_input("Candles per Page", value=1500, min_value=1, max_value=5000) with col3: + st.markdown("##") + show_panel_metrics = st.checkbox("Show panel metrics", value=True) + with col4: total_rows = len( strategy_data_filtered.get_market_data_resampled(interval=f"{intervals[interval]}S")) total_pages = math.ceil(total_rows / rows_per_page) @@ -367,18 +379,23 @@ def returns_histogram(df: pd.DataFrame): end_time_page = candles_df.index.max() page_data_filtered = single_market_strategy_data.get_filtered_strategy_data(start_time_page, end_time_page) - col1, col2 = st.columns([5.5, 1.5]) - with col1: - cg = CandlesGraph(candles_df, show_volume=False, extra_rows=2) - cg.add_buy_trades(page_data_filtered.buys) - cg.add_sell_trades(page_data_filtered.sells) - cg.add_pnl(page_data_filtered, row=2) - cg.add_quote_inventory_change(page_data_filtered, row=3) - fig = cg.figure() - st.plotly_chart(fig, use_container_width=True) - with col2: - st.plotly_chart(intraday_performance(page_data_filtered.trade_fill), use_container_width=True) - st.plotly_chart(returns_histogram(page_data_filtered.trade_fill), use_container_width=True) + if show_panel_metrics: + col1, col2 = st.columns([2, 1]) + with col1: + candles_chart = candles_graph(candles_df, page_data_filtered) + st.plotly_chart(candles_chart, use_container_width=True) + with col2: + chart_tab, table_tab = st.tabs(["Chart", "Table"]) + with chart_tab: + st.plotly_chart(intraday_performance(page_data_filtered.trade_fill), use_container_width=True) + st.plotly_chart(returns_histogram(page_data_filtered.trade_fill), use_container_width=True) + with table_tab: + st.dataframe(page_data_filtered.trade_fill[["timestamp", "realized_pnl"]].dropna(subset="realized_pnl"), + use_container_width=True, + hide_index=True, + height=candles_chart.layout.height - 180) + else: + st.plotly_chart(candles_graph(candles_df, page_data_filtered), use_container_width=True) else: st.warning("Market data is not available so the candles graph is not going to be rendered. " "Make sure that you are using the latest version of Hummingbot and market data recorder activated.")