sf_quant.research.run_ff_regression#
- sf_quant.research.run_ff_regression(portfolio_returns: PortfolioRetSchema) DataFrame#
Run a Fama-French 5-factor regression on a single portfolio’s returns.
Regresses portfolio excess returns (return minus risk-free rate) against the Fama-French 5 factors using OLS. Factors are shifted by -1 day so that today’s return is explained by yesterday’s factor realizations.
Parameters#
- portfolio_returnsPortfolioRetSchema
Portfolio returns containing:
date(date): The observation date.return(float): Daily portfolio return.
Returns#
- pl.DataFrame
Regression summary with columns:
variable(str): Factor name (Intercept, mkt_rf, smb, hml, rmw, cma).coefficient(float): OLS coefficient estimate.tstat(float): T-statistic for the coefficient.
Notes#
Factors are loaded automatically from the date range in portfolio_returns.
Returns and factors are scaled to daily percent (×100) before regression.
Factor values are lagged by one day (shift(-1)) prior to joining.
Examples#
>>> import polars as pl >>> import sf_quant.research as sfr >>> import datetime as dt >>> ports = pl.DataFrame({ ... 'date': [dt.date(2024, 1, i) for i in range(2, 101)], ... 'return': [0.001] * 99, ... }) >>> sfr.run_ff_regression(ports) shape: (6, 3) ┌───────────┬─────────────┬─────────┐ │ variable ┆ coefficient ┆ tstat │ │ --- ┆ --- ┆ --- │ │ str ┆ f64 ┆ f64 │ ╞═══════════╪═════════════╪═════════╡ │ Intercept ┆ 0.0521 ┆ 2.134 │ │ mkt_rf ┆ 0.9876 ┆ 15.432 │ │ smb ┆ 0.1234 ┆ 2.341 │ │ hml ┆ -0.0987 ┆ -1.876 │ │ rmw ┆ 0.0543 ┆ 1.023 │ │ cma ┆ -0.0321 ┆ -0.612 │ └───────────┴─────────────┴─────────┘