cyberosa
gap decimals and filter of trades
d125423
raw
history blame
5.03 kB
from datetime import datetime
import gradio as gr
import pandas as pd
import duckdb
import logging
from tabs.tokens_votes_dist import (
get_based_tokens_distribution,
get_based_votes_distribution,
get_extreme_cases,
)
from tabs.dist_gap import (
get_distribution_plot,
get_correlation_map,
get_kde_with_trades,
get_regplot_with_mean_trade_size,
)
def get_logger():
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
# stream handler and formatter
stream_handler = logging.StreamHandler()
stream_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
stream_handler.setFormatter(formatter)
logger.addHandler(stream_handler)
return logger
logger = get_logger()
def prepare_data():
"""
Get all data from the parquet files
"""
logger.info("Getting all data")
con = duckdb.connect(":memory:")
# Query to fetch invalid trades data
query = f"""
SELECT *
FROM read_parquet('./live_data/markets_live_data.parquet')
"""
df = con.execute(query).fetchdf()
df["sample_datetime"] = df["sample_timestamp"].apply(
lambda x: datetime.fromtimestamp(x)
)
df["opening_datetime"] = df["openingTimestamp"].apply(
lambda x: datetime.fromtimestamp(int(x))
)
df["days_to_resolution"] = (df["opening_datetime"] - df["sample_datetime"]).dt.days
return df
demo = gr.Blocks()
markets_data = prepare_data()
live_markets_data = markets_data.loc[markets_data["open"] == True]
# filter only those with trades
markets_data = markets_data.loc[markets_data["total_trades"] > 0]
with demo:
gr.HTML("<h1>Olas Predict Live Markets </h1>")
gr.Markdown("This app shows the distributions of predictions on the live markets.")
best_market_id, best_gap, worst_market_id, worst_gap = get_extreme_cases(
live_markets_data
)
with gr.Tabs():
with gr.TabItem("๐Ÿ’น Probability distributions of live markets"):
with gr.Row():
gr.Markdown("Best case: a market with a low gap between distributions")
with gr.Row():
gr.Markdown(
f"Market id = {best_market_id} Dist gap = {round(best_gap,2)}"
)
with gr.Row():
with gr.Column(min_width=350):
gr.Markdown("# Evolution of outcomes probability based on tokens")
best_market_tokens_dist = get_based_tokens_distribution(
best_market_id, live_markets_data
)
with gr.Column(min_width=350):
gr.Markdown("# Evolution of outcomes probability based on votes")
best_market_votes_dist = get_based_votes_distribution(
best_market_id, live_markets_data
)
with gr.Row():
gr.Markdown("Worst case: a market with a high distribution gap metric")
with gr.Row():
gr.Markdown(
f"Market id = {worst_market_id} Dist gap = {round(worst_gap,2)}"
)
with gr.Row():
with gr.Column(min_width=350):
# gr.Markdown("# Evolution of outcomes probability based on tokens")
worst_market_tokens_dist = get_based_tokens_distribution(
worst_market_id, live_markets_data
)
with gr.Column(min_width=350):
worst_market_votes_dist = get_based_votes_distribution(
worst_market_id, live_markets_data
)
with gr.TabItem("๐Ÿ“ Distribution gap metric"):
# remove samples with no trades
with gr.Row():
gr.Markdown(
"This metric measures the difference between the probability distribution based on the tokens distribution and the one based on the votes distribution"
)
with gr.Row():
gr.Markdown("# Density distribution")
with gr.Row():
kde_plot = get_distribution_plot(markets_data)
with gr.Row():
gr.Markdown("# Relationship with number of trades")
with gr.Row():
kde_trades_plot = get_kde_with_trades(markets_data)
# with gr.Row():
# gr.Markdown(
# "# Relationship with mean trade size of the market (bet amount in USD)"
# )
# with gr.Row():
# reg_plot = get_regplot_with_mean_trade_size(markets_data)
with gr.Row():
gr.Markdown(
"# Correlation analysis between the metric and market variables"
)
with gr.Row():
correlation_plot = get_correlation_map(markets_data)
demo.queue(default_concurrency_limit=40).launch()