sf_quant.performance.get_turnover_stats#
- sf_quant.performance.get_turnover_stats(weights: DataFrame) DataFrame#
Compute summary statistics for two-sided portfolio turnover.
Calculates the rolling 252-day mean two-sided turnover and summarises it with mean, min, and max statistics.
Parameters#
- weightspl.DataFrame
Portfolio weights containing:
date(date): The observation date.barrid(str): Security identifier.weight(float): Portfolio weight.
Returns#
- pl.DataFrame
Summary statistics with columns:
Mean Turnover(float): Mean of the rolling two-sided turnover.Min Turnover(float): Minimum of the rolling two-sided turnover.Max Turnover(float): Maximum of the rolling two-sided turnover.
Notes#
Two-sided turnover is the sum of absolute weight changes per date.
Rolling window is 252 trading days.
Null values (warm-up period) are excluded from summary statistics.
Examples#
>>> import polars as pl >>> import sf_quant.performance as sfp >>> import datetime as dt >>> weights = pl.DataFrame({ ... 'date': [dt.date(2024, 1, i) for i in range(2, 6)], ... 'barrid': ['A'] * 4, ... 'weight': [0.5, 0.6, 0.4, 0.5], ... }) >>> sfp.get_turnover_stats(weights) shape: (1, 3) ┌───────────────┬───────────────┬───────────────┐ │ Mean Turnover ┆ Min Turnover ┆ Max Turnover │ │ --- ┆ --- ┆ --- │ │ f64 ┆ f64 ┆ f64 │ ╞═══════════════╪═══════════════╪═══════════════╡ │ 0.15 ┆ 0.1 ┆ 0.2 │ └───────────────┴───────────────┴───────────────┘