File size: 2,925 Bytes
c9eef1d
 
 
 
 
 
 
 
a46bb55
c9eef1d
 
 
 
 
 
773f144
 
 
 
a46bb55
 
 
 
17301f4
a46bb55
773f144
 
 
 
a46bb55
 
 
 
4fd6aee
17301f4
a46bb55
 
 
79bdafd
1c548c3
1b041d1
79bdafd
 
 
 
a46bb55
 
 
79bdafd
 
 
 
 
 
a46bb55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e22f08e
a46bb55
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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"""
    # A kernel density estimate (KDE) plot is a method for visualizing the distribution of
    # observations in a dataset, analogous to a histogram. KDE represents the data using a
    # continuous probability density curve in one or more dimensions.
    sns.set_theme(palette="viridis")
    plt.figure(figsize=(10, 5))

    plot = sns.kdeplot(markets_data, x="dist_gap_perc", fill=True)
    # TODO Add title and labels
    # Display the plot using gr.Plot
    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]

    # Compute the correlation matrix
    correlation_matrix = data.corr()

    # Create the heatmap
    heatmap = sns.heatmap(
        correlation_matrix,
        annot=True,  # Show the correlation values
        cmap="coolwarm",  # Color scheme
        vmin=-1,
        vmax=1,  # Set the range of values
        center=0,  # Center the colormap at 0
        square=True,  # Make each cell square-shaped
        linewidths=0.5,  # Add lines between cells
        cbar_kws={"shrink": 0.8},
    )  # Adjust the size of the colorbar

    # Set the title
    plt.title("Correlation Heatmap")

    # Rotate the y-axis labels for better readability
    plt.yticks(rotation=0)

    # Show the plot
    plt.tight_layout()
    return gr.Plot(value=heatmap.get_figure())