Spaces:
Runtime error
Runtime error
cyberosa
commited on
Commit
Β·
2206479
1
Parent(s):
09ddc82
new tab for agent metrics and update of roi functions for agents
Browse files- app.py +26 -21
- tabs/agent_graphs.py +127 -0
- tabs/daily_graphs.py +0 -72
- tabs/trader_plots.py +0 -98
app.py
CHANGED
|
@@ -26,14 +26,14 @@ from tabs.trader_plots import (
|
|
| 26 |
get_interpretation_text,
|
| 27 |
plot_total_bet_amount,
|
| 28 |
plot_active_traders,
|
| 29 |
-
plot_rolling_average_roi,
|
| 30 |
)
|
|
|
|
|
|
|
| 31 |
from tabs.daily_graphs import (
|
| 32 |
get_current_week_data,
|
| 33 |
plot_daily_metrics,
|
| 34 |
trader_daily_metric_choices,
|
| 35 |
default_daily_metric,
|
| 36 |
-
plot_rolling_average_dune,
|
| 37 |
)
|
| 38 |
from scripts.utils import get_traders_family
|
| 39 |
from tabs.market_plots import (
|
|
@@ -434,13 +434,7 @@ with demo:
|
|
| 434 |
inputs=trader_u_details_selector,
|
| 435 |
outputs=trader_u_markets_plot,
|
| 436 |
)
|
| 437 |
-
|
| 438 |
-
gr.Markdown("# 2-weeks rolling average ROI for Pearl traders")
|
| 439 |
-
with gr.Row():
|
| 440 |
-
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
| 441 |
-
weekly_roi_df=weekly_metrics_by_market_creator,
|
| 442 |
-
market_creator="pearl",
|
| 443 |
-
)
|
| 444 |
with gr.TabItem("π
Daily metrics"):
|
| 445 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
| 446 |
if len(live_trades_current_week) > 0:
|
|
@@ -547,6 +541,29 @@ with demo:
|
|
| 547 |
inputs=[no_trader_live_details_selector, no_trader_live_details_plot],
|
| 548 |
outputs=[no_trader_live_details_plot],
|
| 549 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
with gr.TabItem("πͺ Retention metrics (WIP)"):
|
| 551 |
with gr.Row():
|
| 552 |
gr.Markdown("# Wow retention by trader type")
|
|
@@ -684,18 +701,6 @@ with demo:
|
|
| 684 |
active_traders_plot_qs = plot_active_traders(
|
| 685 |
active_traders, market_creator="quickstart"
|
| 686 |
)
|
| 687 |
-
with gr.Row():
|
| 688 |
-
gr.Markdown(" # Daily active agents in Pearl markets")
|
| 689 |
-
with gr.Row():
|
| 690 |
-
rolling_avg_plot = plot_rolling_average_dune(
|
| 691 |
-
daa_pearl_df,
|
| 692 |
-
)
|
| 693 |
-
with gr.Row():
|
| 694 |
-
gr.Markdown(" # Daily active agents in QS markets")
|
| 695 |
-
with gr.Row():
|
| 696 |
-
rolling_avg_plot = plot_rolling_average_dune(
|
| 697 |
-
daa_qs_df,
|
| 698 |
-
)
|
| 699 |
|
| 700 |
with gr.TabItem("π Markets KullbackβLeibler divergence"):
|
| 701 |
with gr.Row():
|
|
|
|
| 26 |
get_interpretation_text,
|
| 27 |
plot_total_bet_amount,
|
| 28 |
plot_active_traders,
|
|
|
|
| 29 |
)
|
| 30 |
+
from tabs.agent_graphs import plot_rolling_average_dune, plot_rolling_average_roi
|
| 31 |
+
|
| 32 |
from tabs.daily_graphs import (
|
| 33 |
get_current_week_data,
|
| 34 |
plot_daily_metrics,
|
| 35 |
trader_daily_metric_choices,
|
| 36 |
default_daily_metric,
|
|
|
|
| 37 |
)
|
| 38 |
from scripts.utils import get_traders_family
|
| 39 |
from tabs.market_plots import (
|
|
|
|
| 434 |
inputs=trader_u_details_selector,
|
| 435 |
outputs=trader_u_markets_plot,
|
| 436 |
)
|
| 437 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 438 |
with gr.TabItem("π
Daily metrics"):
|
| 439 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
| 440 |
if len(live_trades_current_week) > 0:
|
|
|
|
| 541 |
inputs=[no_trader_live_details_selector, no_trader_live_details_plot],
|
| 542 |
outputs=[no_trader_live_details_plot],
|
| 543 |
)
|
| 544 |
+
with gr.TabItem(" Agent metrics"):
|
| 545 |
+
with gr.Row():
|
| 546 |
+
gr.Markdown(" # Daily active Pearl agents")
|
| 547 |
+
with gr.Row():
|
| 548 |
+
rolling_avg_plot = plot_rolling_average_dune(
|
| 549 |
+
daa_pearl_df,
|
| 550 |
+
)
|
| 551 |
+
with gr.Row():
|
| 552 |
+
gr.Markdown(" # Daily active Quickstart agents")
|
| 553 |
+
with gr.Row():
|
| 554 |
+
rolling_avg_plot = plot_rolling_average_dune(
|
| 555 |
+
daa_qs_df,
|
| 556 |
+
)
|
| 557 |
+
with gr.Row():
|
| 558 |
+
gr.Markdown("# 2-weeks rolling average ROI for Pearl agents")
|
| 559 |
+
with gr.Row():
|
| 560 |
+
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
| 561 |
+
weekly_roi_df=weekly_metrics_by_market_creator,
|
| 562 |
+
market_creator="pearl",
|
| 563 |
+
)
|
| 564 |
+
with gr.Row():
|
| 565 |
+
gr.Markdown("# Average weekly ROI for Pearl agents (WIP)")
|
| 566 |
+
|
| 567 |
with gr.TabItem("πͺ Retention metrics (WIP)"):
|
| 568 |
with gr.Row():
|
| 569 |
gr.Markdown("# Wow retention by trader type")
|
|
|
|
| 701 |
active_traders_plot_qs = plot_active_traders(
|
| 702 |
active_traders, market_creator="quickstart"
|
| 703 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
|
| 705 |
with gr.TabItem("π Markets KullbackβLeibler divergence"):
|
| 706 |
with gr.Row():
|
tabs/agent_graphs.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import gc
|
| 4 |
+
import plotly.express as px
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def plot_rolling_average_dune(
|
| 8 |
+
daa_df: pd.DataFrame,
|
| 9 |
+
) -> gr.Plot:
|
| 10 |
+
"""Function to plot the rolling average of daily active traders"""
|
| 11 |
+
|
| 12 |
+
fig = px.bar(
|
| 13 |
+
daa_df,
|
| 14 |
+
x="tx_date",
|
| 15 |
+
y="seven_day_trailing_avg",
|
| 16 |
+
)
|
| 17 |
+
fig.update_layout(
|
| 18 |
+
xaxis_title="Date",
|
| 19 |
+
yaxis_title="7-day rolling average of DAA",
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return gr.Plot(
|
| 23 |
+
value=fig,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def plot_rolling_average(
|
| 28 |
+
daa_df: pd.DataFrame,
|
| 29 |
+
market_creator: str = None,
|
| 30 |
+
) -> gr.Plot:
|
| 31 |
+
"""Function to plot the rolling average of daily active traders by markets"""
|
| 32 |
+
if market_creator is not None:
|
| 33 |
+
filtered_traders_df = daa_df.loc[daa_df["market_creator"] == market_creator]
|
| 34 |
+
rolling_avg_df = get_sevenday_rolling_average(filtered_traders_df)
|
| 35 |
+
else:
|
| 36 |
+
rolling_avg_df = get_sevenday_rolling_average(daa_df)
|
| 37 |
+
print(rolling_avg_df.head())
|
| 38 |
+
|
| 39 |
+
# Ensure 'creation_date' is a column, not an index
|
| 40 |
+
if "tx_date" not in rolling_avg_df.columns:
|
| 41 |
+
rolling_avg_df = rolling_avg_df.reset_index()
|
| 42 |
+
|
| 43 |
+
fig = px.bar(
|
| 44 |
+
rolling_avg_df,
|
| 45 |
+
x="tx_date",
|
| 46 |
+
y="rolling_avg_traders",
|
| 47 |
+
)
|
| 48 |
+
fig.update_layout(
|
| 49 |
+
xaxis_title="Date",
|
| 50 |
+
yaxis_title="7-day rolling average of DAA",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
return gr.Plot(
|
| 54 |
+
value=fig,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def get_sevenday_rolling_average(daa_df: pd.DataFrame) -> pd.DataFrame:
|
| 59 |
+
"""Function to get the 7-day rolling average of the number of unique
|
| 60 |
+
trader_address"""
|
| 61 |
+
# Create a local copy of the dataframe
|
| 62 |
+
local_df = daa_df.copy()
|
| 63 |
+
|
| 64 |
+
# Sort the dataframe by date
|
| 65 |
+
local_df = local_df.sort_values(by="tx_date").set_index("tx_date")
|
| 66 |
+
|
| 67 |
+
# Group by market_creator and calculate rolling average of unique trader_address
|
| 68 |
+
rolling_avg = (
|
| 69 |
+
local_df.resample("D")["trader_address"]
|
| 70 |
+
.nunique()
|
| 71 |
+
.rolling(window=7)
|
| 72 |
+
.mean()
|
| 73 |
+
.reset_index()
|
| 74 |
+
)
|
| 75 |
+
rolling_avg.rename(columns={"trader_address": "rolling_avg_traders"}, inplace=True)
|
| 76 |
+
return rolling_avg
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def plot_rolling_average_roi(
|
| 80 |
+
weekly_roi_df: pd.DataFrame, daa_pearl_df: pd.DataFrame
|
| 81 |
+
) -> gr.Plot:
|
| 82 |
+
"""Function to plot the rolling average of ROI for pearl agents"""
|
| 83 |
+
# Get the list of unique addresses from the daa_pearl_df
|
| 84 |
+
unique_addresses = daa_pearl_df["trader_address"].unique()
|
| 85 |
+
# Filter the weekly_roi_df to include only those addresses
|
| 86 |
+
filtered_weekly_roi_df = weekly_roi_df[
|
| 87 |
+
weekly_roi_df["trader_address"].isin(unique_addresses)
|
| 88 |
+
]
|
| 89 |
+
# Get the 2-week rolling average of ROI
|
| 90 |
+
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(filtered_weekly_roi_df)
|
| 91 |
+
print(rolling_avg_roi_df.head())
|
| 92 |
+
# Ensure 'month_year_week' is a column, not an index
|
| 93 |
+
if "month_year_week" not in rolling_avg_roi_df.columns:
|
| 94 |
+
rolling_avg_roi_df = rolling_avg_roi_df.reset_index()
|
| 95 |
+
fig = px.bar(
|
| 96 |
+
rolling_avg_roi_df,
|
| 97 |
+
x="month_year_week",
|
| 98 |
+
y="rolling_avg_roi",
|
| 99 |
+
)
|
| 100 |
+
fig.update_layout(
|
| 101 |
+
xaxis_title="Week",
|
| 102 |
+
yaxis_title="2-week rolling average of ROI at the trader level",
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
return gr.Plot(
|
| 106 |
+
value=fig,
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def get_twoweeks_rolling_average_roi(weekly_roi_df: pd.DataFrame) -> pd.DataFrame:
|
| 111 |
+
"""Function to get the 2-week rolling average of the ROI by market_creator and total"""
|
| 112 |
+
# Create a local copy of the dataframe
|
| 113 |
+
local_df = weekly_roi_df.copy()
|
| 114 |
+
|
| 115 |
+
# Convert string dates to datetime
|
| 116 |
+
local_df["month_year_week"] = pd.to_datetime(
|
| 117 |
+
local_df["month_year_week"], format="%b-%d-%Y"
|
| 118 |
+
)
|
| 119 |
+
# Sort the dataframe by date
|
| 120 |
+
local_df = local_df.sort_values(by="month_year_week").set_index("month_year_week")
|
| 121 |
+
|
| 122 |
+
# Group by market_creator and calculate rolling average of unique trader_address
|
| 123 |
+
trader_rolling_avg_roi = (
|
| 124 |
+
local_df.resample("W")["roi"].mean().rolling(window=2).mean().reset_index()
|
| 125 |
+
)
|
| 126 |
+
trader_rolling_avg_roi.rename(columns={"roi": "rolling_avg_roi"}, inplace=True)
|
| 127 |
+
return trader_rolling_avg_roi
|
tabs/daily_graphs.py
CHANGED
|
@@ -229,75 +229,3 @@ def plot_daily_metrics_v2(
|
|
| 229 |
|
| 230 |
# Update y-axes to have the same range
|
| 231 |
fig.update_yaxes(matches="y")
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
def get_sevenday_rolling_average(daa_df: pd.DataFrame) -> pd.DataFrame:
|
| 235 |
-
"""Function to get the 7-day rolling average of the number of unique
|
| 236 |
-
trader_address"""
|
| 237 |
-
# Create a local copy of the dataframe
|
| 238 |
-
local_df = daa_df.copy()
|
| 239 |
-
|
| 240 |
-
# Sort the dataframe by date
|
| 241 |
-
local_df = local_df.sort_values(by="tx_date").set_index("tx_date")
|
| 242 |
-
|
| 243 |
-
# Group by market_creator and calculate rolling average of unique trader_address
|
| 244 |
-
rolling_avg = (
|
| 245 |
-
local_df.resample("D")["trader_address"]
|
| 246 |
-
.nunique()
|
| 247 |
-
.rolling(window=7)
|
| 248 |
-
.mean()
|
| 249 |
-
.reset_index()
|
| 250 |
-
)
|
| 251 |
-
rolling_avg.rename(columns={"trader_address": "rolling_avg_traders"}, inplace=True)
|
| 252 |
-
return rolling_avg
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
def plot_rolling_average(
|
| 256 |
-
daa_df: pd.DataFrame,
|
| 257 |
-
market_creator: str = None,
|
| 258 |
-
) -> gr.Plot:
|
| 259 |
-
"""Function to plot the rolling average of daily active traders by markets"""
|
| 260 |
-
if market_creator is not None:
|
| 261 |
-
filtered_traders_df = daa_df.loc[daa_df["market_creator"] == market_creator]
|
| 262 |
-
rolling_avg_df = get_sevenday_rolling_average(filtered_traders_df)
|
| 263 |
-
else:
|
| 264 |
-
rolling_avg_df = get_sevenday_rolling_average(daa_df)
|
| 265 |
-
print(rolling_avg_df.head())
|
| 266 |
-
|
| 267 |
-
# Ensure 'creation_date' is a column, not an index
|
| 268 |
-
if "tx_date" not in rolling_avg_df.columns:
|
| 269 |
-
rolling_avg_df = rolling_avg_df.reset_index()
|
| 270 |
-
|
| 271 |
-
fig = px.bar(
|
| 272 |
-
rolling_avg_df,
|
| 273 |
-
x="tx_date",
|
| 274 |
-
y="rolling_avg_traders",
|
| 275 |
-
)
|
| 276 |
-
fig.update_layout(
|
| 277 |
-
xaxis_title="Date",
|
| 278 |
-
yaxis_title="7-day rolling average of DAA",
|
| 279 |
-
)
|
| 280 |
-
|
| 281 |
-
return gr.Plot(
|
| 282 |
-
value=fig,
|
| 283 |
-
)
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
def plot_rolling_average_dune(
|
| 287 |
-
daa_df: pd.DataFrame,
|
| 288 |
-
) -> gr.Plot:
|
| 289 |
-
"""Function to plot the rolling average of daily active traders"""
|
| 290 |
-
|
| 291 |
-
fig = px.bar(
|
| 292 |
-
daa_df,
|
| 293 |
-
x="tx_date",
|
| 294 |
-
y="seven_day_trailing_avg",
|
| 295 |
-
)
|
| 296 |
-
fig.update_layout(
|
| 297 |
-
xaxis_title="Date",
|
| 298 |
-
yaxis_title="7-day rolling average of DAA",
|
| 299 |
-
)
|
| 300 |
-
|
| 301 |
-
return gr.Plot(
|
| 302 |
-
value=fig,
|
| 303 |
-
)
|
|
|
|
| 229 |
|
| 230 |
# Update y-axes to have the same range
|
| 231 |
fig.update_yaxes(matches="y")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs/trader_plots.py
CHANGED
|
@@ -348,104 +348,6 @@ def plot_total_bet_amount(
|
|
| 348 |
)
|
| 349 |
|
| 350 |
|
| 351 |
-
def get_sevenday_rolling_average_by_market_creator(
|
| 352 |
-
active_traders_df: pd.DataFrame,
|
| 353 |
-
) -> pd.DataFrame:
|
| 354 |
-
"""Function to get the 7-day rolling average of the number of unique trader_address by market_creator and total"""
|
| 355 |
-
# Create a local copy of the dataframe
|
| 356 |
-
local_df = active_traders_df.copy()
|
| 357 |
-
|
| 358 |
-
# Convert string dates to datetime
|
| 359 |
-
local_df["creation_date"] = pd.to_datetime(
|
| 360 |
-
local_df["creation_date"], format="%b-%d-%Y"
|
| 361 |
-
)
|
| 362 |
-
# Sort the dataframe by date
|
| 363 |
-
local_df = local_df.sort_values(by="creation_date")
|
| 364 |
-
|
| 365 |
-
# Group by market_creator and creation_date, count unique traders
|
| 366 |
-
daily_traders = (
|
| 367 |
-
local_df.groupby(["market_creator", "creation_date"])["trader_address"]
|
| 368 |
-
.nunique()
|
| 369 |
-
.reset_index()
|
| 370 |
-
)
|
| 371 |
-
|
| 372 |
-
# Calculate rolling average for each market_creator
|
| 373 |
-
rolling_avg_by_market = daily_traders.copy()
|
| 374 |
-
rolling_avg_by_market["rolling_avg_traders"] = rolling_avg_by_market.groupby(
|
| 375 |
-
"market_creator"
|
| 376 |
-
)["trader_address"].transform(lambda x: x.rolling(window=7).mean())
|
| 377 |
-
|
| 378 |
-
# Calculate the total rolling average across all market_creators
|
| 379 |
-
all_markets = daily_traders.copy()
|
| 380 |
-
all_markets["market_creator"] = "all"
|
| 381 |
-
all_markets = (
|
| 382 |
-
all_markets.groupby(["market_creator", "creation_date"])["trader_address"]
|
| 383 |
-
.sum()
|
| 384 |
-
.reset_index()
|
| 385 |
-
)
|
| 386 |
-
|
| 387 |
-
all_markets["rolling_avg_traders"] = (
|
| 388 |
-
all_markets["trader_address"].rolling(window=7).mean()
|
| 389 |
-
)
|
| 390 |
-
|
| 391 |
-
# Combine both results
|
| 392 |
-
combined_rolling_avg = pd.concat(
|
| 393 |
-
[rolling_avg_by_market, all_markets], ignore_index=True
|
| 394 |
-
)
|
| 395 |
-
|
| 396 |
-
return combined_rolling_avg
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
def get_twoweeks_rolling_average_roi(weekly_roi_df: pd.DataFrame) -> pd.DataFrame:
|
| 400 |
-
"""Function to get the 2-week rolling average of the ROI by market_creator and total"""
|
| 401 |
-
# Create a local copy of the dataframe
|
| 402 |
-
local_df = weekly_roi_df.copy()
|
| 403 |
-
|
| 404 |
-
# Convert string dates to datetime
|
| 405 |
-
local_df["month_year_week"] = pd.to_datetime(
|
| 406 |
-
local_df["month_year_week"], format="%b-%d-%Y"
|
| 407 |
-
)
|
| 408 |
-
# Sort the dataframe by date
|
| 409 |
-
local_df = local_df.sort_values(by="month_year_week").set_index("month_year_week")
|
| 410 |
-
|
| 411 |
-
# Group by market_creator and calculate rolling average of unique trader_address
|
| 412 |
-
trader_rolling_avg_roi = (
|
| 413 |
-
local_df.resample("W")["roi"].mean().rolling(window=2).mean().reset_index()
|
| 414 |
-
)
|
| 415 |
-
trader_rolling_avg_roi.rename(columns={"roi": "rolling_avg_roi"}, inplace=True)
|
| 416 |
-
return trader_rolling_avg_roi
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
def plot_rolling_average_roi(
|
| 420 |
-
weekly_roi_df: pd.DataFrame, market_creator: str
|
| 421 |
-
) -> gr.Plot:
|
| 422 |
-
"""Function to plot the rolling average of ROI for traders in a given market"""
|
| 423 |
-
if market_creator != "all":
|
| 424 |
-
filtered_roi_df = weekly_roi_df.loc[
|
| 425 |
-
weekly_roi_df["market_creator"] == market_creator
|
| 426 |
-
]
|
| 427 |
-
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(filtered_roi_df)
|
| 428 |
-
else:
|
| 429 |
-
rolling_avg_roi_df = get_twoweeks_rolling_average_roi(weekly_roi_df)
|
| 430 |
-
print(rolling_avg_roi_df.head())
|
| 431 |
-
# Ensure 'month_year_week' is a column, not an index
|
| 432 |
-
if "month_year_week" not in rolling_avg_roi_df.columns:
|
| 433 |
-
rolling_avg_roi_df = rolling_avg_roi_df.reset_index()
|
| 434 |
-
fig = px.bar(
|
| 435 |
-
rolling_avg_roi_df,
|
| 436 |
-
x="month_year_week",
|
| 437 |
-
y="rolling_avg_roi",
|
| 438 |
-
)
|
| 439 |
-
fig.update_layout(
|
| 440 |
-
xaxis_title="Week",
|
| 441 |
-
yaxis_title="4-week rolling average of ROI at the trader level",
|
| 442 |
-
)
|
| 443 |
-
|
| 444 |
-
return gr.Plot(
|
| 445 |
-
value=fig,
|
| 446 |
-
)
|
| 447 |
-
|
| 448 |
-
|
| 449 |
def plot_active_traders(
|
| 450 |
active_traders_data: pd.DataFrame,
|
| 451 |
market_creator: str = None,
|
|
|
|
| 348 |
)
|
| 349 |
|
| 350 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
def plot_active_traders(
|
| 352 |
active_traders_data: pd.DataFrame,
|
| 353 |
market_creator: str = None,
|