MCPcopy Create free account
hub / github.com/Open-Quant/openquant / to_polars_backtest_frame

Function to_polars_backtest_frame

python/openquant/adapters.py:111–125  ·  view source on GitHub ↗
(
    timestamps: Sequence[str],
    equity_curve: Sequence[float],
    returns: Sequence[float] | None = None,
    positions: Sequence[float] | None = None,
)

Source from the content-addressed store, hash-verified

109
110
111def to_polars_backtest_frame(
112 timestamps: Sequence[str],
113 equity_curve: Sequence[float],
114 returns: Sequence[float] | None = None,
115 positions: Sequence[float] | None = None,
116) -> pl.DataFrame:
117 _validate_equal_length("timestamps", timestamps, "equity_curve", equity_curve)
118 data: dict[str, object] = {"ts": list(timestamps), "equity": list(equity_curve)}
119 if returns is not None:
120 _validate_equal_length("timestamps", timestamps, "returns", returns)
121 data["returns"] = list(returns)
122 if positions is not None:
123 _validate_equal_length("timestamps", timestamps, "positions", positions)
124 data["position"] = list(positions)
125 return pl.DataFrame(data).with_columns(pl.col("ts").str.strptime(pl.Datetime, strict=False))
126
127
128@dataclass

Callers

nothing calls this directly

Calls 1

_validate_equal_lengthFunction · 0.85

Tested by

no test coverage detected