Commit
·
7a45667
1
Parent(s):
3adbef9
new pearl markets and new graphs
Browse files- app.py +19 -1
- data/all_trades_profitability.parquet +2 -2
- data/fpmmTrades.parquet +2 -2
- data/fpmms.parquet +2 -2
- data/invalid_trades.parquet +2 -2
- data/summary_profitability.parquet +2 -2
- requirements.txt +2 -2
- scripts/markets.py +46 -9
- scripts/profitability.py +50 -19
- tabs/trades.py +176 -45
app.py
CHANGED
|
@@ -8,9 +8,13 @@ import logging
|
|
| 8 |
from tabs.trades import (
|
| 9 |
prepare_trades,
|
| 10 |
get_overall_trades,
|
|
|
|
| 11 |
get_overall_winning_trades,
|
|
|
|
| 12 |
plot_trades_by_week,
|
|
|
|
| 13 |
plot_winning_trades_by_week,
|
|
|
|
| 14 |
plot_trade_details,
|
| 15 |
)
|
| 16 |
from tabs.tool_win import (
|
|
@@ -138,6 +142,7 @@ def prepare_data():
|
|
| 138 |
Prepare the data for the dashboard
|
| 139 |
"""
|
| 140 |
tools_df, trades_df, tools_accuracy_info, invalid_trades = get_all_data()
|
|
|
|
| 141 |
|
| 142 |
tools_df["request_time"] = pd.to_datetime(tools_df["request_time"])
|
| 143 |
trades_df["creation_timestamp"] = pd.to_datetime(trades_df["creation_timestamp"])
|
|
@@ -220,7 +225,20 @@ with demo:
|
|
| 220 |
trade_details_selector
|
| 221 |
with gr.Row():
|
| 222 |
trade_details_plot
|
| 223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
with gr.TabItem("🚀 Tool Winning Dashboard"):
|
| 225 |
with gr.Row():
|
| 226 |
gr.Markdown("# All tools winning performance")
|
|
|
|
| 8 |
from tabs.trades import (
|
| 9 |
prepare_trades,
|
| 10 |
get_overall_trades,
|
| 11 |
+
get_overall_by_market_trades,
|
| 12 |
get_overall_winning_trades,
|
| 13 |
+
get_overall_winning_by_market_trades,
|
| 14 |
plot_trades_by_week,
|
| 15 |
+
plot_trades_per_market_by_week,
|
| 16 |
plot_winning_trades_by_week,
|
| 17 |
+
plot_winning_trades_per_market_by_week,
|
| 18 |
plot_trade_details,
|
| 19 |
)
|
| 20 |
from tabs.tool_win import (
|
|
|
|
| 142 |
Prepare the data for the dashboard
|
| 143 |
"""
|
| 144 |
tools_df, trades_df, tools_accuracy_info, invalid_trades = get_all_data()
|
| 145 |
+
print(trades_df.info())
|
| 146 |
|
| 147 |
tools_df["request_time"] = pd.to_datetime(tools_df["request_time"])
|
| 148 |
trades_df["creation_timestamp"] = pd.to_datetime(trades_df["creation_timestamp"])
|
|
|
|
| 225 |
trade_details_selector
|
| 226 |
with gr.Row():
|
| 227 |
trade_details_plot
|
| 228 |
+
with gr.TabItem("🔥Trades per market Dashboard"):
|
| 229 |
+
with gr.Row():
|
| 230 |
+
gr.Markdown("# Number of trades split by market type per week")
|
| 231 |
+
with gr.Row():
|
| 232 |
+
trades_by_week_plot = plot_trades_per_market_by_week(
|
| 233 |
+
trades_df=get_overall_by_market_trades(trades_df=trades_df)
|
| 234 |
+
)
|
| 235 |
+
with gr.Row():
|
| 236 |
+
gr.Markdown("# Percentage of winning trades per week")
|
| 237 |
+
with gr.Row():
|
| 238 |
+
winning_trades_by_week_plot = plot_winning_trades_per_market_by_week(
|
| 239 |
+
trades_df=get_overall_winning_by_market_trades(trades_df=trades_df)
|
| 240 |
+
)
|
| 241 |
+
# TODO add average ROI value per market
|
| 242 |
with gr.TabItem("🚀 Tool Winning Dashboard"):
|
| 243 |
with gr.Row():
|
| 244 |
gr.Markdown("# All tools winning performance")
|
data/all_trades_profitability.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2228c601aaa9c6f33d8a018b946bbd654e392a27b4d1b2b7310ea8d4019bf640
|
| 3 |
+
size 1651423
|
data/fpmmTrades.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:56d7bc7c2dd1970b3f3d97d70a9d4e92134b17da9469bcfbd2ecdcf85e6b7aea
|
| 3 |
+
size 5345188
|
data/fpmms.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9df2136521afbf13e5d3675f14eead02ae66b2fce1c5e9e09fdd10d057f7dec
|
| 3 |
+
size 411157
|
data/invalid_trades.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:efdca1d658e69a2d61ead2e38513a66cfa37beb64ccd4d642493dd77f02c4ba8
|
| 3 |
+
size 247018
|
data/summary_profitability.parquet
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e6fb720990290b9df24681e10aca6d545a4bab615f166bf4861be14d2465cdd3
|
| 3 |
+
size 34952
|
requirements.txt
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
-
pandas==2.
|
| 2 |
seaborn
|
| 3 |
matplotlib
|
| 4 |
huggingface-hub
|
| 5 |
pyarrow
|
| 6 |
requests
|
| 7 |
-
gradio==4.
|
| 8 |
plotly
|
| 9 |
nbformat
|
| 10 |
pytz
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
seaborn
|
| 3 |
matplotlib
|
| 4 |
huggingface-hub
|
| 5 |
pyarrow
|
| 6 |
requests
|
| 7 |
+
gradio==4.27.0
|
| 8 |
plotly
|
| 9 |
nbformat
|
| 10 |
pytz
|
scripts/markets.py
CHANGED
|
@@ -47,8 +47,9 @@ SubgraphResponseType = Dict[str, ResponseItemType]
|
|
| 47 |
|
| 48 |
|
| 49 |
CREATOR = "0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"
|
|
|
|
| 50 |
BATCH_SIZE = 1000
|
| 51 |
-
|
| 52 |
OMEN_SUBGRAPH_URL = Template(
|
| 53 |
"""https://gateway-arbitrum.network.thegraph.com/api/${subgraph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz"""
|
| 54 |
)
|
|
@@ -142,14 +143,19 @@ def query_subgraph(url: str, query: str, key: str) -> SubgraphResponseType:
|
|
| 142 |
return data
|
| 143 |
|
| 144 |
|
| 145 |
-
def fpmms_fetcher() -> Generator[ResponseItemType, int, None]:
|
| 146 |
"""An indefinite fetcher for the FPMMs."""
|
| 147 |
omen_subgraph = OMEN_SUBGRAPH_URL.substitute(subgraph_api_key=SUBGRAPH_API_KEY)
|
| 148 |
print(f"omen_subgraph = {omen_subgraph}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
while True:
|
| 150 |
fpmm_id = yield
|
| 151 |
fpmms_query = FPMMS_QUERY.substitute(
|
| 152 |
-
creator=
|
| 153 |
fpmm_id=fpmm_id,
|
| 154 |
fpmms_field=FPMMS_FIELD,
|
| 155 |
first=BATCH_SIZE,
|
|
@@ -159,15 +165,38 @@ def fpmms_fetcher() -> Generator[ResponseItemType, int, None]:
|
|
| 159 |
outcomes_field=OUTCOMES_FIELD,
|
| 160 |
title_field=TITLE_FIELD,
|
| 161 |
)
|
| 162 |
-
|
| 163 |
yield query_subgraph(omen_subgraph, fpmms_query, FPMMS_FIELD)
|
| 164 |
|
| 165 |
|
| 166 |
-
def
|
| 167 |
"""Fetch all the fpmms of the creator."""
|
| 168 |
latest_id = ""
|
| 169 |
fpmms = []
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
for _ in tqdm(fetcher, unit="fpmms", unit_scale=BATCH_SIZE):
|
| 172 |
batch = fetcher.send(latest_id)
|
| 173 |
if len(batch) == 0:
|
|
@@ -203,8 +232,16 @@ def transform_fpmms(fpmms: pd.DataFrame) -> pd.DataFrame:
|
|
| 203 |
|
| 204 |
def etl(filename: Optional[str] = None) -> pd.DataFrame:
|
| 205 |
"""Fetch, process, store and return the markets as a Dataframe."""
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
|
| 209 |
if filename:
|
| 210 |
fpmms.to_parquet(DATA_DIR / filename, index=False)
|
|
@@ -213,4 +250,4 @@ def etl(filename: Optional[str] = None) -> pd.DataFrame:
|
|
| 213 |
|
| 214 |
|
| 215 |
if __name__ == "__main__":
|
| 216 |
-
etl(
|
|
|
|
| 47 |
|
| 48 |
|
| 49 |
CREATOR = "0x89c5cc945dd550BcFfb72Fe42BfF002429F46Fec"
|
| 50 |
+
PEARL_CREATOR = "0xFfc8029154ECD55ABED15BD428bA596E7D23f557"
|
| 51 |
BATCH_SIZE = 1000
|
| 52 |
+
|
| 53 |
OMEN_SUBGRAPH_URL = Template(
|
| 54 |
"""https://gateway-arbitrum.network.thegraph.com/api/${subgraph_api_key}/subgraphs/id/9fUVQpFwzpdWS9bq5WkAnmKbNNcoBwatMR4yZq81pbbz"""
|
| 55 |
)
|
|
|
|
| 143 |
return data
|
| 144 |
|
| 145 |
|
| 146 |
+
def fpmms_fetcher(trader_category: str) -> Generator[ResponseItemType, int, None]:
|
| 147 |
"""An indefinite fetcher for the FPMMs."""
|
| 148 |
omen_subgraph = OMEN_SUBGRAPH_URL.substitute(subgraph_api_key=SUBGRAPH_API_KEY)
|
| 149 |
print(f"omen_subgraph = {omen_subgraph}")
|
| 150 |
+
|
| 151 |
+
if trader_category == "pearl":
|
| 152 |
+
creator_id = PEARL_CREATOR
|
| 153 |
+
else: # quickstart
|
| 154 |
+
creator_id = CREATOR
|
| 155 |
while True:
|
| 156 |
fpmm_id = yield
|
| 157 |
fpmms_query = FPMMS_QUERY.substitute(
|
| 158 |
+
creator=creator_id,
|
| 159 |
fpmm_id=fpmm_id,
|
| 160 |
fpmms_field=FPMMS_FIELD,
|
| 161 |
first=BATCH_SIZE,
|
|
|
|
| 165 |
outcomes_field=OUTCOMES_FIELD,
|
| 166 |
title_field=TITLE_FIELD,
|
| 167 |
)
|
| 168 |
+
print(f"markets query = {fpmms_query}")
|
| 169 |
yield query_subgraph(omen_subgraph, fpmms_query, FPMMS_FIELD)
|
| 170 |
|
| 171 |
|
| 172 |
+
def fetch_qs_fpmms() -> pd.DataFrame:
|
| 173 |
"""Fetch all the fpmms of the creator."""
|
| 174 |
latest_id = ""
|
| 175 |
fpmms = []
|
| 176 |
+
trader_category = "quickstart"
|
| 177 |
+
print(f"Getting markets for {trader_category}")
|
| 178 |
+
fetcher = fpmms_fetcher(trader_category)
|
| 179 |
+
for _ in tqdm(fetcher, unit="fpmms", unit_scale=BATCH_SIZE):
|
| 180 |
+
batch = fetcher.send(latest_id)
|
| 181 |
+
if len(batch) == 0:
|
| 182 |
+
break
|
| 183 |
+
|
| 184 |
+
latest_id = batch[-1].get(ID_FIELD, "")
|
| 185 |
+
if latest_id == "":
|
| 186 |
+
raise ValueError(f"Unexpected data format retrieved: {batch}")
|
| 187 |
+
|
| 188 |
+
fpmms.extend(batch)
|
| 189 |
+
|
| 190 |
+
return pd.DataFrame(fpmms)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def fetch_pearl_fpmms() -> pd.DataFrame:
|
| 194 |
+
"""Fetch all the fpmms of the creator."""
|
| 195 |
+
latest_id = ""
|
| 196 |
+
fpmms = []
|
| 197 |
+
trader_category = "pearl"
|
| 198 |
+
print(f"Getting markets for {trader_category}")
|
| 199 |
+
fetcher = fpmms_fetcher(trader_category)
|
| 200 |
for _ in tqdm(fetcher, unit="fpmms", unit_scale=BATCH_SIZE):
|
| 201 |
batch = fetcher.send(latest_id)
|
| 202 |
if len(batch) == 0:
|
|
|
|
| 232 |
|
| 233 |
def etl(filename: Optional[str] = None) -> pd.DataFrame:
|
| 234 |
"""Fetch, process, store and return the markets as a Dataframe."""
|
| 235 |
+
qs_fpmms = fetch_qs_fpmms()
|
| 236 |
+
qs_fpmms = transform_fpmms(qs_fpmms)
|
| 237 |
+
qs_fpmms["market_creator"] = "quickstart"
|
| 238 |
+
print(f"Results for the market creator quickstart. Len = {len(qs_fpmms)}")
|
| 239 |
+
|
| 240 |
+
pearl_fpmms = fetch_pearl_fpmms()
|
| 241 |
+
pearl_fpmms = transform_fpmms(pearl_fpmms)
|
| 242 |
+
pearl_fpmms["market_creator"] = "pearl"
|
| 243 |
+
print(f"Results for the market creator quickstart. Len = {len(pearl_fpmms)}")
|
| 244 |
+
fpmms = pd.concat([qs_fpmms, pearl_fpmms], ignore_index=True)
|
| 245 |
|
| 246 |
if filename:
|
| 247 |
fpmms.to_parquet(DATA_DIR / filename, index=False)
|
|
|
|
| 250 |
|
| 251 |
|
| 252 |
if __name__ == "__main__":
|
| 253 |
+
etl("all_fpmms.parquet")
|
scripts/profitability.py
CHANGED
|
@@ -36,7 +36,8 @@ from queries import omen_xdai_trades_query, conditional_tokens_gc_user_query
|
|
| 36 |
QUERY_BATCH_SIZE = 1000
|
| 37 |
DUST_THRESHOLD = 10000000000000
|
| 38 |
INVALID_ANSWER = -1
|
| 39 |
-
|
|
|
|
| 40 |
DEFAULT_FROM_DATE = "1970-01-01T00:00:00"
|
| 41 |
DEFAULT_TO_DATE = "2038-01-19T03:14:07"
|
| 42 |
DEFAULT_FROM_TIMESTAMP = 0
|
|
@@ -143,6 +144,7 @@ headers = {
|
|
| 143 |
|
| 144 |
|
| 145 |
def _query_omen_xdai_subgraph(
|
|
|
|
| 146 |
from_timestamp: float,
|
| 147 |
to_timestamp: float,
|
| 148 |
fpmm_from_timestamp: float,
|
|
@@ -156,10 +158,14 @@ def _query_omen_xdai_subgraph(
|
|
| 156 |
print(f"omen_subgraph = {omen_subgraph}")
|
| 157 |
grouped_results = defaultdict(list)
|
| 158 |
id_gt = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
|
| 160 |
while True:
|
| 161 |
query = omen_xdai_trades_query.substitute(
|
| 162 |
-
fpmm_creator=
|
| 163 |
creationTimestamp_gte=int(from_timestamp),
|
| 164 |
creationTimestamp_lte=int(to_timestamp),
|
| 165 |
fpmm_creationTimestamp_gte=int(fpmm_from_timestamp),
|
|
@@ -251,22 +257,8 @@ def _is_redeemed(user_json: dict[str, Any], fpmmTrade: dict[str, Any]) -> bool:
|
|
| 251 |
return False
|
| 252 |
|
| 253 |
|
| 254 |
-
def
|
| 255 |
-
"
|
| 256 |
-
trades_json = _query_omen_xdai_subgraph(
|
| 257 |
-
from_timestamp=from_timestamp,
|
| 258 |
-
to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 259 |
-
fpmm_from_timestamp=from_timestamp,
|
| 260 |
-
fpmm_to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 261 |
-
)
|
| 262 |
-
|
| 263 |
-
print(f"length of the trades_json dataset {len(trades_json)}")
|
| 264 |
-
|
| 265 |
-
# convert to dataframe
|
| 266 |
-
df = pd.DataFrame(trades_json["data"]["fpmmTrades"])
|
| 267 |
-
print(df.head())
|
| 268 |
-
print(df.info())
|
| 269 |
-
|
| 270 |
# convert creator to address
|
| 271 |
df["creator"] = df["creator"].apply(lambda x: x["id"])
|
| 272 |
|
|
@@ -280,10 +272,48 @@ def create_fpmmTrades(rpc: str, from_timestamp: float = DEFAULT_FROM_TIMESTAMP):
|
|
| 280 |
|
| 281 |
# change creator to creator_address
|
| 282 |
df.rename(columns={"creator": "trader_address"}, inplace=True)
|
| 283 |
-
|
|
|
|
| 284 |
return df
|
| 285 |
|
| 286 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
def prepare_profitalibity_data(
|
| 288 |
rpc: str,
|
| 289 |
tools_filename: str = "tools.parquet",
|
|
@@ -518,6 +548,7 @@ def run_profitability_analysis(
|
|
| 518 |
rpc, tools_filename, trades_filename, from_timestamp
|
| 519 |
)
|
| 520 |
tools["trader_address"] = tools["trader_address"].str.lower()
|
|
|
|
| 521 |
|
| 522 |
# all trades profitability df
|
| 523 |
print("Analysing trades...")
|
|
|
|
| 36 |
QUERY_BATCH_SIZE = 1000
|
| 37 |
DUST_THRESHOLD = 10000000000000
|
| 38 |
INVALID_ANSWER = -1
|
| 39 |
+
FPMM_QS_CREATOR = "0x89c5cc945dd550bcffb72fe42bff002429f46fec"
|
| 40 |
+
FPMM_PEARL_CREATOR = "0xFfc8029154ECD55ABED15BD428bA596E7D23f557"
|
| 41 |
DEFAULT_FROM_DATE = "1970-01-01T00:00:00"
|
| 42 |
DEFAULT_TO_DATE = "2038-01-19T03:14:07"
|
| 43 |
DEFAULT_FROM_TIMESTAMP = 0
|
|
|
|
| 144 |
|
| 145 |
|
| 146 |
def _query_omen_xdai_subgraph(
|
| 147 |
+
trader_category: str,
|
| 148 |
from_timestamp: float,
|
| 149 |
to_timestamp: float,
|
| 150 |
fpmm_from_timestamp: float,
|
|
|
|
| 158 |
print(f"omen_subgraph = {omen_subgraph}")
|
| 159 |
grouped_results = defaultdict(list)
|
| 160 |
id_gt = ""
|
| 161 |
+
if trader_category == "quickstart":
|
| 162 |
+
creator_id = FPMM_QS_CREATOR.lower()
|
| 163 |
+
else: # pearl
|
| 164 |
+
creator_id = FPMM_PEARL_CREATOR.lower()
|
| 165 |
|
| 166 |
while True:
|
| 167 |
query = omen_xdai_trades_query.substitute(
|
| 168 |
+
fpmm_creator=creator_id,
|
| 169 |
creationTimestamp_gte=int(from_timestamp),
|
| 170 |
creationTimestamp_lte=int(to_timestamp),
|
| 171 |
fpmm_creationTimestamp_gte=int(fpmm_from_timestamp),
|
|
|
|
| 257 |
return False
|
| 258 |
|
| 259 |
|
| 260 |
+
def transform_fpmmTrades(df: pd.DataFrame) -> pd.DataFrame:
|
| 261 |
+
print("Transforming trades dataframe")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
# convert creator to address
|
| 263 |
df["creator"] = df["creator"].apply(lambda x: x["id"])
|
| 264 |
|
|
|
|
| 272 |
|
| 273 |
# change creator to creator_address
|
| 274 |
df.rename(columns={"creator": "trader_address"}, inplace=True)
|
| 275 |
+
print(df.head())
|
| 276 |
+
print(df.info())
|
| 277 |
return df
|
| 278 |
|
| 279 |
|
| 280 |
+
def create_fpmmTrades(rpc: str, from_timestamp: float = DEFAULT_FROM_TIMESTAMP):
|
| 281 |
+
"""Create fpmmTrades for all trades."""
|
| 282 |
+
# Quickstart trades
|
| 283 |
+
qs_trades_json = _query_omen_xdai_subgraph(
|
| 284 |
+
trader_category="quickstart",
|
| 285 |
+
from_timestamp=from_timestamp,
|
| 286 |
+
to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 287 |
+
fpmm_from_timestamp=from_timestamp,
|
| 288 |
+
fpmm_to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
print(f"length of the qs_trades_json dataset {len(qs_trades_json)}")
|
| 292 |
+
|
| 293 |
+
# convert to dataframe
|
| 294 |
+
qs_df = pd.DataFrame(qs_trades_json["data"]["fpmmTrades"])
|
| 295 |
+
qs_df["market_creator"] = "quickstart"
|
| 296 |
+
qs_df = transform_fpmmTrades(qs_df)
|
| 297 |
+
|
| 298 |
+
# Pearl trades
|
| 299 |
+
pearl_trades_json = _query_omen_xdai_subgraph(
|
| 300 |
+
trader_category="pearl",
|
| 301 |
+
from_timestamp=from_timestamp,
|
| 302 |
+
to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 303 |
+
fpmm_from_timestamp=from_timestamp,
|
| 304 |
+
fpmm_to_timestamp=DEFAULT_TO_TIMESTAMP,
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
print(f"length of the pearl_trades_json dataset {len(pearl_trades_json)}")
|
| 308 |
+
|
| 309 |
+
# convert to dataframe
|
| 310 |
+
pearl_df = pd.DataFrame(pearl_trades_json["data"]["fpmmTrades"])
|
| 311 |
+
pearl_df["market_creator"] = "pearl"
|
| 312 |
+
pearl_df = transform_fpmmTrades(pearl_df)
|
| 313 |
+
|
| 314 |
+
return pd.concat([qs_df, pearl_df], ignore_index=True)
|
| 315 |
+
|
| 316 |
+
|
| 317 |
def prepare_profitalibity_data(
|
| 318 |
rpc: str,
|
| 319 |
tools_filename: str = "tools.parquet",
|
|
|
|
| 548 |
rpc, tools_filename, trades_filename, from_timestamp
|
| 549 |
)
|
| 550 |
tools["trader_address"] = tools["trader_address"].str.lower()
|
| 551 |
+
print(f"List of market creators = {trades["trader_address"].unique()}")
|
| 552 |
|
| 553 |
# all trades profitability df
|
| 554 |
print("Analysing trades...")
|
tabs/trades.py
CHANGED
|
@@ -2,51 +2,96 @@ import gradio as gr
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
|
| 5 |
-
HEIGHT=600
|
| 6 |
-
WIDTH=1000
|
|
|
|
| 7 |
|
| 8 |
def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 9 |
"""Prepares the trades data for analysis."""
|
| 10 |
-
trades_df[
|
| 11 |
-
trades_df[
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
trades_df[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
return trades_df
|
| 16 |
|
| 17 |
|
| 18 |
def get_overall_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 19 |
"""Gets the overall trades data for the given tools and calculates the winning percentage."""
|
| 20 |
-
trades_count = trades_df.groupby(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
trades_count.columns = trades_count.columns.astype(str)
|
| 22 |
-
trades_count.rename(columns={
|
| 23 |
return trades_count
|
| 24 |
|
|
|
|
| 25 |
def get_overall_winning_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 26 |
"""Gets the overall winning trades data for the given tools and calculates the winning percentage."""
|
| 27 |
-
winning_trades =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# winning_trades is a series, give it a dataframe
|
| 29 |
winning_trades = winning_trades.reset_index()
|
| 30 |
winning_trades.columns = winning_trades.columns.astype(str)
|
| 31 |
-
winning_trades.columns = [
|
| 32 |
return winning_trades
|
| 33 |
|
|
|
|
| 34 |
def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlot:
|
| 35 |
"""Plots the trade details for the given trade detail."""
|
| 36 |
if trade_detail == "mech calls":
|
| 37 |
# this is to filter out the data before 2023-09-01
|
| 38 |
-
trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
|
| 39 |
-
trades_filtered =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 41 |
trades_filtered.reset_index(inplace=True)
|
| 42 |
trades_filtered.columns = [
|
| 43 |
"month_year_week",
|
| 44 |
"25th_percentile",
|
| 45 |
"50th_percentile",
|
| 46 |
-
"75th_percentile"
|
| 47 |
]
|
| 48 |
# reformat the data as percentile, date, value
|
| 49 |
-
trades_filtered = trades_filtered.melt(
|
|
|
|
|
|
|
| 50 |
|
| 51 |
return gr.LinePlot(
|
| 52 |
value=trades_filtered,
|
|
@@ -58,22 +103,30 @@ def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlo
|
|
| 58 |
show_actions_button=True,
|
| 59 |
tooltip=["month_year_week", "percentile", "mech_calls"],
|
| 60 |
height=HEIGHT,
|
| 61 |
-
width=WIDTH
|
| 62 |
)
|
| 63 |
-
|
| 64 |
if trade_detail == "collateral amount":
|
| 65 |
-
trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
|
| 66 |
-
trades_filtered =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 68 |
trades_filtered.reset_index(inplace=True)
|
| 69 |
trades_filtered.columns = [
|
| 70 |
"month_year_week",
|
| 71 |
"25th_percentile",
|
| 72 |
"50th_percentile",
|
| 73 |
-
"75th_percentile"
|
| 74 |
]
|
| 75 |
# reformat the data as percentile, date, value
|
| 76 |
-
trades_filtered = trades_filtered.melt(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
return gr.LinePlot(
|
| 79 |
value=trades_filtered,
|
|
@@ -85,22 +138,28 @@ def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlo
|
|
| 85 |
show_actions_button=True,
|
| 86 |
tooltip=["month_year_week", "percentile", "collateral_amount"],
|
| 87 |
height=HEIGHT,
|
| 88 |
-
width=WIDTH
|
| 89 |
)
|
| 90 |
|
| 91 |
if trade_detail == "earnings":
|
| 92 |
-
trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
|
| 93 |
-
trades_filtered =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 95 |
trades_filtered.reset_index(inplace=True)
|
| 96 |
trades_filtered.columns = [
|
| 97 |
"month_year_week",
|
| 98 |
"25th_percentile",
|
| 99 |
"50th_percentile",
|
| 100 |
-
"75th_percentile"
|
| 101 |
]
|
| 102 |
# reformat the data as percentile, date, value
|
| 103 |
-
trades_filtered = trades_filtered.melt(
|
|
|
|
|
|
|
| 104 |
|
| 105 |
return gr.LinePlot(
|
| 106 |
value=trades_filtered,
|
|
@@ -112,22 +171,30 @@ def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlo
|
|
| 112 |
show_actions_button=True,
|
| 113 |
tooltip=["month_year_week", "percentile", "earnings"],
|
| 114 |
height=HEIGHT,
|
| 115 |
-
width=WIDTH
|
| 116 |
)
|
| 117 |
-
|
| 118 |
if trade_detail == "net earnings":
|
| 119 |
-
trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
|
| 120 |
-
trades_filtered =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 122 |
trades_filtered.reset_index(inplace=True)
|
| 123 |
trades_filtered.columns = [
|
| 124 |
"month_year_week",
|
| 125 |
"25th_percentile",
|
| 126 |
"50th_percentile",
|
| 127 |
-
"75th_percentile"
|
| 128 |
]
|
| 129 |
# reformat the data as percentile, date, value
|
| 130 |
-
trades_filtered = trades_filtered.melt(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
return gr.LinePlot(
|
| 133 |
value=trades_filtered,
|
|
@@ -139,22 +206,28 @@ def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlo
|
|
| 139 |
show_actions_button=True,
|
| 140 |
tooltip=["month_year_week", "percentile", "net_earnings"],
|
| 141 |
height=HEIGHT,
|
| 142 |
-
width=WIDTH
|
| 143 |
-
)
|
| 144 |
-
|
| 145 |
if trade_detail == "ROI":
|
| 146 |
-
trades_filtered = trades_df[trades_df["creation_timestamp"] >"2023-09-01"]
|
| 147 |
-
trades_filtered =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 149 |
trades_filtered.reset_index(inplace=True)
|
| 150 |
trades_filtered.columns = [
|
| 151 |
"month_year_week",
|
| 152 |
"25th_percentile",
|
| 153 |
"50th_percentile",
|
| 154 |
-
"75th_percentile"
|
| 155 |
]
|
| 156 |
# reformat the data as percentile, date, value
|
| 157 |
-
trades_filtered = trades_filtered.melt(
|
|
|
|
|
|
|
| 158 |
|
| 159 |
return gr.LinePlot(
|
| 160 |
value=trades_filtered,
|
|
@@ -166,9 +239,32 @@ def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlo
|
|
| 166 |
show_actions_button=True,
|
| 167 |
tooltip=["month_year_week", "percentile", "ROI"],
|
| 168 |
height=HEIGHT,
|
| 169 |
-
width=WIDTH
|
| 170 |
-
)
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
def plot_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 173 |
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
| 174 |
return gr.BarPlot(
|
|
@@ -180,9 +276,27 @@ def plot_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
|
| 180 |
show_actions_button=True,
|
| 181 |
tooltip=["month_year_week", "trades"],
|
| 182 |
height=HEIGHT,
|
| 183 |
-
width=WIDTH
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
)
|
| 185 |
|
|
|
|
| 186 |
def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 187 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
| 188 |
return gr.BarPlot(
|
|
@@ -194,5 +308,22 @@ def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
|
| 194 |
show_actions_button=True,
|
| 195 |
tooltip=["month_year_week", "winning_trade"],
|
| 196 |
height=HEIGHT,
|
| 197 |
-
width=WIDTH
|
| 198 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
|
| 5 |
+
HEIGHT = 600
|
| 6 |
+
WIDTH = 1000
|
| 7 |
+
|
| 8 |
|
| 9 |
def prepare_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 10 |
"""Prepares the trades data for analysis."""
|
| 11 |
+
trades_df["creation_timestamp"] = pd.to_datetime(trades_df["creation_timestamp"])
|
| 12 |
+
trades_df["creation_timestamp"] = trades_df["creation_timestamp"].dt.tz_convert(
|
| 13 |
+
"UTC"
|
| 14 |
+
)
|
| 15 |
+
trades_df["month_year"] = (
|
| 16 |
+
trades_df["creation_timestamp"].dt.to_period("M").astype(str)
|
| 17 |
+
)
|
| 18 |
+
trades_df["month_year_week"] = (
|
| 19 |
+
trades_df["creation_timestamp"].dt.to_period("W").astype(str)
|
| 20 |
+
)
|
| 21 |
+
trades_df["winning_trade"] = trades_df["winning_trade"].astype(int)
|
| 22 |
return trades_df
|
| 23 |
|
| 24 |
|
| 25 |
def get_overall_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 26 |
"""Gets the overall trades data for the given tools and calculates the winning percentage."""
|
| 27 |
+
trades_count = trades_df.groupby("month_year_week").size().reset_index()
|
| 28 |
+
trades_count.columns = trades_count.columns.astype(str)
|
| 29 |
+
trades_count.rename(columns={"0": "trades"}, inplace=True)
|
| 30 |
+
return trades_count
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_overall_by_market_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 34 |
+
"""Gets the overall trades data for the given tools and calculates the winning percentage."""
|
| 35 |
+
trades_count = (
|
| 36 |
+
trades_df.groupby(["market_creator", "month_year_week"]).size().reset_index()
|
| 37 |
+
)
|
| 38 |
trades_count.columns = trades_count.columns.astype(str)
|
| 39 |
+
trades_count.rename(columns={"0": "trades"}, inplace=True)
|
| 40 |
return trades_count
|
| 41 |
|
| 42 |
+
|
| 43 |
def get_overall_winning_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 44 |
"""Gets the overall winning trades data for the given tools and calculates the winning percentage."""
|
| 45 |
+
winning_trades = (
|
| 46 |
+
trades_df.groupby(["month_year_week"])["winning_trade"].sum()
|
| 47 |
+
/ trades_df.groupby(["month_year_week"])["winning_trade"].count()
|
| 48 |
+
* 100
|
| 49 |
+
)
|
| 50 |
+
# winning_trades is a series, give it a dataframe
|
| 51 |
+
winning_trades = winning_trades.reset_index()
|
| 52 |
+
winning_trades.columns = winning_trades.columns.astype(str)
|
| 53 |
+
winning_trades.columns = ["month_year_week", "winning_trade"]
|
| 54 |
+
return winning_trades
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def get_overall_winning_by_market_trades(trades_df: pd.DataFrame) -> pd.DataFrame:
|
| 58 |
+
"""Gets the overall winning trades data for the given tools and calculates the winning percentage."""
|
| 59 |
+
winning_trades = (
|
| 60 |
+
trades_df.groupby(["market_creator", "month_year_week"])["winning_trade"].sum()
|
| 61 |
+
/ trades_df.groupby(["market_creator", "month_year_week"])[
|
| 62 |
+
"winning_trade"
|
| 63 |
+
].count()
|
| 64 |
+
* 100
|
| 65 |
+
)
|
| 66 |
# winning_trades is a series, give it a dataframe
|
| 67 |
winning_trades = winning_trades.reset_index()
|
| 68 |
winning_trades.columns = winning_trades.columns.astype(str)
|
| 69 |
+
winning_trades.columns = ["market_creator", "month_year_week", "winning_trade"]
|
| 70 |
return winning_trades
|
| 71 |
|
| 72 |
+
|
| 73 |
def plot_trade_details(trade_detail: str, trades_df: pd.DataFrame) -> gr.LinePlot:
|
| 74 |
"""Plots the trade details for the given trade detail."""
|
| 75 |
if trade_detail == "mech calls":
|
| 76 |
# this is to filter out the data before 2023-09-01
|
| 77 |
+
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
| 78 |
+
trades_filtered = (
|
| 79 |
+
trades_filtered.groupby("month_year_week")["num_mech_calls"]
|
| 80 |
+
.quantile([0.25, 0.5, 0.75])
|
| 81 |
+
.unstack()
|
| 82 |
+
)
|
| 83 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 84 |
trades_filtered.reset_index(inplace=True)
|
| 85 |
trades_filtered.columns = [
|
| 86 |
"month_year_week",
|
| 87 |
"25th_percentile",
|
| 88 |
"50th_percentile",
|
| 89 |
+
"75th_percentile",
|
| 90 |
]
|
| 91 |
# reformat the data as percentile, date, value
|
| 92 |
+
trades_filtered = trades_filtered.melt(
|
| 93 |
+
id_vars=["month_year_week"], var_name="percentile", value_name="mech_calls"
|
| 94 |
+
)
|
| 95 |
|
| 96 |
return gr.LinePlot(
|
| 97 |
value=trades_filtered,
|
|
|
|
| 103 |
show_actions_button=True,
|
| 104 |
tooltip=["month_year_week", "percentile", "mech_calls"],
|
| 105 |
height=HEIGHT,
|
| 106 |
+
width=WIDTH,
|
| 107 |
)
|
| 108 |
+
|
| 109 |
if trade_detail == "collateral amount":
|
| 110 |
+
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
| 111 |
+
trades_filtered = (
|
| 112 |
+
trades_filtered.groupby("month_year_week")["collateral_amount"]
|
| 113 |
+
.quantile([0.25, 0.5, 0.75])
|
| 114 |
+
.unstack()
|
| 115 |
+
)
|
| 116 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 117 |
trades_filtered.reset_index(inplace=True)
|
| 118 |
trades_filtered.columns = [
|
| 119 |
"month_year_week",
|
| 120 |
"25th_percentile",
|
| 121 |
"50th_percentile",
|
| 122 |
+
"75th_percentile",
|
| 123 |
]
|
| 124 |
# reformat the data as percentile, date, value
|
| 125 |
+
trades_filtered = trades_filtered.melt(
|
| 126 |
+
id_vars=["month_year_week"],
|
| 127 |
+
var_name="percentile",
|
| 128 |
+
value_name="collateral_amount",
|
| 129 |
+
)
|
| 130 |
|
| 131 |
return gr.LinePlot(
|
| 132 |
value=trades_filtered,
|
|
|
|
| 138 |
show_actions_button=True,
|
| 139 |
tooltip=["month_year_week", "percentile", "collateral_amount"],
|
| 140 |
height=HEIGHT,
|
| 141 |
+
width=WIDTH,
|
| 142 |
)
|
| 143 |
|
| 144 |
if trade_detail == "earnings":
|
| 145 |
+
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
| 146 |
+
trades_filtered = (
|
| 147 |
+
trades_filtered.groupby("month_year_week")["earnings"]
|
| 148 |
+
.quantile([0.25, 0.5, 0.75])
|
| 149 |
+
.unstack()
|
| 150 |
+
)
|
| 151 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 152 |
trades_filtered.reset_index(inplace=True)
|
| 153 |
trades_filtered.columns = [
|
| 154 |
"month_year_week",
|
| 155 |
"25th_percentile",
|
| 156 |
"50th_percentile",
|
| 157 |
+
"75th_percentile",
|
| 158 |
]
|
| 159 |
# reformat the data as percentile, date, value
|
| 160 |
+
trades_filtered = trades_filtered.melt(
|
| 161 |
+
id_vars=["month_year_week"], var_name="percentile", value_name="earnings"
|
| 162 |
+
)
|
| 163 |
|
| 164 |
return gr.LinePlot(
|
| 165 |
value=trades_filtered,
|
|
|
|
| 171 |
show_actions_button=True,
|
| 172 |
tooltip=["month_year_week", "percentile", "earnings"],
|
| 173 |
height=HEIGHT,
|
| 174 |
+
width=WIDTH,
|
| 175 |
)
|
| 176 |
+
|
| 177 |
if trade_detail == "net earnings":
|
| 178 |
+
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
| 179 |
+
trades_filtered = (
|
| 180 |
+
trades_filtered.groupby("month_year_week")["net_earnings"]
|
| 181 |
+
.quantile([0.25, 0.5, 0.75])
|
| 182 |
+
.unstack()
|
| 183 |
+
)
|
| 184 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 185 |
trades_filtered.reset_index(inplace=True)
|
| 186 |
trades_filtered.columns = [
|
| 187 |
"month_year_week",
|
| 188 |
"25th_percentile",
|
| 189 |
"50th_percentile",
|
| 190 |
+
"75th_percentile",
|
| 191 |
]
|
| 192 |
# reformat the data as percentile, date, value
|
| 193 |
+
trades_filtered = trades_filtered.melt(
|
| 194 |
+
id_vars=["month_year_week"],
|
| 195 |
+
var_name="percentile",
|
| 196 |
+
value_name="net_earnings",
|
| 197 |
+
)
|
| 198 |
|
| 199 |
return gr.LinePlot(
|
| 200 |
value=trades_filtered,
|
|
|
|
| 206 |
show_actions_button=True,
|
| 207 |
tooltip=["month_year_week", "percentile", "net_earnings"],
|
| 208 |
height=HEIGHT,
|
| 209 |
+
width=WIDTH,
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
if trade_detail == "ROI":
|
| 213 |
+
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
| 214 |
+
trades_filtered = (
|
| 215 |
+
trades_filtered.groupby("month_year_week")["roi"]
|
| 216 |
+
.quantile([0.25, 0.5, 0.75])
|
| 217 |
+
.unstack()
|
| 218 |
+
)
|
| 219 |
trades_filtered.columns = trades_filtered.columns.astype(str)
|
| 220 |
trades_filtered.reset_index(inplace=True)
|
| 221 |
trades_filtered.columns = [
|
| 222 |
"month_year_week",
|
| 223 |
"25th_percentile",
|
| 224 |
"50th_percentile",
|
| 225 |
+
"75th_percentile",
|
| 226 |
]
|
| 227 |
# reformat the data as percentile, date, value
|
| 228 |
+
trades_filtered = trades_filtered.melt(
|
| 229 |
+
id_vars=["month_year_week"], var_name="percentile", value_name="ROI"
|
| 230 |
+
)
|
| 231 |
|
| 232 |
return gr.LinePlot(
|
| 233 |
value=trades_filtered,
|
|
|
|
| 239 |
show_actions_button=True,
|
| 240 |
tooltip=["month_year_week", "percentile", "ROI"],
|
| 241 |
height=HEIGHT,
|
| 242 |
+
width=WIDTH,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def plot_average_roi_per_market_by_week(trades_df: pd.DataFrame) -> gr.LinePlot:
|
| 247 |
+
|
| 248 |
+
mean_roi_per_market_by_week = (
|
| 249 |
+
trades_df.groupby(["market_creator", "month_year_week"])["roi"]
|
| 250 |
+
.mean()
|
| 251 |
+
.reset_index()
|
| 252 |
+
)
|
| 253 |
+
mean_roi_per_market_by_week.rename(columns={"roi": "mean_roi"}, inplace=True)
|
| 254 |
+
return gr.LinePlot(
|
| 255 |
+
value=mean_roi_per_market_by_week,
|
| 256 |
+
x="month_year_week",
|
| 257 |
+
y="ROI",
|
| 258 |
+
color="market_creator",
|
| 259 |
+
show_label=True,
|
| 260 |
+
interactive=True,
|
| 261 |
+
show_actions_button=True,
|
| 262 |
+
tooltip=["month_year_week", "market_creator", "mean_roi"],
|
| 263 |
+
height=HEIGHT,
|
| 264 |
+
width=WIDTH,
|
| 265 |
+
)
|
| 266 |
+
|
| 267 |
+
|
| 268 |
def plot_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 269 |
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
| 270 |
return gr.BarPlot(
|
|
|
|
| 276 |
show_actions_button=True,
|
| 277 |
tooltip=["month_year_week", "trades"],
|
| 278 |
height=HEIGHT,
|
| 279 |
+
width=WIDTH,
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
def plot_trades_per_market_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 284 |
+
"""Plots the trades data for the given tools and calculates the winning percentage."""
|
| 285 |
+
assert "market_creator" in trades_df.columns
|
| 286 |
+
return gr.BarPlot(
|
| 287 |
+
value=trades_df,
|
| 288 |
+
x="month_year_week",
|
| 289 |
+
y="trades",
|
| 290 |
+
color="market_creator",
|
| 291 |
+
show_label=True,
|
| 292 |
+
interactive=True,
|
| 293 |
+
show_actions_button=True,
|
| 294 |
+
tooltip=["month_year_week", "trades"],
|
| 295 |
+
height=HEIGHT,
|
| 296 |
+
width=WIDTH,
|
| 297 |
)
|
| 298 |
|
| 299 |
+
|
| 300 |
def plot_winning_trades_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 301 |
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
| 302 |
return gr.BarPlot(
|
|
|
|
| 308 |
show_actions_button=True,
|
| 309 |
tooltip=["month_year_week", "winning_trade"],
|
| 310 |
height=HEIGHT,
|
| 311 |
+
width=WIDTH,
|
| 312 |
+
)
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
def plot_winning_trades_per_market_by_week(trades_df: pd.DataFrame) -> gr.BarPlot:
|
| 316 |
+
"""Plots the winning trades data for the given tools and calculates the winning percentage."""
|
| 317 |
+
assert "market_creator" in trades_df.columns
|
| 318 |
+
return gr.BarPlot(
|
| 319 |
+
value=trades_df,
|
| 320 |
+
x="month_year_week",
|
| 321 |
+
y="winning_trade",
|
| 322 |
+
color="market_creator",
|
| 323 |
+
show_label=True,
|
| 324 |
+
interactive=True,
|
| 325 |
+
show_actions_button=True,
|
| 326 |
+
tooltip=["month_year_week", "winning_trade"],
|
| 327 |
+
height=HEIGHT,
|
| 328 |
+
width=WIDTH,
|
| 329 |
+
)
|