def visualize_strategy_stats()

in src/backend/domain/services/charts.py [0:0]


def visualize_strategy_stats(strategy_stats, title, num_cols, periodicity):
    num_plots = 3
    thickness = get_thickness(num_plots)
    vertical_spacing = get_vertical_spacing(thickness)

    title = "strategy"
    fig = make_subplots(
        rows=3,
        cols=1,
        subplot_titles=[title + ".pnl", title + ".market_value", title + ".gross_value"],
        horizontal_spacing=0.1,
        vertical_spacing=vertical_spacing,
        shared_xaxes=False,
    )
    value = strategy_stats["acct_ccy_pnl"]

    fig.add_trace(
        go.Scatter(x=value.index, y=value.values, name="pnl"),
        row=1,
        col=1,
    )
    acc_value = strategy_stats["acct_ccy_value"]

    fig.add_trace(
        go.Scatter(x=acc_value.index, y=acc_value.values, name="market_value"),
        row=2,
        col=1,
    )
    gross_value = strategy_stats["gross_value"]

    fig.add_trace(
        go.Scatter(x=gross_value.index, y=gross_value.values, name="gross_value"),
        row=3,
        col=1,
    )

    simple_updatemenus = []
    for i in range(3):
        simple_updatemenus.append(
            dict(
                buttons=list(
                    [
                        dict(
                            args=[
                                {
                                    "type": ["scatter"],
                                    "x": [fig.data[i]["x"]],
                                },
                                {
                                    ("yaxis%d.type" % (i + 1) if i != 0 else "yaxis.type"): "linear",
                                    ("xaxis%d.type" % (i + 1) if i != 0 else "xaxis.type"): "date",
                                },
                                [
                                    i,
                                ],
                            ],
                            label="Line plot",
                            method="update",
                        ),
                        dict(
                            args=[
                                {
                                    "type": ["scatter"],
                                    "x": [fig.data[i]["x"]],
                                },
                                {
                                    ("yaxis%d.type" % (i + 1) if i != 0 else "yaxis.type"): "log",
                                    ("xaxis%d.type" % (i + 1) if i != 0 else "xaxis.type"): "date",
                                },
                                [i],
                            ],
                            label="Log plot",
                            method="update",
                        ),
                        dict(
                            args=[
                                {"type": ["histogram"], "x": [None]},
                                {
                                    ("yaxis%d.type" % (i + 1) if i != 0 else "yaxis.type"): "linear",
                                    ("xaxis%d.type" % (i + 1) if i != 0 else "xaxis.type"): "category",
                                },
                                [i],
                            ],
                            label="Histogram plot",
                            method="update",
                        ),
                    ]
                ),
                direction="down",
                showactive=True,
                xanchor="left",
                y=get_update_menus_position(vertical_spacing, 3, i),
                x=0,
            ),
        )

    fig.update_layout(
        updatemenus=simple_updatemenus,
        legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
        margin=dict(l=0, r=30, t=20, b=0),
        # title=title,
        width=650 * 1 / num_cols,
        height=400,
    )

    n_iter = (value.index.shape[0] - 1) // 5 + 1
    ttext = value.index[::n_iter].tolist()
    if periodicity == "1day":
        for index, date in enumerate(ttext):
            ttext[index] = date.strftime("%Y-%m-%d")

    fig.for_each_xaxis(lambda x: x.update(type="date", rangeslider={"thickness": thickness, "yaxis": {"rangemode": "auto"}}))

    return [fig]