rosacastillo
commited on
Commit
·
773af00
1
Parent(s):
6ca7c50
updating graphs for trades version 1 and version 2
Browse files- app.py +55 -1
- tabs/metrics.py +5 -1
- tabs/trades.py +66 -4
app.py
CHANGED
@@ -15,6 +15,8 @@ from tabs.trades import (
|
|
15 |
plot_trades_per_market_by_week,
|
16 |
plot_winning_trades_by_week,
|
17 |
plot_winning_trades_per_market_by_week,
|
|
|
|
|
18 |
)
|
19 |
|
20 |
from tabs.metrics import (
|
@@ -23,6 +25,8 @@ from tabs.metrics import (
|
|
23 |
plot_trade_details,
|
24 |
plot2_trade_details,
|
25 |
plot_trade_metrics,
|
|
|
|
|
26 |
)
|
27 |
|
28 |
from tabs.tool_win import (
|
@@ -189,7 +193,7 @@ with demo:
|
|
189 |
)
|
190 |
|
191 |
with gr.Tabs():
|
192 |
-
with gr.TabItem("🔥Trades Dashboard"):
|
193 |
with gr.Row():
|
194 |
gr.Markdown("# Trend of weekly trades")
|
195 |
with gr.Row():
|
@@ -250,6 +254,56 @@ with demo:
|
|
250 |
with gr.Row():
|
251 |
trade_details_plot
|
252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
with gr.TabItem("🚀 Tool Winning Dashboard"):
|
254 |
with gr.Row():
|
255 |
gr.Markdown("# All tools winning performance")
|
|
|
15 |
plot_trades_per_market_by_week,
|
16 |
plot_winning_trades_by_week,
|
17 |
plot_winning_trades_per_market_by_week,
|
18 |
+
integrated_plot_trades_per_market_by_week,
|
19 |
+
integrated_plot_winning_trades_per_market_by_week,
|
20 |
)
|
21 |
|
22 |
from tabs.metrics import (
|
|
|
25 |
plot_trade_details,
|
26 |
plot2_trade_details,
|
27 |
plot_trade_metrics,
|
28 |
+
WIDTH,
|
29 |
+
HEIGHT,
|
30 |
)
|
31 |
|
32 |
from tabs.tool_win import (
|
|
|
193 |
)
|
194 |
|
195 |
with gr.Tabs():
|
196 |
+
with gr.TabItem("🔥Trades Dashboard v1"):
|
197 |
with gr.Row():
|
198 |
gr.Markdown("# Trend of weekly trades")
|
199 |
with gr.Row():
|
|
|
254 |
with gr.Row():
|
255 |
trade_details_plot
|
256 |
|
257 |
+
with gr.TabItem("🔥Trades Dashboard v2"):
|
258 |
+
with gr.Row():
|
259 |
+
gr.Markdown("# Trend of weekly trades")
|
260 |
+
with gr.Row():
|
261 |
+
trades_by_week = integrated_plot_trades_per_market_by_week(
|
262 |
+
trades_df=trades_df
|
263 |
+
)
|
264 |
+
|
265 |
+
with gr.Row():
|
266 |
+
gr.Markdown("# Percentage of winning trades per week")
|
267 |
+
with gr.Row():
|
268 |
+
all_wtrades_by_week = integrated_plot_winning_trades_per_market_by_week(
|
269 |
+
trades_df=trades_df
|
270 |
+
)
|
271 |
+
|
272 |
+
with gr.Row():
|
273 |
+
gr.Markdown("# ⚖️ Trading metrics")
|
274 |
+
with gr.Row():
|
275 |
+
trade_details_selector = gr.Dropdown(
|
276 |
+
label="Select a trade metric",
|
277 |
+
choices=metric_choices,
|
278 |
+
value=default_metric,
|
279 |
+
)
|
280 |
+
with gr.Row():
|
281 |
+
trade_details_plot = plot_trade_metrics(
|
282 |
+
metric_name=default_metric,
|
283 |
+
trades_df=trades_df,
|
284 |
+
height=400,
|
285 |
+
width=1400,
|
286 |
+
)
|
287 |
+
|
288 |
+
def update_trade_details(trade_detail):
|
289 |
+
return plot_trade_metrics(
|
290 |
+
metric_name=trade_detail,
|
291 |
+
trades_df=trades_df,
|
292 |
+
height=400,
|
293 |
+
width=1400,
|
294 |
+
)
|
295 |
+
|
296 |
+
trade_details_selector.change(
|
297 |
+
update_trade_details,
|
298 |
+
inputs=trade_details_selector,
|
299 |
+
outputs=trade_details_plot,
|
300 |
+
)
|
301 |
+
|
302 |
+
with gr.Row():
|
303 |
+
trade_details_selector
|
304 |
+
with gr.Row():
|
305 |
+
trade_details_plot
|
306 |
+
|
307 |
with gr.TabItem("🚀 Tool Winning Dashboard"):
|
308 |
with gr.Row():
|
309 |
gr.Markdown("# All tools winning performance")
|
tabs/metrics.py
CHANGED
@@ -153,7 +153,9 @@ def plot2_trade_details(
|
|
153 |
)
|
154 |
|
155 |
|
156 |
-
def plot_trade_metrics(
|
|
|
|
|
157 |
"""Plots the trade metrics."""
|
158 |
|
159 |
if metric_name == "mech calls":
|
@@ -190,6 +192,8 @@ def plot_trade_metrics(metric_name: str, trades_df: pd.DataFrame) -> gr.Plot:
|
|
190 |
legend=dict(yanchor="top", y=0.5),
|
191 |
)
|
192 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
|
|
|
|
193 |
return gr.Plot(
|
194 |
value=fig,
|
195 |
)
|
|
|
153 |
)
|
154 |
|
155 |
|
156 |
+
def plot_trade_metrics(
|
157 |
+
metric_name: str, trades_df: pd.DataFrame, height: int = None, width: int = None
|
158 |
+
) -> gr.Plot:
|
159 |
"""Plots the trade metrics."""
|
160 |
|
161 |
if metric_name == "mech calls":
|
|
|
192 |
legend=dict(yanchor="top", y=0.5),
|
193 |
)
|
194 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
195 |
+
if height is not None:
|
196 |
+
fig.update_layout(width=WIDTH, height=HEIGHT)
|
197 |
return gr.Plot(
|
198 |
value=fig,
|
199 |
)
|
tabs/trades.py
CHANGED
@@ -3,8 +3,8 @@ import pandas as pd
|
|
3 |
import plotly.express as px
|
4 |
|
5 |
|
6 |
-
HEIGHT =
|
7 |
-
WIDTH =
|
8 |
|
9 |
|
10 |
def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
@@ -119,7 +119,6 @@ def plot_trades_per_market_by_week(
|
|
119 |
fig.update_layout(
|
120 |
xaxis_title="Week",
|
121 |
yaxis_title="Weekly nr of trades",
|
122 |
-
# xaxis_type="category",
|
123 |
)
|
124 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
125 |
return gr.Plot(
|
@@ -127,6 +126,70 @@ def plot_trades_per_market_by_week(
|
|
127 |
)
|
128 |
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
131 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
132 |
return gr.BarPlot(
|
@@ -168,7 +231,6 @@ def plot_winning_trades_per_market_by_week(
|
|
168 |
fig.update_layout(
|
169 |
xaxis_title="Week",
|
170 |
yaxis_title="Weekly % of winning trades",
|
171 |
-
# xaxis_type="category",
|
172 |
)
|
173 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
174 |
return gr.Plot(
|
|
|
3 |
import plotly.express as px
|
4 |
|
5 |
|
6 |
+
HEIGHT = 400
|
7 |
+
WIDTH = 1200
|
8 |
|
9 |
|
10 |
def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
|
119 |
fig.update_layout(
|
120 |
xaxis_title="Week",
|
121 |
yaxis_title="Weekly nr of trades",
|
|
|
122 |
)
|
123 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
124 |
return gr.Plot(
|
|
|
126 |
)
|
127 |
|
128 |
|
129 |
+
def integrated_plot_trades_per_market_by_week(trades_df: pd.DataFrame) -> gr.Plot:
|
130 |
+
|
131 |
+
# adding the total
|
132 |
+
trades_all = trades_df.copy(deep=True)
|
133 |
+
trades_all["market_creator"] = "all"
|
134 |
+
|
135 |
+
# merging both dataframes
|
136 |
+
all_filtered_trades = pd.concat([trades_df, trades_all], ignore_index=True)
|
137 |
+
all_filtered_trades = all_filtered_trades.sort_values(
|
138 |
+
by="creation_timestamp", ascending=True
|
139 |
+
)
|
140 |
+
|
141 |
+
trades = get_overall_by_market_trades(all_filtered_trades)
|
142 |
+
fig = px.bar(
|
143 |
+
trades,
|
144 |
+
x="month_year_week",
|
145 |
+
y="trades",
|
146 |
+
color="market_creator",
|
147 |
+
barmode="group",
|
148 |
+
color_discrete_sequence=["goldenrod", "darkgreen", "purple"],
|
149 |
+
)
|
150 |
+
fig.update_layout(
|
151 |
+
xaxis_title="Week",
|
152 |
+
yaxis_title="Weekly nr of trades",
|
153 |
+
legend=dict(yanchor="top", y=0.5),
|
154 |
+
)
|
155 |
+
fig.update_layout(width=WIDTH, height=HEIGHT)
|
156 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
157 |
+
return gr.Plot(value=fig)
|
158 |
+
|
159 |
+
|
160 |
+
def integrated_plot_winning_trades_per_market_by_week(
|
161 |
+
trades_df: pd.DataFrame,
|
162 |
+
) -> gr.Plot:
|
163 |
+
# adding the total
|
164 |
+
trades_all = trades_df.copy(deep=True)
|
165 |
+
trades_all["market_creator"] = "all"
|
166 |
+
|
167 |
+
# merging both dataframes
|
168 |
+
all_filtered_trades = pd.concat([trades_df, trades_all], ignore_index=True)
|
169 |
+
all_filtered_trades = all_filtered_trades.sort_values(
|
170 |
+
by="creation_timestamp", ascending=True
|
171 |
+
)
|
172 |
+
final_df = get_overall_winning_by_market_trades(all_filtered_trades)
|
173 |
+
fig = px.bar(
|
174 |
+
final_df,
|
175 |
+
x="month_year_week",
|
176 |
+
y="winning_trade",
|
177 |
+
color="market_creator",
|
178 |
+
barmode="group",
|
179 |
+
color_discrete_sequence=["goldenrod", "darkgreen", "purple"],
|
180 |
+
)
|
181 |
+
fig.update_layout(
|
182 |
+
xaxis_title="Week",
|
183 |
+
yaxis_title="Weekly % of winning trades",
|
184 |
+
legend=dict(yanchor="top", y=0.5),
|
185 |
+
)
|
186 |
+
fig.update_layout(width=WIDTH, height=HEIGHT)
|
187 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
188 |
+
return gr.Plot(
|
189 |
+
value=fig,
|
190 |
+
)
|
191 |
+
|
192 |
+
|
193 |
def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
194 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
195 |
return gr.BarPlot(
|
|
|
231 |
fig.update_layout(
|
232 |
xaxis_title="Week",
|
233 |
yaxis_title="Weekly % of winning trades",
|
|
|
234 |
)
|
235 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
236 |
return gr.Plot(
|