|
import pandas as pd |
|
import gradio as gr |
|
import matplotlib.pyplot as plt |
|
import seaborn as sns |
|
from seaborn import FacetGrid |
|
import plotly.express as px |
|
|
|
|
|
def get_top_best_behaviour_markets(markets_data: pd.DataFrame): |
|
"""Function to paint the top markets with the lowest metric of distribution gap""" |
|
sorted_data = markets_data.sort_values(by="dist_gap_perc", ascending=False) |
|
top_best_markets = sorted_data[["title", "sample_datetime", "dist_gap_perc"]].head( |
|
5 |
|
) |
|
return gr.DataFrame(top_best_markets) |
|
|
|
|
|
def get_distribution_plot(markets_data: pd.DataFrame): |
|
"""Function to paint the density plot of the metric distribution gap percentage""" |
|
|
|
|
|
|
|
sns.set_theme(palette="viridis") |
|
plt.figure(figsize=(10, 5)) |
|
|
|
plot = sns.kdeplot(markets_data, x="dist_gap_perc", fill=True) |
|
|
|
|
|
return gr.Plot(value=plot.get_figure()) |
|
|
|
|
|
def get_kde_with_trades(markets_data: pd.DataFrame): |
|
"""Function to paint the density plot of the metric in terms of the number of trades""" |
|
plot = sns.kdeplot(markets_data, x="dist_gap_perc", y="total_trades", fill=True) |
|
plt.ylabel("Total number of trades per market") |
|
return gr.Plot(value=plot.get_figure()) |
|
|
|
|
|
def get_regplot_with_mean_trade_size(markets_data: pd.DataFrame): |
|
"""Function to Plot data and a linear regression model fit between the metric and the mean trade size""" |
|
regplot = sns.regplot(markets_data, x="dist_gap_perc", y="mean_trade_size") |
|
plt.ylabel("Mean trade size in USD") |
|
return gr.Plot(value=regplot.get_figure()) |
|
|
|
|
|
def get_correlation_map(markets_data: pd.DataFrame): |
|
"""Function to paint the correlation between different variables""" |
|
|
|
columns_of_interest = [ |
|
"total_trades", |
|
"dist_gap_perc", |
|
"liquidityMeasure", |
|
"mean_trade_size", |
|
] |
|
data = markets_data[columns_of_interest] |
|
|
|
|
|
correlation_matrix = data.corr() |
|
|
|
|
|
heatmap = sns.heatmap( |
|
correlation_matrix, |
|
annot=True, |
|
cmap="coolwarm", |
|
vmin=-1, |
|
vmax=1, |
|
center=0, |
|
square=True, |
|
linewidths=0.5, |
|
cbar_kws={"shrink": 0.8}, |
|
) |
|
|
|
|
|
plt.title("Correlation Heatmap") |
|
|
|
|
|
plt.yticks(rotation=0) |
|
|
|
|
|
plt.tight_layout() |
|
return gr.Plot(value=heatmap.get_figure()) |
|
|