Commit
·
b9cf4a4
1
Parent(s):
b4a0040
removing daily graphs
Browse files- app.py +6 -79
- notebooks/daily_data.ipynb +0 -430
- notebooks/invalid_markets.ipynb +0 -0
- notebooks/mech_calls_analysis.ipynb +0 -0
- notebooks/outliers_analysis.ipynb +0 -0
- notebooks/roi_analysis.ipynb +112 -31
- notebooks/tool_errors_analysis.ipynb +0 -0
- notebooks/tools_accuracy.ipynb +74 -28
- notebooks/weekly_analysis.ipynb +46 -2
- scripts/daily_data.py +0 -89
- tabs/daily_graphs.py +0 -215
- tabs/metrics.py +1 -5
app.py
CHANGED
|
@@ -18,10 +18,8 @@ from tabs.staking import plot_staking_trades_per_market_by_week
|
|
| 18 |
|
| 19 |
from tabs.metrics import (
|
| 20 |
trade_metric_choices,
|
| 21 |
-
trade_daily_metric_choices,
|
| 22 |
tool_metric_choices,
|
| 23 |
default_trade_metric,
|
| 24 |
-
default_daily_metric,
|
| 25 |
default_tool_metric,
|
| 26 |
plot_trade_metrics,
|
| 27 |
get_trade_metrics_text,
|
|
@@ -54,9 +52,7 @@ from tabs.error import (
|
|
| 54 |
plot_tool_error_data_by_market,
|
| 55 |
)
|
| 56 |
|
| 57 |
-
from tabs.daily_graphs import get_current_week_data, plot_daily_metrics
|
| 58 |
from tabs.about import about_olas_predict, about_this_dashboard
|
| 59 |
-
import matplotlib.pyplot as plt
|
| 60 |
from scripts.utils import INC_TOOLS
|
| 61 |
|
| 62 |
|
|
@@ -112,14 +108,8 @@ def get_all_data():
|
|
| 112 |
Get all data from the tools.parquet, tools_accuracy and trades parquet files
|
| 113 |
"""
|
| 114 |
logger.info("Getting all data")
|
| 115 |
-
# Query to fetch daily live data
|
| 116 |
-
con = duckdb.connect(":memory:")
|
| 117 |
-
query5 = f"""
|
| 118 |
-
SELECT *
|
| 119 |
-
FROM read_parquet('./data/daily_info.parquet')
|
| 120 |
-
"""
|
| 121 |
-
df5 = con.execute(query5).fetchdf()
|
| 122 |
|
|
|
|
| 123 |
# Query to fetch invalid trades data
|
| 124 |
query4 = f"""
|
| 125 |
SELECT *
|
|
@@ -151,16 +141,14 @@ def get_all_data():
|
|
| 151 |
|
| 152 |
con.close()
|
| 153 |
|
| 154 |
-
return df1, df2, df3, df4
|
| 155 |
|
| 156 |
|
| 157 |
def prepare_data():
|
| 158 |
"""
|
| 159 |
Prepare the data for the dashboard
|
| 160 |
"""
|
| 161 |
-
tools_df, trades_df, tools_accuracy_info, invalid_trades
|
| 162 |
-
get_all_data()
|
| 163 |
-
)
|
| 164 |
print(trades_df.info())
|
| 165 |
|
| 166 |
tools_df = prepare_tools(tools_df)
|
|
@@ -174,17 +162,17 @@ def prepare_data():
|
|
| 174 |
invalid_trades["creation_timestamp"]
|
| 175 |
)
|
| 176 |
invalid_trades["creation_date"] = invalid_trades["creation_timestamp"].dt.date
|
| 177 |
-
|
| 178 |
# discovering outliers for ROI
|
| 179 |
outliers = trades_df.loc[trades_df["roi"] >= 1000]
|
| 180 |
if len(outliers) > 0:
|
| 181 |
outliers.to_parquet("./data/outliers.parquet")
|
| 182 |
trades_df = trades_df.loc[trades_df["roi"] < 1000]
|
| 183 |
|
| 184 |
-
return tools_df, trades_df, tools_accuracy_info, invalid_trades
|
| 185 |
|
| 186 |
|
| 187 |
-
tools_df, trades_df, tools_accuracy_info, invalid_trades
|
| 188 |
|
| 189 |
|
| 190 |
demo = gr.Blocks()
|
|
@@ -334,67 +322,6 @@ with demo:
|
|
| 334 |
inputs=[trade_na_details_selector, na_trade_details_plot],
|
| 335 |
outputs=[na_trade_details_plot],
|
| 336 |
)
|
| 337 |
-
with gr.TabItem("📅 Daily trades dashboard (WIP)"):
|
| 338 |
-
current_week_trades = get_current_week_data(trades_df=trades_df)
|
| 339 |
-
live_trades_current_week = get_current_week_data(trades_df=daily_info)
|
| 340 |
-
with gr.Row():
|
| 341 |
-
gr.Markdown("# Daily live metrics for all trades")
|
| 342 |
-
with gr.Row():
|
| 343 |
-
trade_live_details_selector = gr.Dropdown(
|
| 344 |
-
label="Select a daily live metric",
|
| 345 |
-
choices=trade_daily_metric_choices,
|
| 346 |
-
value=default_daily_metric,
|
| 347 |
-
)
|
| 348 |
-
|
| 349 |
-
with gr.Row():
|
| 350 |
-
with gr.Column(scale=3):
|
| 351 |
-
trade_live_details_plot = plot_daily_metrics(
|
| 352 |
-
metric_name=default_daily_metric,
|
| 353 |
-
trades_df=live_trades_current_week,
|
| 354 |
-
)
|
| 355 |
-
with gr.Column(scale=1):
|
| 356 |
-
trade_details_text = get_trade_metrics_text()
|
| 357 |
-
|
| 358 |
-
def update_trade_live_details(trade_detail, trade_live_details_plot):
|
| 359 |
-
new_a_plot = plot_daily_metrics(
|
| 360 |
-
metric_name=trade_detail, trades_df=live_trades_current_week
|
| 361 |
-
)
|
| 362 |
-
return new_a_plot
|
| 363 |
-
|
| 364 |
-
trade_live_details_selector.change(
|
| 365 |
-
update_trade_live_details,
|
| 366 |
-
inputs=[trade_live_details_selector, trade_live_details_plot],
|
| 367 |
-
outputs=[trade_live_details_plot],
|
| 368 |
-
)
|
| 369 |
-
|
| 370 |
-
with gr.Row():
|
| 371 |
-
gr.Markdown("# Daily profitability metrics available for all trades")
|
| 372 |
-
with gr.Row():
|
| 373 |
-
trade_daily_details_selector = gr.Dropdown(
|
| 374 |
-
label="Select a daily trade metric",
|
| 375 |
-
choices=trade_metric_choices,
|
| 376 |
-
value=default_trade_metric,
|
| 377 |
-
)
|
| 378 |
-
|
| 379 |
-
with gr.Row():
|
| 380 |
-
with gr.Column(scale=3):
|
| 381 |
-
trade_daily_details_plot = plot_daily_metrics(
|
| 382 |
-
metric_name=default_trade_metric, trades_df=current_week_trades
|
| 383 |
-
)
|
| 384 |
-
with gr.Column(scale=1):
|
| 385 |
-
trade_details_text = get_trade_metrics_text()
|
| 386 |
-
|
| 387 |
-
def update_trade_daily_details(trade_detail, trade_daily_details_plot):
|
| 388 |
-
new_a_plot = plot_daily_metrics(
|
| 389 |
-
metric_name=trade_detail, trades_df=current_week_trades
|
| 390 |
-
)
|
| 391 |
-
return new_a_plot
|
| 392 |
-
|
| 393 |
-
trade_daily_details_selector.change(
|
| 394 |
-
update_trade_daily_details,
|
| 395 |
-
inputs=[trade_daily_details_selector, trade_daily_details_plot],
|
| 396 |
-
outputs=[trade_daily_details_plot],
|
| 397 |
-
)
|
| 398 |
|
| 399 |
with gr.TabItem("🔒 Staking traders"):
|
| 400 |
with gr.Row():
|
|
|
|
| 18 |
|
| 19 |
from tabs.metrics import (
|
| 20 |
trade_metric_choices,
|
|
|
|
| 21 |
tool_metric_choices,
|
| 22 |
default_trade_metric,
|
|
|
|
| 23 |
default_tool_metric,
|
| 24 |
plot_trade_metrics,
|
| 25 |
get_trade_metrics_text,
|
|
|
|
| 52 |
plot_tool_error_data_by_market,
|
| 53 |
)
|
| 54 |
|
|
|
|
| 55 |
from tabs.about import about_olas_predict, about_this_dashboard
|
|
|
|
| 56 |
from scripts.utils import INC_TOOLS
|
| 57 |
|
| 58 |
|
|
|
|
| 108 |
Get all data from the tools.parquet, tools_accuracy and trades parquet files
|
| 109 |
"""
|
| 110 |
logger.info("Getting all data")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
+
con = duckdb.connect(":memory:")
|
| 113 |
# Query to fetch invalid trades data
|
| 114 |
query4 = f"""
|
| 115 |
SELECT *
|
|
|
|
| 141 |
|
| 142 |
con.close()
|
| 143 |
|
| 144 |
+
return df1, df2, df3, df4
|
| 145 |
|
| 146 |
|
| 147 |
def prepare_data():
|
| 148 |
"""
|
| 149 |
Prepare the data for the dashboard
|
| 150 |
"""
|
| 151 |
+
tools_df, trades_df, tools_accuracy_info, invalid_trades = get_all_data()
|
|
|
|
|
|
|
| 152 |
print(trades_df.info())
|
| 153 |
|
| 154 |
tools_df = prepare_tools(tools_df)
|
|
|
|
| 162 |
invalid_trades["creation_timestamp"]
|
| 163 |
)
|
| 164 |
invalid_trades["creation_date"] = invalid_trades["creation_timestamp"].dt.date
|
| 165 |
+
|
| 166 |
# discovering outliers for ROI
|
| 167 |
outliers = trades_df.loc[trades_df["roi"] >= 1000]
|
| 168 |
if len(outliers) > 0:
|
| 169 |
outliers.to_parquet("./data/outliers.parquet")
|
| 170 |
trades_df = trades_df.loc[trades_df["roi"] < 1000]
|
| 171 |
|
| 172 |
+
return tools_df, trades_df, tools_accuracy_info, invalid_trades
|
| 173 |
|
| 174 |
|
| 175 |
+
tools_df, trades_df, tools_accuracy_info, invalid_trades = prepare_data()
|
| 176 |
|
| 177 |
|
| 178 |
demo = gr.Blocks()
|
|
|
|
| 322 |
inputs=[trade_na_details_selector, na_trade_details_plot],
|
| 323 |
outputs=[na_trade_details_plot],
|
| 324 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
with gr.TabItem("🔒 Staking traders"):
|
| 327 |
with gr.Row():
|
notebooks/daily_data.ipynb
DELETED
|
@@ -1,430 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"cells": [
|
| 3 |
-
{
|
| 4 |
-
"cell_type": "code",
|
| 5 |
-
"execution_count": 2,
|
| 6 |
-
"metadata": {},
|
| 7 |
-
"outputs": [],
|
| 8 |
-
"source": [
|
| 9 |
-
"import pandas as pd"
|
| 10 |
-
]
|
| 11 |
-
},
|
| 12 |
-
{
|
| 13 |
-
"cell_type": "code",
|
| 14 |
-
"execution_count": 2,
|
| 15 |
-
"metadata": {},
|
| 16 |
-
"outputs": [],
|
| 17 |
-
"source": [
|
| 18 |
-
"all_trades = pd.read_parquet('../data/all_trades_profitability.parquet')"
|
| 19 |
-
]
|
| 20 |
-
},
|
| 21 |
-
{
|
| 22 |
-
"cell_type": "code",
|
| 23 |
-
"execution_count": 3,
|
| 24 |
-
"metadata": {},
|
| 25 |
-
"outputs": [
|
| 26 |
-
{
|
| 27 |
-
"data": {
|
| 28 |
-
"text/plain": [
|
| 29 |
-
"Timestamp('2024-11-23 01:38:25+0000', tz='UTC')"
|
| 30 |
-
]
|
| 31 |
-
},
|
| 32 |
-
"execution_count": 3,
|
| 33 |
-
"metadata": {},
|
| 34 |
-
"output_type": "execute_result"
|
| 35 |
-
}
|
| 36 |
-
],
|
| 37 |
-
"source": [
|
| 38 |
-
"max(all_trades.creation_timestamp)"
|
| 39 |
-
]
|
| 40 |
-
},
|
| 41 |
-
{
|
| 42 |
-
"cell_type": "code",
|
| 43 |
-
"execution_count": 4,
|
| 44 |
-
"metadata": {},
|
| 45 |
-
"outputs": [
|
| 46 |
-
{
|
| 47 |
-
"data": {
|
| 48 |
-
"text/plain": [
|
| 49 |
-
"Timestamp('2024-09-22 00:02:05+0000', tz='UTC')"
|
| 50 |
-
]
|
| 51 |
-
},
|
| 52 |
-
"execution_count": 4,
|
| 53 |
-
"metadata": {},
|
| 54 |
-
"output_type": "execute_result"
|
| 55 |
-
}
|
| 56 |
-
],
|
| 57 |
-
"source": [
|
| 58 |
-
"min(all_trades.creation_timestamp)"
|
| 59 |
-
]
|
| 60 |
-
},
|
| 61 |
-
{
|
| 62 |
-
"cell_type": "code",
|
| 63 |
-
"execution_count": 3,
|
| 64 |
-
"metadata": {},
|
| 65 |
-
"outputs": [],
|
| 66 |
-
"source": [
|
| 67 |
-
"new_trades = pd.read_parquet('../data/new_fpmmTrades.parquet')"
|
| 68 |
-
]
|
| 69 |
-
},
|
| 70 |
-
{
|
| 71 |
-
"cell_type": "code",
|
| 72 |
-
"execution_count": 11,
|
| 73 |
-
"metadata": {},
|
| 74 |
-
"outputs": [
|
| 75 |
-
{
|
| 76 |
-
"name": "stdout",
|
| 77 |
-
"output_type": "stream",
|
| 78 |
-
"text": [
|
| 79 |
-
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 80 |
-
"RangeIndex: 3798 entries, 0 to 3797\n",
|
| 81 |
-
"Data columns (total 24 columns):\n",
|
| 82 |
-
" # Column Non-Null Count Dtype \n",
|
| 83 |
-
"--- ------ -------------- ----- \n",
|
| 84 |
-
" 0 collateralAmount 3798 non-null object\n",
|
| 85 |
-
" 1 collateralAmountUSD 3798 non-null object\n",
|
| 86 |
-
" 2 collateralToken 3798 non-null object\n",
|
| 87 |
-
" 3 creationTimestamp 3798 non-null object\n",
|
| 88 |
-
" 4 trader_address 3798 non-null object\n",
|
| 89 |
-
" 5 feeAmount 3798 non-null object\n",
|
| 90 |
-
" 6 id 3798 non-null object\n",
|
| 91 |
-
" 7 oldOutcomeTokenMarginalPrice 3798 non-null object\n",
|
| 92 |
-
" 8 outcomeIndex 3798 non-null object\n",
|
| 93 |
-
" 9 outcomeTokenMarginalPrice 3798 non-null object\n",
|
| 94 |
-
" 10 outcomeTokensTraded 3798 non-null object\n",
|
| 95 |
-
" 11 title 3798 non-null object\n",
|
| 96 |
-
" 12 transactionHash 3798 non-null object\n",
|
| 97 |
-
" 13 type 3798 non-null object\n",
|
| 98 |
-
" 14 market_creator 3798 non-null object\n",
|
| 99 |
-
" 15 fpmm.answerFinalizedTimestamp 0 non-null object\n",
|
| 100 |
-
" 16 fpmm.arbitrationOccurred 3798 non-null bool \n",
|
| 101 |
-
" 17 fpmm.currentAnswer 0 non-null object\n",
|
| 102 |
-
" 18 fpmm.id 3798 non-null object\n",
|
| 103 |
-
" 19 fpmm.isPendingArbitration 3798 non-null bool \n",
|
| 104 |
-
" 20 fpmm.openingTimestamp 3798 non-null object\n",
|
| 105 |
-
" 21 fpmm.outcomes 3798 non-null object\n",
|
| 106 |
-
" 22 fpmm.title 3798 non-null object\n",
|
| 107 |
-
" 23 fpmm.condition.id 3798 non-null object\n",
|
| 108 |
-
"dtypes: bool(2), object(22)\n",
|
| 109 |
-
"memory usage: 660.3+ KB\n"
|
| 110 |
-
]
|
| 111 |
-
}
|
| 112 |
-
],
|
| 113 |
-
"source": [
|
| 114 |
-
"new_trades.info()"
|
| 115 |
-
]
|
| 116 |
-
},
|
| 117 |
-
{
|
| 118 |
-
"cell_type": "code",
|
| 119 |
-
"execution_count": 12,
|
| 120 |
-
"metadata": {},
|
| 121 |
-
"outputs": [
|
| 122 |
-
{
|
| 123 |
-
"data": {
|
| 124 |
-
"text/plain": [
|
| 125 |
-
"3798"
|
| 126 |
-
]
|
| 127 |
-
},
|
| 128 |
-
"execution_count": 12,
|
| 129 |
-
"metadata": {},
|
| 130 |
-
"output_type": "execute_result"
|
| 131 |
-
}
|
| 132 |
-
],
|
| 133 |
-
"source": [
|
| 134 |
-
"len(new_trades.id.unique())"
|
| 135 |
-
]
|
| 136 |
-
},
|
| 137 |
-
{
|
| 138 |
-
"cell_type": "code",
|
| 139 |
-
"execution_count": 4,
|
| 140 |
-
"metadata": {},
|
| 141 |
-
"outputs": [
|
| 142 |
-
{
|
| 143 |
-
"data": {
|
| 144 |
-
"text/plain": [
|
| 145 |
-
"Index(['collateralAmount', 'collateralAmountUSD', 'collateralToken',\n",
|
| 146 |
-
" 'creationTimestamp', 'trader_address', 'feeAmount', 'id',\n",
|
| 147 |
-
" 'oldOutcomeTokenMarginalPrice', 'outcomeIndex',\n",
|
| 148 |
-
" 'outcomeTokenMarginalPrice', 'outcomeTokensTraded', 'title',\n",
|
| 149 |
-
" 'transactionHash', 'type', 'market_creator',\n",
|
| 150 |
-
" 'fpmm.answerFinalizedTimestamp', 'fpmm.arbitrationOccurred',\n",
|
| 151 |
-
" 'fpmm.currentAnswer', 'fpmm.id', 'fpmm.isPendingArbitration',\n",
|
| 152 |
-
" 'fpmm.openingTimestamp', 'fpmm.outcomes', 'fpmm.title',\n",
|
| 153 |
-
" 'fpmm.condition.id'],\n",
|
| 154 |
-
" dtype='object')"
|
| 155 |
-
]
|
| 156 |
-
},
|
| 157 |
-
"execution_count": 4,
|
| 158 |
-
"metadata": {},
|
| 159 |
-
"output_type": "execute_result"
|
| 160 |
-
}
|
| 161 |
-
],
|
| 162 |
-
"source": [
|
| 163 |
-
"new_trades.columns"
|
| 164 |
-
]
|
| 165 |
-
},
|
| 166 |
-
{
|
| 167 |
-
"cell_type": "code",
|
| 168 |
-
"execution_count": 6,
|
| 169 |
-
"metadata": {},
|
| 170 |
-
"outputs": [
|
| 171 |
-
{
|
| 172 |
-
"data": {
|
| 173 |
-
"text/plain": [
|
| 174 |
-
"'1732609530'"
|
| 175 |
-
]
|
| 176 |
-
},
|
| 177 |
-
"execution_count": 6,
|
| 178 |
-
"metadata": {},
|
| 179 |
-
"output_type": "execute_result"
|
| 180 |
-
}
|
| 181 |
-
],
|
| 182 |
-
"source": [
|
| 183 |
-
"max(new_trades.creationTimestamp)"
|
| 184 |
-
]
|
| 185 |
-
},
|
| 186 |
-
{
|
| 187 |
-
"cell_type": "code",
|
| 188 |
-
"execution_count": 13,
|
| 189 |
-
"metadata": {},
|
| 190 |
-
"outputs": [],
|
| 191 |
-
"source": [
|
| 192 |
-
"old_trades = pd.read_parquet('../data/fpmmTrades.parquet')"
|
| 193 |
-
]
|
| 194 |
-
},
|
| 195 |
-
{
|
| 196 |
-
"cell_type": "code",
|
| 197 |
-
"execution_count": 14,
|
| 198 |
-
"metadata": {},
|
| 199 |
-
"outputs": [
|
| 200 |
-
{
|
| 201 |
-
"data": {
|
| 202 |
-
"text/plain": [
|
| 203 |
-
"'1732609530'"
|
| 204 |
-
]
|
| 205 |
-
},
|
| 206 |
-
"execution_count": 14,
|
| 207 |
-
"metadata": {},
|
| 208 |
-
"output_type": "execute_result"
|
| 209 |
-
}
|
| 210 |
-
],
|
| 211 |
-
"source": [
|
| 212 |
-
"max(old_trades.creationTimestamp)"
|
| 213 |
-
]
|
| 214 |
-
},
|
| 215 |
-
{
|
| 216 |
-
"cell_type": "code",
|
| 217 |
-
"execution_count": 25,
|
| 218 |
-
"metadata": {},
|
| 219 |
-
"outputs": [],
|
| 220 |
-
"source": [
|
| 221 |
-
"all_trades_before = pd.read_parquet('../data/daily_info.parquet')"
|
| 222 |
-
]
|
| 223 |
-
},
|
| 224 |
-
{
|
| 225 |
-
"cell_type": "code",
|
| 226 |
-
"execution_count": 26,
|
| 227 |
-
"metadata": {},
|
| 228 |
-
"outputs": [
|
| 229 |
-
{
|
| 230 |
-
"name": "stdout",
|
| 231 |
-
"output_type": "stream",
|
| 232 |
-
"text": [
|
| 233 |
-
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 234 |
-
"RangeIndex: 3882 entries, 0 to 3881\n",
|
| 235 |
-
"Data columns (total 21 columns):\n",
|
| 236 |
-
" # Column Non-Null Count Dtype \n",
|
| 237 |
-
"--- ------ -------------- ----- \n",
|
| 238 |
-
" 0 trader_address 3882 non-null object \n",
|
| 239 |
-
" 1 market_creator 3882 non-null object \n",
|
| 240 |
-
" 2 trade_id 3882 non-null object \n",
|
| 241 |
-
" 3 creation_timestamp 3882 non-null datetime64[ns, UTC]\n",
|
| 242 |
-
" 4 title 3882 non-null object \n",
|
| 243 |
-
" 5 market_status 3882 non-null object \n",
|
| 244 |
-
" 6 collateral_amount 3882 non-null float64 \n",
|
| 245 |
-
" 7 outcome_index 3882 non-null object \n",
|
| 246 |
-
" 8 trade_fee_amount 3882 non-null float64 \n",
|
| 247 |
-
" 9 outcomes_tokens_traded 3882 non-null float64 \n",
|
| 248 |
-
" 10 current_answer 0 non-null object \n",
|
| 249 |
-
" 11 is_invalid 3882 non-null bool \n",
|
| 250 |
-
" 12 winning_trade 0 non-null object \n",
|
| 251 |
-
" 13 earnings 3882 non-null float64 \n",
|
| 252 |
-
" 14 redeemed 3882 non-null bool \n",
|
| 253 |
-
" 15 redeemed_amount 3882 non-null int64 \n",
|
| 254 |
-
" 16 num_mech_calls 3882 non-null int64 \n",
|
| 255 |
-
" 17 mech_fee_amount 3882 non-null float64 \n",
|
| 256 |
-
" 18 net_earnings 3882 non-null float64 \n",
|
| 257 |
-
" 19 roi 3882 non-null float64 \n",
|
| 258 |
-
" 20 staking 3882 non-null object \n",
|
| 259 |
-
"dtypes: bool(2), datetime64[ns, UTC](1), float64(7), int64(2), object(9)\n",
|
| 260 |
-
"memory usage: 583.9+ KB\n"
|
| 261 |
-
]
|
| 262 |
-
}
|
| 263 |
-
],
|
| 264 |
-
"source": [
|
| 265 |
-
"all_trades_before.info()"
|
| 266 |
-
]
|
| 267 |
-
},
|
| 268 |
-
{
|
| 269 |
-
"cell_type": "code",
|
| 270 |
-
"execution_count": 27,
|
| 271 |
-
"metadata": {},
|
| 272 |
-
"outputs": [
|
| 273 |
-
{
|
| 274 |
-
"data": {
|
| 275 |
-
"text/plain": [
|
| 276 |
-
"Index(['trader_address', 'market_creator', 'trade_id', 'creation_timestamp',\n",
|
| 277 |
-
" 'title', 'market_status', 'collateral_amount', 'outcome_index',\n",
|
| 278 |
-
" 'trade_fee_amount', 'outcomes_tokens_traded', 'current_answer',\n",
|
| 279 |
-
" 'is_invalid', 'winning_trade', 'earnings', 'redeemed',\n",
|
| 280 |
-
" 'redeemed_amount', 'num_mech_calls', 'mech_fee_amount', 'net_earnings',\n",
|
| 281 |
-
" 'roi', 'staking'],\n",
|
| 282 |
-
" dtype='object')"
|
| 283 |
-
]
|
| 284 |
-
},
|
| 285 |
-
"execution_count": 27,
|
| 286 |
-
"metadata": {},
|
| 287 |
-
"output_type": "execute_result"
|
| 288 |
-
}
|
| 289 |
-
],
|
| 290 |
-
"source": [
|
| 291 |
-
"all_trades_before.columns"
|
| 292 |
-
]
|
| 293 |
-
},
|
| 294 |
-
{
|
| 295 |
-
"cell_type": "code",
|
| 296 |
-
"execution_count": 23,
|
| 297 |
-
"metadata": {},
|
| 298 |
-
"outputs": [
|
| 299 |
-
{
|
| 300 |
-
"data": {
|
| 301 |
-
"text/plain": [
|
| 302 |
-
"Timestamp('2024-11-26 10:19:30+0000', tz='UTC')"
|
| 303 |
-
]
|
| 304 |
-
},
|
| 305 |
-
"execution_count": 23,
|
| 306 |
-
"metadata": {},
|
| 307 |
-
"output_type": "execute_result"
|
| 308 |
-
}
|
| 309 |
-
],
|
| 310 |
-
"source": [
|
| 311 |
-
"max(all_trades_before.creation_timestamp)"
|
| 312 |
-
]
|
| 313 |
-
},
|
| 314 |
-
{
|
| 315 |
-
"cell_type": "code",
|
| 316 |
-
"execution_count": 28,
|
| 317 |
-
"metadata": {},
|
| 318 |
-
"outputs": [
|
| 319 |
-
{
|
| 320 |
-
"data": {
|
| 321 |
-
"text/plain": [
|
| 322 |
-
"staking\n",
|
| 323 |
-
"non_agent 2376\n",
|
| 324 |
-
"quickstart 672\n",
|
| 325 |
-
"pearl 502\n",
|
| 326 |
-
"non_staking 332\n",
|
| 327 |
-
"Name: count, dtype: int64"
|
| 328 |
-
]
|
| 329 |
-
},
|
| 330 |
-
"execution_count": 28,
|
| 331 |
-
"metadata": {},
|
| 332 |
-
"output_type": "execute_result"
|
| 333 |
-
}
|
| 334 |
-
],
|
| 335 |
-
"source": [
|
| 336 |
-
"all_trades_before.staking.value_counts()"
|
| 337 |
-
]
|
| 338 |
-
},
|
| 339 |
-
{
|
| 340 |
-
"cell_type": "code",
|
| 341 |
-
"execution_count": 7,
|
| 342 |
-
"metadata": {},
|
| 343 |
-
"outputs": [],
|
| 344 |
-
"source": [
|
| 345 |
-
"all_trades_df = pd.read_parquet('../json_data/all_trades_df.parquet')"
|
| 346 |
-
]
|
| 347 |
-
},
|
| 348 |
-
{
|
| 349 |
-
"cell_type": "code",
|
| 350 |
-
"execution_count": 8,
|
| 351 |
-
"metadata": {},
|
| 352 |
-
"outputs": [
|
| 353 |
-
{
|
| 354 |
-
"data": {
|
| 355 |
-
"text/plain": [
|
| 356 |
-
"Index(['trader_address', 'market_creator', 'trade_id', 'creation_timestamp',\n",
|
| 357 |
-
" 'title', 'market_status', 'collateral_amount', 'outcome_index',\n",
|
| 358 |
-
" 'trade_fee_amount', 'outcomes_tokens_traded', 'current_answer',\n",
|
| 359 |
-
" 'is_invalid', 'winning_trade', 'earnings', 'redeemed',\n",
|
| 360 |
-
" 'redeemed_amount', 'num_mech_calls', 'mech_fee_amount', 'net_earnings',\n",
|
| 361 |
-
" 'roi', 'staking', 'nr_mech_calls'],\n",
|
| 362 |
-
" dtype='object')"
|
| 363 |
-
]
|
| 364 |
-
},
|
| 365 |
-
"execution_count": 8,
|
| 366 |
-
"metadata": {},
|
| 367 |
-
"output_type": "execute_result"
|
| 368 |
-
}
|
| 369 |
-
],
|
| 370 |
-
"source": [
|
| 371 |
-
"all_trades_df.columns"
|
| 372 |
-
]
|
| 373 |
-
},
|
| 374 |
-
{
|
| 375 |
-
"cell_type": "code",
|
| 376 |
-
"execution_count": 9,
|
| 377 |
-
"metadata": {},
|
| 378 |
-
"outputs": [
|
| 379 |
-
{
|
| 380 |
-
"data": {
|
| 381 |
-
"text/plain": [
|
| 382 |
-
"Timestamp('2024-11-23 01:38:25+0000', tz='UTC')"
|
| 383 |
-
]
|
| 384 |
-
},
|
| 385 |
-
"execution_count": 9,
|
| 386 |
-
"metadata": {},
|
| 387 |
-
"output_type": "execute_result"
|
| 388 |
-
}
|
| 389 |
-
],
|
| 390 |
-
"source": [
|
| 391 |
-
"max(all_trades_df.creation_timestamp)"
|
| 392 |
-
]
|
| 393 |
-
},
|
| 394 |
-
{
|
| 395 |
-
"cell_type": "code",
|
| 396 |
-
"execution_count": null,
|
| 397 |
-
"metadata": {},
|
| 398 |
-
"outputs": [],
|
| 399 |
-
"source": []
|
| 400 |
-
},
|
| 401 |
-
{
|
| 402 |
-
"cell_type": "code",
|
| 403 |
-
"execution_count": null,
|
| 404 |
-
"metadata": {},
|
| 405 |
-
"outputs": [],
|
| 406 |
-
"source": []
|
| 407 |
-
}
|
| 408 |
-
],
|
| 409 |
-
"metadata": {
|
| 410 |
-
"kernelspec": {
|
| 411 |
-
"display_name": "hf_dashboards",
|
| 412 |
-
"language": "python",
|
| 413 |
-
"name": "python3"
|
| 414 |
-
},
|
| 415 |
-
"language_info": {
|
| 416 |
-
"codemirror_mode": {
|
| 417 |
-
"name": "ipython",
|
| 418 |
-
"version": 3
|
| 419 |
-
},
|
| 420 |
-
"file_extension": ".py",
|
| 421 |
-
"mimetype": "text/x-python",
|
| 422 |
-
"name": "python",
|
| 423 |
-
"nbconvert_exporter": "python",
|
| 424 |
-
"pygments_lexer": "ipython3",
|
| 425 |
-
"version": "3.12.2"
|
| 426 |
-
}
|
| 427 |
-
},
|
| 428 |
-
"nbformat": 4,
|
| 429 |
-
"nbformat_minor": 2
|
| 430 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
notebooks/invalid_markets.ipynb
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/mech_calls_analysis.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/outliers_analysis.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/roi_analysis.ipynb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
@@ -15,7 +15,7 @@
|
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
-
"execution_count":
|
| 19 |
"metadata": {},
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
|
@@ -25,6 +25,45 @@
|
|
| 25 |
"all_trades = pd.read_parquet('../data/all_trades_profitability.parquet')"
|
| 26 |
]
|
| 27 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
{
|
| 29 |
"cell_type": "code",
|
| 30 |
"execution_count": 3,
|
|
@@ -34,9 +73,8 @@
|
|
| 34 |
"data": {
|
| 35 |
"text/plain": [
|
| 36 |
"current_answer\n",
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"-1 801\n",
|
| 40 |
"Name: count, dtype: int64"
|
| 41 |
]
|
| 42 |
},
|
|
@@ -51,7 +89,49 @@
|
|
| 51 |
},
|
| 52 |
{
|
| 53 |
"cell_type": "code",
|
| 54 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"metadata": {},
|
| 56 |
"outputs": [
|
| 57 |
{
|
|
@@ -59,32 +139,33 @@
|
|
| 59 |
"output_type": "stream",
|
| 60 |
"text": [
|
| 61 |
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 62 |
-
"RangeIndex:
|
| 63 |
-
"Data columns (total
|
| 64 |
" # Column Non-Null Count Dtype \n",
|
| 65 |
"--- ------ -------------- ----- \n",
|
| 66 |
-
" 0 trader_address
|
| 67 |
-
" 1 market_creator
|
| 68 |
-
" 2 trade_id
|
| 69 |
-
" 3 creation_timestamp
|
| 70 |
-
" 4 title
|
| 71 |
-
" 5 market_status
|
| 72 |
-
" 6 collateral_amount
|
| 73 |
-
" 7 outcome_index
|
| 74 |
-
" 8 trade_fee_amount
|
| 75 |
-
" 9 outcomes_tokens_traded
|
| 76 |
-
" 10 current_answer
|
| 77 |
-
" 11 is_invalid
|
| 78 |
-
" 12 winning_trade
|
| 79 |
-
" 13 earnings
|
| 80 |
-
" 14 redeemed
|
| 81 |
-
" 15 redeemed_amount
|
| 82 |
-
" 16 num_mech_calls
|
| 83 |
-
" 17 mech_fee_amount
|
| 84 |
-
" 18 net_earnings
|
| 85 |
-
" 19 roi
|
| 86 |
-
"
|
| 87 |
-
"
|
|
|
|
| 88 |
]
|
| 89 |
}
|
| 90 |
],
|
|
@@ -709,7 +790,7 @@
|
|
| 709 |
],
|
| 710 |
"metadata": {
|
| 711 |
"kernelspec": {
|
| 712 |
-
"display_name": "
|
| 713 |
"language": "python",
|
| 714 |
"name": "python3"
|
| 715 |
},
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 3,
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
|
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
+
"execution_count": 4,
|
| 19 |
"metadata": {},
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
|
|
|
| 25 |
"all_trades = pd.read_parquet('../data/all_trades_profitability.parquet')"
|
| 26 |
]
|
| 27 |
},
|
| 28 |
+
{
|
| 29 |
+
"cell_type": "code",
|
| 30 |
+
"execution_count": 7,
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"outputs": [
|
| 33 |
+
{
|
| 34 |
+
"name": "stdout",
|
| 35 |
+
"output_type": "stream",
|
| 36 |
+
"text": [
|
| 37 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 38 |
+
"RangeIndex: 615 entries, 0 to 614\n",
|
| 39 |
+
"Data columns (total 16 columns):\n",
|
| 40 |
+
" # Column Non-Null Count Dtype \n",
|
| 41 |
+
"--- ------ -------------- ----- \n",
|
| 42 |
+
" 0 trader_address 615 non-null object \n",
|
| 43 |
+
" 1 num_trades 615 non-null int64 \n",
|
| 44 |
+
" 2 num_winning_trades 615 non-null float64\n",
|
| 45 |
+
" 3 num_redeemed 615 non-null float64\n",
|
| 46 |
+
" 4 total_investment 615 non-null float64\n",
|
| 47 |
+
" 5 total_trade_fees 615 non-null float64\n",
|
| 48 |
+
" 6 num_mech_calls 615 non-null int64 \n",
|
| 49 |
+
" 7 total_mech_fees 615 non-null float64\n",
|
| 50 |
+
" 8 total_earnings 615 non-null float64\n",
|
| 51 |
+
" 9 total_redeemed_amount 615 non-null float64\n",
|
| 52 |
+
" 10 total_net_earnings 615 non-null float64\n",
|
| 53 |
+
" 11 total_roi 615 non-null float64\n",
|
| 54 |
+
" 12 mean_mech_calls_per_trade 615 non-null float64\n",
|
| 55 |
+
" 13 mean_mech_fee_amount_per_trade 615 non-null float64\n",
|
| 56 |
+
" 14 total_net_earnings_wo_mech_fees 615 non-null float64\n",
|
| 57 |
+
" 15 total_roi_wo_mech_fees 615 non-null float64\n",
|
| 58 |
+
"dtypes: float64(13), int64(2), object(1)\n",
|
| 59 |
+
"memory usage: 77.0+ KB\n"
|
| 60 |
+
]
|
| 61 |
+
}
|
| 62 |
+
],
|
| 63 |
+
"source": [
|
| 64 |
+
"summary_traders.info()"
|
| 65 |
+
]
|
| 66 |
+
},
|
| 67 |
{
|
| 68 |
"cell_type": "code",
|
| 69 |
"execution_count": 3,
|
|
|
|
| 73 |
"data": {
|
| 74 |
"text/plain": [
|
| 75 |
"current_answer\n",
|
| 76 |
+
"1 25382\n",
|
| 77 |
+
"0 15794\n",
|
|
|
|
| 78 |
"Name: count, dtype: int64"
|
| 79 |
]
|
| 80 |
},
|
|
|
|
| 89 |
},
|
| 90 |
{
|
| 91 |
"cell_type": "code",
|
| 92 |
+
"execution_count": 5,
|
| 93 |
+
"metadata": {},
|
| 94 |
+
"outputs": [
|
| 95 |
+
{
|
| 96 |
+
"data": {
|
| 97 |
+
"text/plain": [
|
| 98 |
+
"pandas._libs.tslibs.timestamps.Timestamp"
|
| 99 |
+
]
|
| 100 |
+
},
|
| 101 |
+
"execution_count": 5,
|
| 102 |
+
"metadata": {},
|
| 103 |
+
"output_type": "execute_result"
|
| 104 |
+
}
|
| 105 |
+
],
|
| 106 |
+
"source": [
|
| 107 |
+
"type(all_trades.iloc[0].creation_timestamp)"
|
| 108 |
+
]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"cell_type": "code",
|
| 112 |
+
"execution_count": 7,
|
| 113 |
+
"metadata": {},
|
| 114 |
+
"outputs": [
|
| 115 |
+
{
|
| 116 |
+
"data": {
|
| 117 |
+
"text/plain": [
|
| 118 |
+
"is_invalid\n",
|
| 119 |
+
"False 41176\n",
|
| 120 |
+
"Name: count, dtype: int64"
|
| 121 |
+
]
|
| 122 |
+
},
|
| 123 |
+
"execution_count": 7,
|
| 124 |
+
"metadata": {},
|
| 125 |
+
"output_type": "execute_result"
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
"source": [
|
| 129 |
+
"all_trades.is_invalid.value_counts()"
|
| 130 |
+
]
|
| 131 |
+
},
|
| 132 |
+
{
|
| 133 |
+
"cell_type": "code",
|
| 134 |
+
"execution_count": 6,
|
| 135 |
"metadata": {},
|
| 136 |
"outputs": [
|
| 137 |
{
|
|
|
|
| 139 |
"output_type": "stream",
|
| 140 |
"text": [
|
| 141 |
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 142 |
+
"RangeIndex: 41176 entries, 0 to 41175\n",
|
| 143 |
+
"Data columns (total 21 columns):\n",
|
| 144 |
" # Column Non-Null Count Dtype \n",
|
| 145 |
"--- ------ -------------- ----- \n",
|
| 146 |
+
" 0 trader_address 41176 non-null object \n",
|
| 147 |
+
" 1 market_creator 41176 non-null object \n",
|
| 148 |
+
" 2 trade_id 41176 non-null object \n",
|
| 149 |
+
" 3 creation_timestamp 41176 non-null datetime64[ns, UTC]\n",
|
| 150 |
+
" 4 title 41176 non-null object \n",
|
| 151 |
+
" 5 market_status 41176 non-null object \n",
|
| 152 |
+
" 6 collateral_amount 41176 non-null float64 \n",
|
| 153 |
+
" 7 outcome_index 41176 non-null object \n",
|
| 154 |
+
" 8 trade_fee_amount 41176 non-null float64 \n",
|
| 155 |
+
" 9 outcomes_tokens_traded 41176 non-null float64 \n",
|
| 156 |
+
" 10 current_answer 41176 non-null int64 \n",
|
| 157 |
+
" 11 is_invalid 41176 non-null bool \n",
|
| 158 |
+
" 12 winning_trade 41176 non-null bool \n",
|
| 159 |
+
" 13 earnings 41176 non-null float64 \n",
|
| 160 |
+
" 14 redeemed 41176 non-null bool \n",
|
| 161 |
+
" 15 redeemed_amount 41176 non-null float64 \n",
|
| 162 |
+
" 16 num_mech_calls 41176 non-null int64 \n",
|
| 163 |
+
" 17 mech_fee_amount 41176 non-null float64 \n",
|
| 164 |
+
" 18 net_earnings 41176 non-null float64 \n",
|
| 165 |
+
" 19 roi 41176 non-null float64 \n",
|
| 166 |
+
" 20 staking 41176 non-null object \n",
|
| 167 |
+
"dtypes: bool(3), datetime64[ns, UTC](1), float64(8), int64(2), object(7)\n",
|
| 168 |
+
"memory usage: 5.8+ MB\n"
|
| 169 |
]
|
| 170 |
}
|
| 171 |
],
|
|
|
|
| 790 |
],
|
| 791 |
"metadata": {
|
| 792 |
"kernelspec": {
|
| 793 |
+
"display_name": "hf_dashboards",
|
| 794 |
"language": "python",
|
| 795 |
"name": "python3"
|
| 796 |
},
|
notebooks/tool_errors_analysis.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
notebooks/tools_accuracy.ipynb
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
-
"execution_count":
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
@@ -15,7 +15,7 @@
|
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
-
"execution_count":
|
| 19 |
"metadata": {},
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
|
@@ -24,7 +24,7 @@
|
|
| 24 |
},
|
| 25 |
{
|
| 26 |
"cell_type": "code",
|
| 27 |
-
"execution_count":
|
| 28 |
"metadata": {},
|
| 29 |
"outputs": [
|
| 30 |
{
|
|
@@ -32,35 +32,35 @@
|
|
| 32 |
"output_type": "stream",
|
| 33 |
"text": [
|
| 34 |
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 35 |
-
"RangeIndex:
|
| 36 |
"Data columns (total 23 columns):\n",
|
| 37 |
" # Column Non-Null Count Dtype \n",
|
| 38 |
"--- ------ -------------- ----- \n",
|
| 39 |
-
" 0 request_id
|
| 40 |
-
" 1 request_block
|
| 41 |
-
" 2 prompt_request
|
| 42 |
-
" 3 tool
|
| 43 |
-
" 4 nonce
|
| 44 |
-
" 5 trader_address
|
| 45 |
-
" 6 deliver_block
|
| 46 |
-
" 7 error
|
| 47 |
-
" 8 error_message
|
| 48 |
-
" 9 prompt_response
|
| 49 |
-
" 10 mech_address
|
| 50 |
-
" 11 p_yes
|
| 51 |
-
" 12 p_no
|
| 52 |
-
" 13 confidence
|
| 53 |
-
" 14 info_utility
|
| 54 |
-
" 15 vote
|
| 55 |
-
" 16 win_probability
|
| 56 |
-
" 17
|
| 57 |
-
" 18
|
| 58 |
-
" 19
|
| 59 |
-
" 20
|
| 60 |
-
" 21
|
| 61 |
-
" 22
|
| 62 |
"dtypes: float64(5), int64(1), object(17)\n",
|
| 63 |
-
"memory usage:
|
| 64 |
]
|
| 65 |
}
|
| 66 |
],
|
|
@@ -68,6 +68,52 @@
|
|
| 68 |
"tools.info()"
|
| 69 |
]
|
| 70 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
{
|
| 72 |
"cell_type": "code",
|
| 73 |
"execution_count": 23,
|
|
|
|
| 2 |
"cells": [
|
| 3 |
{
|
| 4 |
"cell_type": "code",
|
| 5 |
+
"execution_count": 2,
|
| 6 |
"metadata": {},
|
| 7 |
"outputs": [],
|
| 8 |
"source": [
|
|
|
|
| 15 |
},
|
| 16 |
{
|
| 17 |
"cell_type": "code",
|
| 18 |
+
"execution_count": 3,
|
| 19 |
"metadata": {},
|
| 20 |
"outputs": [],
|
| 21 |
"source": [
|
|
|
|
| 24 |
},
|
| 25 |
{
|
| 26 |
"cell_type": "code",
|
| 27 |
+
"execution_count": 4,
|
| 28 |
"metadata": {},
|
| 29 |
"outputs": [
|
| 30 |
{
|
|
|
|
| 32 |
"output_type": "stream",
|
| 33 |
"text": [
|
| 34 |
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 35 |
+
"RangeIndex: 358454 entries, 0 to 358453\n",
|
| 36 |
"Data columns (total 23 columns):\n",
|
| 37 |
" # Column Non-Null Count Dtype \n",
|
| 38 |
"--- ------ -------------- ----- \n",
|
| 39 |
+
" 0 request_id 358454 non-null object \n",
|
| 40 |
+
" 1 request_block 358454 non-null object \n",
|
| 41 |
+
" 2 prompt_request 358454 non-null object \n",
|
| 42 |
+
" 3 tool 358454 non-null object \n",
|
| 43 |
+
" 4 nonce 358454 non-null object \n",
|
| 44 |
+
" 5 trader_address 358454 non-null object \n",
|
| 45 |
+
" 6 deliver_block 358454 non-null object \n",
|
| 46 |
+
" 7 error 358454 non-null int64 \n",
|
| 47 |
+
" 8 error_message 3772 non-null object \n",
|
| 48 |
+
" 9 prompt_response 357509 non-null object \n",
|
| 49 |
+
" 10 mech_address 357601 non-null object \n",
|
| 50 |
+
" 11 p_yes 354682 non-null float64\n",
|
| 51 |
+
" 12 p_no 354682 non-null float64\n",
|
| 52 |
+
" 13 confidence 354682 non-null float64\n",
|
| 53 |
+
" 14 info_utility 354682 non-null float64\n",
|
| 54 |
+
" 15 vote 261707 non-null object \n",
|
| 55 |
+
" 16 win_probability 354682 non-null float64\n",
|
| 56 |
+
" 17 market_creator 358454 non-null object \n",
|
| 57 |
+
" 18 title 358454 non-null object \n",
|
| 58 |
+
" 19 currentAnswer 287126 non-null object \n",
|
| 59 |
+
" 20 request_time 358454 non-null object \n",
|
| 60 |
+
" 21 request_month_year 358454 non-null object \n",
|
| 61 |
+
" 22 request_month_year_week 358454 non-null object \n",
|
| 62 |
"dtypes: float64(5), int64(1), object(17)\n",
|
| 63 |
+
"memory usage: 62.9+ MB\n"
|
| 64 |
]
|
| 65 |
}
|
| 66 |
],
|
|
|
|
| 68 |
"tools.info()"
|
| 69 |
]
|
| 70 |
},
|
| 71 |
+
{
|
| 72 |
+
"cell_type": "code",
|
| 73 |
+
"execution_count": 5,
|
| 74 |
+
"metadata": {},
|
| 75 |
+
"outputs": [
|
| 76 |
+
{
|
| 77 |
+
"data": {
|
| 78 |
+
"text/plain": [
|
| 79 |
+
"Index(['request_id', 'request_block', 'prompt_request', 'tool', 'nonce',\n",
|
| 80 |
+
" 'trader_address', 'deliver_block', 'error', 'error_message',\n",
|
| 81 |
+
" 'prompt_response', 'mech_address', 'p_yes', 'p_no', 'confidence',\n",
|
| 82 |
+
" 'info_utility', 'vote', 'win_probability', 'market_creator', 'title',\n",
|
| 83 |
+
" 'currentAnswer', 'request_time', 'request_month_year',\n",
|
| 84 |
+
" 'request_month_year_week'],\n",
|
| 85 |
+
" dtype='object')"
|
| 86 |
+
]
|
| 87 |
+
},
|
| 88 |
+
"execution_count": 5,
|
| 89 |
+
"metadata": {},
|
| 90 |
+
"output_type": "execute_result"
|
| 91 |
+
}
|
| 92 |
+
],
|
| 93 |
+
"source": [
|
| 94 |
+
"tools.columns"
|
| 95 |
+
]
|
| 96 |
+
},
|
| 97 |
+
{
|
| 98 |
+
"cell_type": "code",
|
| 99 |
+
"execution_count": 8,
|
| 100 |
+
"metadata": {},
|
| 101 |
+
"outputs": [
|
| 102 |
+
{
|
| 103 |
+
"data": {
|
| 104 |
+
"text/plain": [
|
| 105 |
+
"str"
|
| 106 |
+
]
|
| 107 |
+
},
|
| 108 |
+
"execution_count": 8,
|
| 109 |
+
"metadata": {},
|
| 110 |
+
"output_type": "execute_result"
|
| 111 |
+
}
|
| 112 |
+
],
|
| 113 |
+
"source": [
|
| 114 |
+
"type(tools.iloc[0].request_time)"
|
| 115 |
+
]
|
| 116 |
+
},
|
| 117 |
{
|
| 118 |
"cell_type": "code",
|
| 119 |
"execution_count": 23,
|
notebooks/weekly_analysis.ipynb
CHANGED
|
@@ -74,13 +74,57 @@
|
|
| 74 |
},
|
| 75 |
{
|
| 76 |
"cell_type": "code",
|
| 77 |
-
"execution_count":
|
| 78 |
"metadata": {},
|
| 79 |
"outputs": [],
|
| 80 |
"source": [
|
| 81 |
"all_trades = pd.read_parquet('../data/all_trades_profitability.parquet')"
|
| 82 |
]
|
| 83 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
{
|
| 85 |
"cell_type": "code",
|
| 86 |
"execution_count": null,
|
|
@@ -4646,7 +4690,7 @@
|
|
| 4646 |
"name": "python",
|
| 4647 |
"nbconvert_exporter": "python",
|
| 4648 |
"pygments_lexer": "ipython3",
|
| 4649 |
-
"version": "3.12.
|
| 4650 |
},
|
| 4651 |
"orig_nbformat": 4
|
| 4652 |
},
|
|
|
|
| 74 |
},
|
| 75 |
{
|
| 76 |
"cell_type": "code",
|
| 77 |
+
"execution_count": 2,
|
| 78 |
"metadata": {},
|
| 79 |
"outputs": [],
|
| 80 |
"source": [
|
| 81 |
"all_trades = pd.read_parquet('../data/all_trades_profitability.parquet')"
|
| 82 |
]
|
| 83 |
},
|
| 84 |
+
{
|
| 85 |
+
"cell_type": "code",
|
| 86 |
+
"execution_count": 3,
|
| 87 |
+
"metadata": {},
|
| 88 |
+
"outputs": [
|
| 89 |
+
{
|
| 90 |
+
"name": "stdout",
|
| 91 |
+
"output_type": "stream",
|
| 92 |
+
"text": [
|
| 93 |
+
"<class 'pandas.core.frame.DataFrame'>\n",
|
| 94 |
+
"RangeIndex: 26861 entries, 0 to 26860\n",
|
| 95 |
+
"Data columns (total 21 columns):\n",
|
| 96 |
+
" # Column Non-Null Count Dtype \n",
|
| 97 |
+
"--- ------ -------------- ----- \n",
|
| 98 |
+
" 0 trader_address 26861 non-null object \n",
|
| 99 |
+
" 1 market_creator 26861 non-null object \n",
|
| 100 |
+
" 2 trade_id 26861 non-null object \n",
|
| 101 |
+
" 3 creation_timestamp 26861 non-null datetime64[ns, UTC]\n",
|
| 102 |
+
" 4 title 26861 non-null object \n",
|
| 103 |
+
" 5 market_status 26861 non-null object \n",
|
| 104 |
+
" 6 collateral_amount 26861 non-null float64 \n",
|
| 105 |
+
" 7 outcome_index 26861 non-null object \n",
|
| 106 |
+
" 8 trade_fee_amount 26861 non-null float64 \n",
|
| 107 |
+
" 9 outcomes_tokens_traded 26861 non-null float64 \n",
|
| 108 |
+
" 10 current_answer 26861 non-null int64 \n",
|
| 109 |
+
" 11 is_invalid 26861 non-null bool \n",
|
| 110 |
+
" 12 winning_trade 26861 non-null bool \n",
|
| 111 |
+
" 13 earnings 26861 non-null float64 \n",
|
| 112 |
+
" 14 redeemed 26861 non-null bool \n",
|
| 113 |
+
" 15 redeemed_amount 26861 non-null float64 \n",
|
| 114 |
+
" 16 num_mech_calls 26861 non-null int64 \n",
|
| 115 |
+
" 17 mech_fee_amount 26861 non-null float64 \n",
|
| 116 |
+
" 18 net_earnings 26861 non-null float64 \n",
|
| 117 |
+
" 19 roi 26861 non-null float64 \n",
|
| 118 |
+
" 20 staking 26861 non-null object \n",
|
| 119 |
+
"dtypes: bool(3), datetime64[ns, UTC](1), float64(8), int64(2), object(7)\n",
|
| 120 |
+
"memory usage: 3.8+ MB\n"
|
| 121 |
+
]
|
| 122 |
+
}
|
| 123 |
+
],
|
| 124 |
+
"source": [
|
| 125 |
+
"all_trades.info()"
|
| 126 |
+
]
|
| 127 |
+
},
|
| 128 |
{
|
| 129 |
"cell_type": "code",
|
| 130 |
"execution_count": null,
|
|
|
|
| 4690 |
"name": "python",
|
| 4691 |
"nbconvert_exporter": "python",
|
| 4692 |
"pygments_lexer": "ipython3",
|
| 4693 |
+
"version": "3.12.2"
|
| 4694 |
},
|
| 4695 |
"orig_nbformat": 4
|
| 4696 |
},
|
scripts/daily_data.py
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
import logging
|
| 2 |
-
from utils import get_question, current_answer, RPC, measure_execution_time
|
| 3 |
-
from markets import (
|
| 4 |
-
etl as mkt_etl,
|
| 5 |
-
DEFAULT_FILENAME as MARKETS_FILENAME,
|
| 6 |
-
)
|
| 7 |
-
from get_mech_info import (
|
| 8 |
-
get_mech_events_since_last_run,
|
| 9 |
-
update_json_files,
|
| 10 |
-
)
|
| 11 |
-
from pull_data import DATA_DIR, update_json_files, updating_timestamps
|
| 12 |
-
from tools import DEFAULT_FILENAME as TOOLS_FILENAME, generate_tools_file
|
| 13 |
-
from profitability import (
|
| 14 |
-
run_profitability_analysis,
|
| 15 |
-
analyse_all_traders,
|
| 16 |
-
label_trades_by_staking,
|
| 17 |
-
)
|
| 18 |
-
from update_tools_accuracy import compute_tools_accuracy
|
| 19 |
-
import pandas as pd
|
| 20 |
-
|
| 21 |
-
logging.basicConfig(level=logging.INFO)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def prepare_live_metrics(
|
| 25 |
-
tools_filename="new_tools.parquet", trades_filename="new_fpmmTrades.parquet"
|
| 26 |
-
):
|
| 27 |
-
fpmmTrades = pd.read_parquet(DATA_DIR / trades_filename)
|
| 28 |
-
tools = pd.read_parquet(DATA_DIR / tools_filename)
|
| 29 |
-
print("Analysing trades...")
|
| 30 |
-
all_trades_df = analyse_all_traders(fpmmTrades, tools, daily_info=True)
|
| 31 |
-
|
| 32 |
-
# staking label
|
| 33 |
-
label_trades_by_staking(all_trades_df)
|
| 34 |
-
|
| 35 |
-
# save into a separate file
|
| 36 |
-
all_trades_df.to_parquet(DATA_DIR / "daily_info.parquet", index=False)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
@measure_execution_time
|
| 40 |
-
def daily_analysis():
|
| 41 |
-
"""Run daily analysis for the FPMMS project."""
|
| 42 |
-
rpc = RPC
|
| 43 |
-
# Run markets ETL
|
| 44 |
-
logging.info("Running markets ETL")
|
| 45 |
-
mkt_etl(MARKETS_FILENAME)
|
| 46 |
-
logging.info("Markets ETL completed")
|
| 47 |
-
|
| 48 |
-
# get only new data
|
| 49 |
-
latest_timestamp = get_mech_events_since_last_run()
|
| 50 |
-
if latest_timestamp == None:
|
| 51 |
-
print("Error while getting the mech events")
|
| 52 |
-
return
|
| 53 |
-
logging.info(f"Finished generating the mech json files from {latest_timestamp}")
|
| 54 |
-
|
| 55 |
-
# Run tools ETL
|
| 56 |
-
logging.info("Generate and parse the tools content")
|
| 57 |
-
# generate only new file
|
| 58 |
-
generate_tools_file("new_tools_info.json", "new_tools.parquet")
|
| 59 |
-
logging.info("Tools ETL completed")
|
| 60 |
-
|
| 61 |
-
# add_current_answer("new_tools.parquet")
|
| 62 |
-
|
| 63 |
-
# # Run profitability analysis
|
| 64 |
-
logging.info("Computing trading metrics")
|
| 65 |
-
run_profitability_analysis(
|
| 66 |
-
rpc=rpc,
|
| 67 |
-
tools_filename="new_tools.parquet",
|
| 68 |
-
trades_filename="new_fpmmTrades.parquet",
|
| 69 |
-
# from_timestamp=int(latest_timestamp.timestamp()),
|
| 70 |
-
from_timestamp=latest_timestamp,
|
| 71 |
-
merge=True,
|
| 72 |
-
)
|
| 73 |
-
logging.info("Profitability analysis completed")
|
| 74 |
-
|
| 75 |
-
# merge new json files with old json files
|
| 76 |
-
update_json_files()
|
| 77 |
-
|
| 78 |
-
try:
|
| 79 |
-
updating_timestamps(rpc, TOOLS_FILENAME)
|
| 80 |
-
except Exception as e:
|
| 81 |
-
logging.error("Error while updating timestamps of tools")
|
| 82 |
-
print(e)
|
| 83 |
-
|
| 84 |
-
compute_tools_accuracy()
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
if __name__ == "__main__":
|
| 88 |
-
daily_analysis()
|
| 89 |
-
prepare_live_metrics()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs/daily_graphs.py
DELETED
|
@@ -1,215 +0,0 @@
|
|
| 1 |
-
import pandas as pd
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import gc
|
| 4 |
-
import plotly.express as px
|
| 5 |
-
from plotly.subplots import make_subplots
|
| 6 |
-
import plotly.graph_objects as go
|
| 7 |
-
from datetime import datetime, timedelta
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def plot_daily_trades(trades_df: pd.DataFrame) -> gr.Plot:
|
| 11 |
-
# get daily trades
|
| 12 |
-
daily_trades_count = (
|
| 13 |
-
trades_df.groupby("month_year_week").size().reset_index(name="trades")
|
| 14 |
-
)
|
| 15 |
-
daily_trades_count.columns = daily_trades_count.columns.astype(str)
|
| 16 |
-
print("WIP")
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def get_current_week_data(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 20 |
-
# Get current date
|
| 21 |
-
now = datetime.now()
|
| 22 |
-
|
| 23 |
-
# Get start of the current week (Monday)
|
| 24 |
-
start_of_week = now - timedelta(days=now.weekday())
|
| 25 |
-
start_of_week = start_of_week.replace(hour=0, minute=0, second=0, microsecond=0)
|
| 26 |
-
print(f"start of the week = {start_of_week}")
|
| 27 |
-
|
| 28 |
-
# Get end of the current week (Sunday)
|
| 29 |
-
end_of_week = start_of_week + timedelta(days=6)
|
| 30 |
-
end_of_week = end_of_week.replace(hour=23, minute=59, second=59, microsecond=999999)
|
| 31 |
-
print(f"end of the week = {end_of_week}")
|
| 32 |
-
trades_df["creation_date"] = pd.to_datetime(trades_df["creation_date"])
|
| 33 |
-
# Filter the dataframe
|
| 34 |
-
return trades_df[
|
| 35 |
-
(trades_df["creation_date"] >= start_of_week)
|
| 36 |
-
& (trades_df["creation_date"] <= end_of_week)
|
| 37 |
-
]
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
def get_boxplot_daily_metrics(
|
| 41 |
-
column_name: str, trades_df: pd.DataFrame
|
| 42 |
-
) -> pd.DataFrame:
|
| 43 |
-
trades_filtered = trades_df[
|
| 44 |
-
["creation_timestamp", "creation_date", "market_creator", column_name]
|
| 45 |
-
]
|
| 46 |
-
# adding the total
|
| 47 |
-
trades_filtered_all = trades_df.copy(deep=True)
|
| 48 |
-
trades_filtered_all["market_creator"] = "all"
|
| 49 |
-
|
| 50 |
-
# merging both dataframes
|
| 51 |
-
all_filtered_trades = pd.concat(
|
| 52 |
-
[trades_filtered, trades_filtered_all], ignore_index=True
|
| 53 |
-
)
|
| 54 |
-
all_filtered_trades = all_filtered_trades.sort_values(
|
| 55 |
-
by="creation_timestamp", ascending=True
|
| 56 |
-
)
|
| 57 |
-
gc.collect()
|
| 58 |
-
return all_filtered_trades
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def plot_daily_metrics(
|
| 62 |
-
metric_name: str, trades_df: pd.DataFrame, trader_filter: str = None
|
| 63 |
-
) -> gr.Plot:
|
| 64 |
-
"""Plots the trade metrics."""
|
| 65 |
-
|
| 66 |
-
if metric_name == "mech calls":
|
| 67 |
-
metric_name = "mech_calls"
|
| 68 |
-
column_name = "num_mech_calls"
|
| 69 |
-
yaxis_title = "Nr of mech calls per trade"
|
| 70 |
-
elif metric_name == "ROI":
|
| 71 |
-
column_name = "roi"
|
| 72 |
-
yaxis_title = "ROI (net profit/cost)"
|
| 73 |
-
elif metric_name == "collateral amount":
|
| 74 |
-
metric_name = "collateral_amount"
|
| 75 |
-
column_name = metric_name
|
| 76 |
-
yaxis_title = "Collateral amount per trade (xDAI)"
|
| 77 |
-
elif metric_name == "net earnings":
|
| 78 |
-
metric_name = "net_earnings"
|
| 79 |
-
column_name = metric_name
|
| 80 |
-
yaxis_title = "Net profit per trade (xDAI)"
|
| 81 |
-
else: # earnings
|
| 82 |
-
column_name = metric_name
|
| 83 |
-
yaxis_title = "Gross profit per trade (xDAI)"
|
| 84 |
-
|
| 85 |
-
color_discrete = ["purple", "darkgoldenrod", "darkgreen"]
|
| 86 |
-
|
| 87 |
-
if trader_filter == "agent":
|
| 88 |
-
trades_filtered = get_boxplot_daily_metrics(
|
| 89 |
-
column_name, trades_df.loc[trades_df["staking"] != "non_agent"]
|
| 90 |
-
)
|
| 91 |
-
color_discrete = ["darkviolet", "goldenrod", "green"]
|
| 92 |
-
elif trader_filter == "non_agent":
|
| 93 |
-
trades_filtered = get_boxplot_daily_metrics(
|
| 94 |
-
column_name, trades_df.loc[trades_df["staking"] == "non_agent"]
|
| 95 |
-
)
|
| 96 |
-
else:
|
| 97 |
-
trades_filtered = get_boxplot_daily_metrics(column_name, trades_df)
|
| 98 |
-
color_mapping = [
|
| 99 |
-
"darkviolet",
|
| 100 |
-
"purple",
|
| 101 |
-
"goldenrod",
|
| 102 |
-
"darkgoldenrod",
|
| 103 |
-
"green",
|
| 104 |
-
"darkgreen",
|
| 105 |
-
]
|
| 106 |
-
|
| 107 |
-
# Create binary staking category
|
| 108 |
-
trades_filtered["trader_type"] = trades_filtered["staking"].apply(
|
| 109 |
-
lambda x: "non_agent" if x == "non_agent" else "agent"
|
| 110 |
-
)
|
| 111 |
-
trades_filtered["trader_market"] = trades_filtered.apply(
|
| 112 |
-
lambda x: (x["trader_type"], x["market_creator"]), axis=1
|
| 113 |
-
)
|
| 114 |
-
fig = px.box(
|
| 115 |
-
trades_filtered,
|
| 116 |
-
x="creation_date",
|
| 117 |
-
y=column_name,
|
| 118 |
-
color="trader_market",
|
| 119 |
-
color_discrete_sequence=color_mapping,
|
| 120 |
-
category_orders={
|
| 121 |
-
"market_creator": ["pearl", "quickstart", "all"],
|
| 122 |
-
"trader_market": [
|
| 123 |
-
("agent", "pearl"),
|
| 124 |
-
("non_agent", "pearl"),
|
| 125 |
-
("agent", "quickstart"),
|
| 126 |
-
("non_agent", "quickstart"),
|
| 127 |
-
("agent", "all"),
|
| 128 |
-
("non_agent", "all"),
|
| 129 |
-
],
|
| 130 |
-
},
|
| 131 |
-
facet_col="market_creator",
|
| 132 |
-
)
|
| 133 |
-
fig.update_traces(boxmean=True)
|
| 134 |
-
fig.update_layout(
|
| 135 |
-
xaxis_title="Day",
|
| 136 |
-
yaxis_title=yaxis_title,
|
| 137 |
-
legend=dict(yanchor="top", y=0.5),
|
| 138 |
-
)
|
| 139 |
-
for axis in fig.layout:
|
| 140 |
-
if axis.startswith("xaxis"):
|
| 141 |
-
fig.layout[axis].update(title="Day")
|
| 142 |
-
fig.update_xaxes(tickformat="%b %d")
|
| 143 |
-
return gr.Plot(
|
| 144 |
-
value=fig,
|
| 145 |
-
)
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
def plot_daily_metrics_v2(
|
| 149 |
-
metric_name: str, trades_df: pd.DataFrame, trader_filter: str = None
|
| 150 |
-
) -> gr.Plot:
|
| 151 |
-
"""Plots the trade metrics."""
|
| 152 |
-
|
| 153 |
-
if metric_name == "mech calls":
|
| 154 |
-
metric_name = "mech_calls"
|
| 155 |
-
column_name = "num_mech_calls"
|
| 156 |
-
yaxis_title = "Nr of mech calls per trade"
|
| 157 |
-
elif metric_name == "ROI":
|
| 158 |
-
column_name = "roi"
|
| 159 |
-
yaxis_title = "ROI (net profit/cost)"
|
| 160 |
-
elif metric_name == "collateral amount":
|
| 161 |
-
metric_name = "collateral_amount"
|
| 162 |
-
column_name = metric_name
|
| 163 |
-
yaxis_title = "Collateral amount per trade (xDAI)"
|
| 164 |
-
elif metric_name == "net earnings":
|
| 165 |
-
metric_name = "net_earnings"
|
| 166 |
-
column_name = metric_name
|
| 167 |
-
yaxis_title = "Net profit per trade (xDAI)"
|
| 168 |
-
else: # earnings
|
| 169 |
-
column_name = metric_name
|
| 170 |
-
yaxis_title = "Gross profit per trade (xDAI)"
|
| 171 |
-
|
| 172 |
-
color_discrete = ["purple", "darkgoldenrod", "darkgreen"]
|
| 173 |
-
trades_filtered = get_boxplot_daily_metrics(column_name, trades_df)
|
| 174 |
-
fig = make_subplots(rows=1, cols=2, subplot_titles=("Agent", "Non-Agents"))
|
| 175 |
-
|
| 176 |
-
# Create first boxplot for staking=True
|
| 177 |
-
fig.add_trace(
|
| 178 |
-
go.Box(
|
| 179 |
-
x=trades_filtered[trades_filtered["staking"] != "non_agent"][
|
| 180 |
-
"creation_date"
|
| 181 |
-
],
|
| 182 |
-
y=trades_filtered[trades_filtered["staking"] != "non_agent"][column_name],
|
| 183 |
-
name="Trades from agents",
|
| 184 |
-
marker_color=color_discrete[0],
|
| 185 |
-
legendgroup="staking_true",
|
| 186 |
-
showlegend=True,
|
| 187 |
-
),
|
| 188 |
-
row=1,
|
| 189 |
-
col=1,
|
| 190 |
-
)
|
| 191 |
-
|
| 192 |
-
# Create second boxplot for staking=False
|
| 193 |
-
fig.add_trace(
|
| 194 |
-
go.Box(
|
| 195 |
-
x=trades_filtered[trades_filtered["staking"] == False]["creation_date"],
|
| 196 |
-
y=trades_filtered[trades_filtered["staking"] == False][column_name],
|
| 197 |
-
name="Staking False",
|
| 198 |
-
marker_color=color_discrete[1],
|
| 199 |
-
legendgroup="staking_false",
|
| 200 |
-
showlegend=True,
|
| 201 |
-
),
|
| 202 |
-
row=1,
|
| 203 |
-
col=2,
|
| 204 |
-
)
|
| 205 |
-
|
| 206 |
-
# Update layout
|
| 207 |
-
fig.update_layout(
|
| 208 |
-
height=600,
|
| 209 |
-
width=1200,
|
| 210 |
-
title_text=f"Box Plot of {column_name} by Staking Status",
|
| 211 |
-
showlegend=True,
|
| 212 |
-
)
|
| 213 |
-
|
| 214 |
-
# Update y-axes to have the same range
|
| 215 |
-
fig.update_yaxes(matches="y")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs/metrics.py
CHANGED
|
@@ -11,10 +11,6 @@ trade_metric_choices = [
|
|
| 11 |
"ROI",
|
| 12 |
]
|
| 13 |
|
| 14 |
-
trade_daily_metric_choices = [
|
| 15 |
-
"mech calls",
|
| 16 |
-
"collateral amount",
|
| 17 |
-
]
|
| 18 |
|
| 19 |
tool_metric_choices = {
|
| 20 |
"Weekly Mean Mech Tool Accuracy as (Accurate Responses/All) %": "win_perc",
|
|
@@ -24,7 +20,7 @@ tool_metric_choices = {
|
|
| 24 |
}
|
| 25 |
|
| 26 |
default_trade_metric = "ROI"
|
| 27 |
-
|
| 28 |
default_tool_metric = "Weekly Mean Mech Tool Accuracy as (Accurate Responses/All) %"
|
| 29 |
|
| 30 |
HEIGHT = 600
|
|
|
|
| 11 |
"ROI",
|
| 12 |
]
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
tool_metric_choices = {
|
| 16 |
"Weekly Mean Mech Tool Accuracy as (Accurate Responses/All) %": "win_perc",
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
default_trade_metric = "ROI"
|
| 23 |
+
|
| 24 |
default_tool_metric = "Weekly Mean Mech Tool Accuracy as (Accurate Responses/All) %"
|
| 25 |
|
| 26 |
HEIGHT = 600
|