Skip to content

contango.trading.analysis.graphing.parallel_coordinates

contango.trading.analysis.graphing.parallel_coordinates

ParallelCoordinates

ParallelCoordinates(config: C)

Bases: GraphType[ParallelCoordinatesConfig]

A graph type that shows parameter combinations across all swept parameters.

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 parallel coordinates plot across all swept parameters.

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\parallel_coordinates.py
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
def build(self, df: pd.DataFrame) -> go.Figure:
    """
    Builds the parallel coordinates plot across all swept parameters.

    Args:
        df: The experiment DataFrame.

    Returns:
        A plotly Figure.
    """
    plot_df = df.dropna(subset=self.config.param_columns + [self.config.target_metric]).copy()

    if self.config.sample_size is not None and len(plot_df) > self.config.sample_size:
        plot_df = plot_df.sample(self.config.sample_size, random_state=42)

    dimensions = self.config.param_columns + [self.config.target_metric]

    fig = px.parallel_coordinates(  # type: ignore[unknownMemberType]
        plot_df,
        dimensions=dimensions,
        color=self.config.target_metric,
        color_continuous_scale=px.colors.diverging.RdYlGn,
        title=f"Parameter Combinations: Parallel Coordinates colored by {self.config.target_metric}",
    )
    fig.update_layout()  # type: ignore[unknownMemberType]
    return fig

ParallelCoordinatesConfig dataclass

ParallelCoordinatesConfig(param_columns: list[str], target_metric: str = 'calmar_ratio', sample_size: int | None = None)

Bases: GraphConfig

A graph configuration specific to the parallel coordinates graph.

Attributes:

Name Type Description
param_columns list[str]

The parameter columns to include as axes.

target_metric str

The name for the targeted metric used as the final axis and the color scale.

sample_size int | None

The maximum amount of experiments to plot.