rosacastillo
commited on
Commit
·
53ce693
1
Parent(s):
1f8286c
updating graphs of trades tab
Browse files- app.py +34 -23
- tabs/trades.py +49 -49
app.py
CHANGED
@@ -12,9 +12,9 @@ from tabs.trades import (
|
|
12 |
get_overall_winning_trades,
|
13 |
get_overall_winning_by_market_trades,
|
14 |
plot_trades_by_week,
|
15 |
-
|
16 |
plot_winning_trades_by_week,
|
17 |
-
|
18 |
plot_trade_details,
|
19 |
)
|
20 |
from tabs.tool_win import (
|
@@ -172,7 +172,8 @@ winning_rate_df = get_tool_winning_rate(tools_df=tools_df, inc_tools=INC_TOOLS)
|
|
172 |
winning_rate_overall_df = get_overall_winning_rate(wins_df=winning_rate_df)
|
173 |
trades_count_df = get_overall_trades(trades_df=trades_df)
|
174 |
trades_winning_rate_df = get_overall_winning_trades(trades_df=trades_df)
|
175 |
-
|
|
|
176 |
with demo:
|
177 |
gr.HTML("<h1>Olas Predict Actual Performance</h1>")
|
178 |
gr.Markdown(
|
@@ -182,17 +183,40 @@ with demo:
|
|
182 |
with gr.Tabs():
|
183 |
with gr.TabItem("🔥Trades Dashboard"):
|
184 |
with gr.Row():
|
185 |
-
gr.Markdown("#
|
186 |
with gr.Row():
|
187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
with gr.Row():
|
189 |
gr.Markdown("# Percentage of winning trades per week")
|
190 |
with gr.Row():
|
191 |
-
|
192 |
-
|
193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
with gr.Row():
|
195 |
-
gr.Markdown("# Trading metrics")
|
196 |
with gr.Row():
|
197 |
trade_details_selector = gr.Dropdown(
|
198 |
label="Select a trade metric",
|
@@ -225,20 +249,7 @@ with demo:
|
|
225 |
trade_details_selector
|
226 |
with gr.Row():
|
227 |
trade_details_plot
|
228 |
-
|
229 |
-
with gr.Row():
|
230 |
-
gr.Markdown("# Number of trades split by market type per week")
|
231 |
-
with gr.Row():
|
232 |
-
trades_by_week_plot = plot_trades_per_market_by_week2(
|
233 |
-
trades_df=get_overall_by_market_trades(trades_df=trades_df)
|
234 |
-
)
|
235 |
-
with gr.Row():
|
236 |
-
gr.Markdown("# Percentage of winning trades per week")
|
237 |
-
with gr.Row():
|
238 |
-
winning_trades_by_week_plot = plot_winning_trades_per_market_by_week2(
|
239 |
-
trades_df=get_overall_winning_by_market_trades(trades_df=trades_df)
|
240 |
-
)
|
241 |
-
# TODO add average ROI value per market
|
242 |
with gr.TabItem("🚀 Tool Winning Dashboard"):
|
243 |
with gr.Row():
|
244 |
gr.Markdown("# All tools winning performance")
|
|
|
12 |
get_overall_winning_trades,
|
13 |
get_overall_winning_by_market_trades,
|
14 |
plot_trades_by_week,
|
15 |
+
plot_trades_per_market_by_week,
|
16 |
plot_winning_trades_by_week,
|
17 |
+
plot_winning_trades_per_market_by_week,
|
18 |
plot_trade_details,
|
19 |
)
|
20 |
from tabs.tool_win import (
|
|
|
172 |
winning_rate_overall_df = get_overall_winning_rate(wins_df=winning_rate_df)
|
173 |
trades_count_df = get_overall_trades(trades_df=trades_df)
|
174 |
trades_winning_rate_df = get_overall_winning_trades(trades_df=trades_df)
|
175 |
+
trades_by_market = get_overall_by_market_trades(trades_df=trades_df)
|
176 |
+
winning_trades_by_market = get_overall_winning_by_market_trades(trades_df=trades_df)
|
177 |
with demo:
|
178 |
gr.HTML("<h1>Olas Predict Actual Performance</h1>")
|
179 |
gr.Markdown(
|
|
|
183 |
with gr.Tabs():
|
184 |
with gr.TabItem("🔥Trades Dashboard"):
|
185 |
with gr.Row():
|
186 |
+
gr.Markdown("# Trend of weekly trades")
|
187 |
with gr.Row():
|
188 |
+
with gr.Column(min_width=350):
|
189 |
+
qs_trades_by_week = plot_trades_per_market_by_week(
|
190 |
+
trades_df=trades_by_market, market_type="quickstart"
|
191 |
+
)
|
192 |
+
with gr.Column(min_width=350):
|
193 |
+
pearl_trades_by_week = plot_trades_per_market_by_week(
|
194 |
+
trades_df=trades_by_market, market_type="pearl"
|
195 |
+
)
|
196 |
+
with gr.Column(min_width=350):
|
197 |
+
all_trades_by_week = plot_trades_per_market_by_week(
|
198 |
+
trades_df=trades_by_market, market_type="all"
|
199 |
+
)
|
200 |
+
|
201 |
with gr.Row():
|
202 |
gr.Markdown("# Percentage of winning trades per week")
|
203 |
with gr.Row():
|
204 |
+
with gr.Column(min_width=350):
|
205 |
+
qs_wtrades_by_week = plot_winning_trades_per_market_by_week(
|
206 |
+
trades_df=winning_trades_by_market, market_type="quickstart"
|
207 |
+
)
|
208 |
+
with gr.Column(min_width=350):
|
209 |
+
# gr.Markdown("# From Pearl market creator")
|
210 |
+
pearl_wtrades_by_week = plot_winning_trades_per_market_by_week(
|
211 |
+
trades_df=winning_trades_by_market, market_type="pearl"
|
212 |
+
)
|
213 |
+
with gr.Column(min_width=350):
|
214 |
+
all_wtrades_by_week = plot_winning_trades_per_market_by_week(
|
215 |
+
trades_df=trades_winning_rate_df, market_type="all"
|
216 |
+
)
|
217 |
+
|
218 |
with gr.Row():
|
219 |
+
gr.Markdown("# ⚖️ Trading metrics")
|
220 |
with gr.Row():
|
221 |
trade_details_selector = gr.Dropdown(
|
222 |
label="Select a trade metric",
|
|
|
249 |
trade_details_selector
|
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")
|
tabs/trades.py
CHANGED
@@ -17,14 +17,14 @@ def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
17 |
trades_df["creation_timestamp"].dt.to_period("M").astype(str)
|
18 |
)
|
19 |
trades_df["month_year_week"] = (
|
20 |
-
trades_df["creation_timestamp"].dt.to_period("W").
|
21 |
)
|
22 |
trades_df["winning_trade"] = trades_df["winning_trade"].astype(int)
|
23 |
return trades_df
|
24 |
|
25 |
|
26 |
def get_overall_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
27 |
-
"""Gets the overall trades data
|
28 |
trades_count = trades_df.groupby("month_year_week").size().reset_index()
|
29 |
trades_count.columns = trades_count.columns.astype(str)
|
30 |
trades_count.rename(columns={"0": "trades"}, inplace=True)
|
@@ -32,7 +32,7 @@ def get_overall_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
32 |
|
33 |
|
34 |
def get_overall_by_market_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
35 |
-
"""Gets the overall trades data
|
36 |
trades_count = (
|
37 |
trades_df.groupby(["market_creator", "month_year_week"]).size().reset_index()
|
38 |
)
|
@@ -68,6 +68,7 @@ def get_overall_winning_by_market_trades(trades_df: pd.DataFrame) -> pd.DataFram
|
|
68 |
winning_trades = winning_trades.reset_index()
|
69 |
winning_trades.columns = winning_trades.columns.astype(str)
|
70 |
winning_trades.columns = ["market_creator", "month_year_week", "winning_trade"]
|
|
|
71 |
return winning_trades
|
72 |
|
73 |
|
@@ -281,36 +282,35 @@ def plot_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
|
281 |
)
|
282 |
|
283 |
|
284 |
-
def plot_trades_per_market_by_week(
|
|
|
|
|
285 |
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
286 |
assert "market_creator" in trades_df.columns
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
)
|
299 |
-
|
300 |
|
301 |
-
def plot_trades_per_market_by_week2(trades_df: pd.DataFrame) -> gr.Plot:
|
302 |
-
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
303 |
-
assert "market_creator" in trades_df.columns
|
304 |
fig = px.bar(
|
305 |
-
|
306 |
x="month_year_week",
|
307 |
y="trades",
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
312 |
)
|
313 |
-
fig.
|
314 |
return gr.Plot(
|
315 |
value=fig,
|
316 |
)
|
@@ -331,35 +331,35 @@ def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
|
331 |
)
|
332 |
|
333 |
|
334 |
-
def plot_winning_trades_per_market_by_week(
|
|
|
|
|
335 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
width=WIDTH,
|
348 |
-
)
|
349 |
|
350 |
-
|
351 |
-
def plot_winning_trades_per_market_by_week2(trades_df: pd.DataFrame) -> gr.BarPlot:
|
352 |
-
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
353 |
fig = px.bar(
|
354 |
-
|
355 |
x="month_year_week",
|
356 |
y="winning_trade",
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
|
|
|
|
|
|
361 |
)
|
362 |
-
fig.
|
363 |
return gr.Plot(
|
364 |
value=fig,
|
365 |
)
|
|
|
17 |
trades_df["creation_timestamp"].dt.to_period("M").astype(str)
|
18 |
)
|
19 |
trades_df["month_year_week"] = (
|
20 |
+
trades_df["creation_timestamp"].dt.to_period("W").dt.strftime("%b-%d")
|
21 |
)
|
22 |
trades_df["winning_trade"] = trades_df["winning_trade"].astype(int)
|
23 |
return trades_df
|
24 |
|
25 |
|
26 |
def get_overall_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
27 |
+
"""Gets the overall trades data"""
|
28 |
trades_count = trades_df.groupby("month_year_week").size().reset_index()
|
29 |
trades_count.columns = trades_count.columns.astype(str)
|
30 |
trades_count.rename(columns={"0": "trades"}, inplace=True)
|
|
|
32 |
|
33 |
|
34 |
def get_overall_by_market_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
35 |
+
"""Gets the overall trades data"""
|
36 |
trades_count = (
|
37 |
trades_df.groupby(["market_creator", "month_year_week"]).size().reset_index()
|
38 |
)
|
|
|
68 |
winning_trades = winning_trades.reset_index()
|
69 |
winning_trades.columns = winning_trades.columns.astype(str)
|
70 |
winning_trades.columns = ["market_creator", "month_year_week", "winning_trade"]
|
71 |
+
print(winning_trades.head())
|
72 |
return winning_trades
|
73 |
|
74 |
|
|
|
282 |
)
|
283 |
|
284 |
|
285 |
+
def plot_trades_per_market_by_week(
|
286 |
+
trades_df: pd.DataFrame, market_type: str
|
287 |
+
) -> gr.Plot:
|
288 |
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
289 |
assert "market_creator" in trades_df.columns
|
290 |
+
# if market_type is "all then no filter is applied"
|
291 |
+
if market_type == "quickstart":
|
292 |
+
trades = trades_df.loc[trades_df["market_creator"] == "quickstart"]
|
293 |
+
color_sequence = ["goldenrod"]
|
294 |
+
|
295 |
+
elif market_type == "pearl":
|
296 |
+
trades = trades_df.loc[trades_df["market_creator"] == "pearl"]
|
297 |
+
color_sequence = ["purple"]
|
298 |
+
else:
|
299 |
+
trades = trades_df
|
300 |
+
color_sequence = ["darkgreen"]
|
|
|
|
|
301 |
|
|
|
|
|
|
|
302 |
fig = px.bar(
|
303 |
+
trades,
|
304 |
x="month_year_week",
|
305 |
y="trades",
|
306 |
+
color_discrete_sequence=color_sequence,
|
307 |
+
title=market_type + " trades",
|
308 |
+
)
|
309 |
+
fig.update_layout(
|
310 |
+
xaxis_title="Week",
|
311 |
+
yaxis_title="Weekly nr of trades",
|
312 |
)
|
313 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
314 |
return gr.Plot(
|
315 |
value=fig,
|
316 |
)
|
|
|
331 |
)
|
332 |
|
333 |
|
334 |
+
def plot_winning_trades_per_market_by_week(
|
335 |
+
trades_df: pd.DataFrame, market_type: str
|
336 |
+
) -> gr.Plot:
|
337 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
338 |
+
# if market_type is "all then no filter is applied"
|
339 |
+
if market_type == "quickstart":
|
340 |
+
trades = trades_df.loc[trades_df["market_creator"] == "quickstart"]
|
341 |
+
color_sequence = ["goldenrod"]
|
342 |
+
|
343 |
+
elif market_type == "pearl":
|
344 |
+
trades = trades_df.loc[trades_df["market_creator"] == "pearl"]
|
345 |
+
color_sequence = ["purple"]
|
346 |
+
else:
|
347 |
+
trades = trades_df
|
348 |
+
color_sequence = ["darkgreen"]
|
|
|
|
|
349 |
|
|
|
|
|
|
|
350 |
fig = px.bar(
|
351 |
+
trades,
|
352 |
x="month_year_week",
|
353 |
y="winning_trade",
|
354 |
+
color_discrete_sequence=color_sequence,
|
355 |
+
title=market_type + " winning trades",
|
356 |
+
)
|
357 |
+
fig.update_layout(
|
358 |
+
xaxis_title="Week",
|
359 |
+
yaxis_title="Weekly % of winning trades",
|
360 |
+
# yaxis_tickformat="%",
|
361 |
)
|
362 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
363 |
return gr.Plot(
|
364 |
value=fig,
|
365 |
)
|