Spaces:
Runtime error
Runtime error
cyberosa
commited on
Commit
Β·
e29f544
1
Parent(s):
1e8c5cf
removing monthly roi graph and adding 4 weeks avg roi
Browse files- app.py +8 -9
- tabs/trader_plots.py +50 -6
app.py
CHANGED
|
@@ -27,7 +27,7 @@ from tabs.trader_plots import (
|
|
| 27 |
plot_total_bet_amount,
|
| 28 |
plot_active_traders,
|
| 29 |
plot_rolling_average,
|
| 30 |
-
|
| 31 |
)
|
| 32 |
from tabs.daily_graphs import (
|
| 33 |
get_current_week_data,
|
|
@@ -264,14 +264,6 @@ with demo:
|
|
| 264 |
gr.Markdown("This app shows the weekly performance of the traders in Olas Predict.")
|
| 265 |
|
| 266 |
with gr.Tabs():
|
| 267 |
-
with gr.TabItem("π Monthly metrics"):
|
| 268 |
-
with gr.Row():
|
| 269 |
-
gr.Markdown("# Monthly average ROI of Pearl traders")
|
| 270 |
-
with gr.Row():
|
| 271 |
-
avrg_monthly_roi = plot_avg_monthly_ROI(
|
| 272 |
-
traders_data, market_creator="pearl"
|
| 273 |
-
)
|
| 274 |
-
|
| 275 |
with gr.TabItem("π₯ Weekly metrics"):
|
| 276 |
with gr.Row():
|
| 277 |
gr.Markdown("# Weekly metrics of all traders")
|
|
@@ -396,6 +388,13 @@ with demo:
|
|
| 396 |
inputs=trader_u_details_selector,
|
| 397 |
outputs=trader_u_markets_plot,
|
| 398 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
with gr.TabItem("π
Daily metrics"):
|
| 400 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
| 401 |
if len(live_trades_current_week) > 0:
|
|
|
|
| 27 |
plot_total_bet_amount,
|
| 28 |
plot_active_traders,
|
| 29 |
plot_rolling_average,
|
| 30 |
+
plot_rolling_average_roi,
|
| 31 |
)
|
| 32 |
from tabs.daily_graphs import (
|
| 33 |
get_current_week_data,
|
|
|
|
| 264 |
gr.Markdown("This app shows the weekly performance of the traders in Olas Predict.")
|
| 265 |
|
| 266 |
with gr.Tabs():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
with gr.TabItem("π₯ Weekly metrics"):
|
| 268 |
with gr.Row():
|
| 269 |
gr.Markdown("# Weekly metrics of all traders")
|
|
|
|
| 388 |
inputs=trader_u_details_selector,
|
| 389 |
outputs=trader_u_markets_plot,
|
| 390 |
)
|
| 391 |
+
with gr.Row():
|
| 392 |
+
gr.Markdown("# 4-weeks rolling average ROI for Pearl traders")
|
| 393 |
+
with gr.Row():
|
| 394 |
+
pearl_rolling_avg_plot = plot_rolling_average_roi(
|
| 395 |
+
weekly_roi_df=weekly_metrics_by_market_creator,
|
| 396 |
+
market_creator="pearl",
|
| 397 |
+
)
|
| 398 |
with gr.TabItem("π
Daily metrics"):
|
| 399 |
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
| 400 |
if len(live_trades_current_week) > 0:
|
tabs/trader_plots.py
CHANGED
|
@@ -396,6 +396,56 @@ def get_sevenday_rolling_average_by_market_creator(
|
|
| 396 |
return combined_rolling_avg
|
| 397 |
|
| 398 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 399 |
def get_sevenday_rolling_average(active_traders_df: pd.DataFrame) -> pd.DataFrame:
|
| 400 |
"""Function to get the 7-day rolling average of the number of unique trader_address by market_creator and total"""
|
| 401 |
# Create a local copy of the dataframe
|
|
@@ -444,16 +494,10 @@ def plot_rolling_average(
|
|
| 444 |
rolling_avg_df,
|
| 445 |
x="creation_date",
|
| 446 |
y="rolling_avg_traders",
|
| 447 |
-
# color="market_creator",
|
| 448 |
-
# color_discrete_sequence=color_mapping,
|
| 449 |
-
# category_orders={
|
| 450 |
-
# "market_creator": ["pearl", "quickstart", "all"],
|
| 451 |
-
# },
|
| 452 |
)
|
| 453 |
fig.update_layout(
|
| 454 |
xaxis_title="Date",
|
| 455 |
yaxis_title="7-day rolling average of active traders",
|
| 456 |
-
legend=dict(yanchor="top", y=0.5),
|
| 457 |
)
|
| 458 |
|
| 459 |
return gr.Plot(
|
|
|
|
| 396 |
return combined_rolling_avg
|
| 397 |
|
| 398 |
|
| 399 |
+
def get_fourweeks_rolling_average_roi(weekly_roi_df: pd.DataFrame) -> pd.DataFrame:
|
| 400 |
+
"""Function to get the 4-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=4).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_fourweeks_rolling_average_roi(filtered_roi_df)
|
| 428 |
+
else:
|
| 429 |
+
rolling_avg_roi_df = get_fourweeks_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 get_sevenday_rolling_average(active_traders_df: pd.DataFrame) -> pd.DataFrame:
|
| 450 |
"""Function to get the 7-day rolling average of the number of unique trader_address by market_creator and total"""
|
| 451 |
# Create a local copy of the dataframe
|
|
|
|
| 494 |
rolling_avg_df,
|
| 495 |
x="creation_date",
|
| 496 |
y="rolling_avg_traders",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 497 |
)
|
| 498 |
fig.update_layout(
|
| 499 |
xaxis_title="Date",
|
| 500 |
yaxis_title="7-day rolling average of active traders",
|
|
|
|
| 501 |
)
|
| 502 |
|
| 503 |
return gr.Plot(
|