cyberosa
commited on
Commit
·
5f0d39e
1
Parent(s):
7839697
new graph about trades volume at the market level
Browse files- app.py +16 -5
- scripts/trades_volume_per_market.py +38 -0
app.py
CHANGED
@@ -21,6 +21,7 @@ from tabs.trader_plots import (
|
|
21 |
)
|
22 |
|
23 |
from scripts.utils import get_traders_family
|
|
|
24 |
from tabs.market_plots import (
|
25 |
plot_kl_div_per_market,
|
26 |
)
|
@@ -76,7 +77,7 @@ def prepare_data():
|
|
76 |
|
77 |
all_trades["creation_date"] = all_trades["creation_timestamp"].dt.date
|
78 |
|
79 |
-
#
|
80 |
volume_trades_per_trader_and_market = (
|
81 |
all_trades.groupby(["trader_address", "title"])["roi"].count().reset_index()
|
82 |
)
|
@@ -89,10 +90,10 @@ def prepare_data():
|
|
89 |
)
|
90 |
|
91 |
# adding the trader family column
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
|
97 |
trader_agents_data = trader_agents_data.sort_values(
|
98 |
by="creation_timestamp", ascending=True
|
@@ -286,6 +287,16 @@ with demo:
|
|
286 |
with gr.Column(scale=1):
|
287 |
interpretation = get_interpretation_text()
|
288 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
289 |
with gr.TabItem("🎖️Weekly winning trades % per trader"):
|
290 |
with gr.Row():
|
291 |
gr.Markdown("# Weekly winning trades percentage from all traders")
|
|
|
21 |
)
|
22 |
|
23 |
from scripts.utils import get_traders_family
|
24 |
+
from scripts.trades_volume_per_market import plot_weekly_trades_volume_by_trader_family
|
25 |
from tabs.market_plots import (
|
26 |
plot_kl_div_per_market,
|
27 |
)
|
|
|
77 |
|
78 |
all_trades["creation_date"] = all_trades["creation_timestamp"].dt.date
|
79 |
|
80 |
+
# nr-trades variable
|
81 |
volume_trades_per_trader_and_market = (
|
82 |
all_trades.groupby(["trader_address", "title"])["roi"].count().reset_index()
|
83 |
)
|
|
|
90 |
)
|
91 |
|
92 |
# adding the trader family column
|
93 |
+
trader_agents_data["trader_family"] = trader_agents_data.apply(
|
94 |
+
lambda x: get_traders_family(x), axis=1
|
95 |
+
)
|
96 |
+
print(trader_agents_data.trader_family.value_counts())
|
97 |
|
98 |
trader_agents_data = trader_agents_data.sort_values(
|
99 |
by="creation_timestamp", ascending=True
|
|
|
287 |
with gr.Column(scale=1):
|
288 |
interpretation = get_interpretation_text()
|
289 |
|
290 |
+
with gr.Row():
|
291 |
+
gr.Markdown(
|
292 |
+
"# Weekly volume of trades at each market per trader family"
|
293 |
+
)
|
294 |
+
|
295 |
+
with gr.Row():
|
296 |
+
trades_volume_plot = plot_weekly_trades_volume_by_trader_family(
|
297 |
+
trader_agents_data
|
298 |
+
)
|
299 |
+
|
300 |
with gr.TabItem("🎖️Weekly winning trades % per trader"):
|
301 |
with gr.Row():
|
302 |
gr.Markdown("# Weekly winning trades percentage from all traders")
|
scripts/trades_volume_per_market.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import gradio as gr
|
3 |
+
import plotly.express as px
|
4 |
+
|
5 |
+
|
6 |
+
def plot_weekly_trades_volume_by_trader_family(
|
7 |
+
trader_agents_data: pd.DataFrame,
|
8 |
+
) -> gr.Plot:
|
9 |
+
"""Function to compute the metrics at the trader level per week
|
10 |
+
and with different categories by market creator"""
|
11 |
+
|
12 |
+
weekly_trades_volume = (
|
13 |
+
trader_agents_data.groupby(
|
14 |
+
["month_year_week", "title", "trader_family"], sort=False
|
15 |
+
)["trader_address"]
|
16 |
+
.size()
|
17 |
+
.reset_index(name="trades")
|
18 |
+
)
|
19 |
+
|
20 |
+
fig = px.box(
|
21 |
+
weekly_trades_volume,
|
22 |
+
x="month_year_week",
|
23 |
+
y="trades",
|
24 |
+
color="trader_family",
|
25 |
+
color_discrete_sequence=["darkviolet", "goldenrod", "gray"],
|
26 |
+
category_orders={
|
27 |
+
"trader_family": ["pearl_agent", "quickstart_agent", "non_agent"]
|
28 |
+
},
|
29 |
+
)
|
30 |
+
|
31 |
+
fig.update_layout(
|
32 |
+
xaxis_title="Week",
|
33 |
+
yaxis_title="Weekly trades volume in each market per trader family type",
|
34 |
+
legend=dict(yanchor="top", y=0.5),
|
35 |
+
)
|
36 |
+
# fig.update_layout(width=WIDTH, height=HEIGHT)
|
37 |
+
fig.update_xaxes(tickformat="%b %d\n%Y")
|
38 |
+
return gr.Plot(value=fig)
|