cyberosa commited on
Commit
1e8c5cf
Β·
1 Parent(s): e5aa6da

prototype of avg monthly ROI for pearl traders

Browse files
Files changed (2) hide show
  1. app.py +9 -0
  2. tabs/trader_plots.py +47 -0
app.py CHANGED
@@ -27,6 +27,7 @@ from tabs.trader_plots import (
27
  plot_total_bet_amount,
28
  plot_active_traders,
29
  plot_rolling_average,
 
30
  )
31
  from tabs.daily_graphs import (
32
  get_current_week_data,
@@ -263,6 +264,14 @@ with demo:
263
  gr.Markdown("This app shows the weekly performance of the traders in Olas Predict.")
264
 
265
  with gr.Tabs():
 
 
 
 
 
 
 
 
266
  with gr.TabItem("πŸ”₯ Weekly metrics"):
267
  with gr.Row():
268
  gr.Markdown("# Weekly metrics of all traders")
 
27
  plot_total_bet_amount,
28
  plot_active_traders,
29
  plot_rolling_average,
30
+ plot_avg_monthly_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("πŸ“Š 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")
tabs/trader_plots.py CHANGED
@@ -84,6 +84,53 @@ def get_interpretation_text() -> gr.Markdown:
84
  return gr.Markdown(interpretation_text)
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  def plot_trader_metrics_by_market_creator(
88
  metric_name: str, traders_df: pd.DataFrame
89
  ) -> gr.Plot:
 
84
  return gr.Markdown(interpretation_text)
85
 
86
 
87
+ def plot_avg_monthly_ROI(traders_df: pd.DataFrame, market_creator: str) -> gr.Plot:
88
+ """Plots the average monthly ROI."""
89
+
90
+ filtered_traders_df = traders_df.copy()
91
+ if market_creator != "all": # filter by market creator
92
+ filtered_traders_df = filtered_traders_df[
93
+ traders_df["market_creator"] == market_creator
94
+ ]
95
+
96
+ # Create the column month_year from the creation_date
97
+ filtered_traders_df["month_year"] = filtered_traders_df["creation_date"].apply(
98
+ lambda x: x.strftime("%Y-%m")
99
+ )
100
+ # Compute the average monthly ROI per trader
101
+
102
+ monthly_avg_roi_traders = (
103
+ filtered_traders_df.groupby(["month_year", "trader_address"])["roi"]
104
+ .mean()
105
+ .reset_index(name="avg_roi")
106
+ )
107
+
108
+ # Plot the mean value per month in monthly_avg_roi_traders
109
+ total_monthly_avg_roi = (
110
+ monthly_avg_roi_traders.groupby("month_year")["avg_roi"]
111
+ .mean()
112
+ .reset_index(name="avg_roi")
113
+ )
114
+
115
+ fig = px.line(
116
+ total_monthly_avg_roi,
117
+ x="month_year",
118
+ y="avg_roi",
119
+ )
120
+
121
+ fig.update_layout(
122
+ xaxis_title="Month-Year",
123
+ yaxis_title="Average monthly ROI (net profit/cost)",
124
+ )
125
+ fig.update_xaxes(
126
+ tickvals=total_monthly_avg_roi["month_year"].tolist(), # Set x-axis tick values
127
+ tickformat="%Y-%m",
128
+ )
129
+ return gr.Plot(
130
+ value=fig,
131
+ )
132
+
133
+
134
  def plot_trader_metrics_by_market_creator(
135
  metric_name: str, traders_df: pd.DataFrame
136
  ) -> gr.Plot: