Skip to content

contango.trading.analysis.graphing.trade_quality_scatter

contango.trading.analysis.graphing.trade_quality_scatter

TradeQualityScatter

TradeQualityScatter(config: C)

Bases: GraphType[TradeQualityScatterConfig]

A graph type that shows the trade-quality scatter plot.

Source code in src\contango\trading\analysis\graph_type.py
26
27
28
29
30
31
32
33
def __init__(self, config: C) -> None:
    """
    Initializes `GraphType`.

    Args:
        config: The matching configuration for the graph type.
    """
    self._config = config

build

build(df: DataFrame) -> go.Figure

Builds the trade-quality scatter plot.

Parameters:

Name Type Description Default
df DataFrame

The experiment DataFrame.

required

Returns:

Type Description
Figure

A plotly Figure.

Source code in src\contango\trading\analysis\graphing\trade_quality_scatter.py
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def build(self, df: pd.DataFrame) -> go.Figure:
    """
    Builds the trade-quality scatter plot.

    Args:
        df: The experiment DataFrame.

    Returns:
        A plotly Figure.
    """
    plot_df = df.dropna(subset=["win_rate", self.config.y_metric, "trade_count", self.config.color_by]).copy()

    fig = px.scatter(   # type: ignore[unknownMemberType]
        plot_df,
        x="win_rate",
        y=self.config.y_metric,
        size="trade_count",
        color=self.config.color_by,
        hover_name="name",
        title=f"Trade quality: win rate vs. {self.config.y_metric}, bubble size = trade count",
        labels={"win_rate": "Win Rate"},
    )
    fig.update_layout(xaxis_tickformat=".0%")  # type: ignore[unknownMemberType]
    return fig

TradeQualityScatterConfig dataclass

TradeQualityScatterConfig(y_metric: str = 'profit_factor', color_by: str = 'calmar_ratio')

Bases: GraphConfig

A graph configuration specific to the trade quality scatter graph.

Attributes:

Name Type Description
y_metric str

The metric for the y-axis.

color_by str

The column to color points by, defaults to "calmar_ratio".