跳转至

RollingEngine

Batch rolling metric computation in a single call.

Usage

from fincore.core.engine import RollingEngine

engine = RollingEngine(returns, factor_returns=benchmark, window=60)
results = engine.compute(['sharpe', 'volatility', 'max_drawdown', 'beta'])

for name, series in results.items():
    print(f"{name}: {len(series)} observations")

Available Metrics

  • sharpe — Rolling Sharpe ratio
  • volatility — Rolling annualized volatility
  • max_drawdown — Rolling maximum drawdown (vectorized)
  • beta — Rolling beta vs benchmark (requires factor_returns)
  • sortino — Rolling Sortino ratio
  • mean_return — Rolling annualized mean return

API Reference

fincore.core.engine.RollingEngine(returns, *, factor_returns=None, window=252, period=DAILY)

Batch rolling metric computation engine.

参数:

名称 类型 描述 默认
returns Series

Non-cumulative simple returns with a DatetimeIndex.

必需
factor_returns Series

Benchmark returns (required for beta).

None
window int

Rolling window size. Default 252 (approx. 1 year of daily data).

252
period str

Data frequency. Default DAILY.

DAILY

available_metrics property

Return the set of metric names supported by this engine.

compute(metrics='all')

Compute the requested rolling metrics.

参数:

名称 类型 描述 默认
metrics list of str or ``'all'``

Which metrics to compute. Pass 'all' to compute every available metric.

'all'

返回:

类型 描述
dict[str, Series]

Mapping from metric name to rolling values.