Skip to content

Commit

Permalink
(feat) isolate candles_graph and panel metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasgaudino committed Sep 20, 2023
1 parent 75b9dc7 commit 1a12e72
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions pages/strategy_performance/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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)
Expand All @@ -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.")
Expand Down

0 comments on commit 1a12e72

Please sign in to comment.