Alpha API¶
asrquant.alpha ¶
Cross-sectional alpha research and signal diagnostics.
The functions in this module are deliberately model-agnostic. They help turn an arbitrary cross-sectional score into an auditable research object: cleaned signals, forward returns, information coefficients, quantile portfolios, long-short returns, and turnover.
All transforms are performed within a timestamp unless documented otherwise, which avoids leaking future cross-sections into the current observation.
AlphaResearchReport
dataclass
¶
Compact, inspectable output of a cross-sectional signal study.
Source code in src/asrquant/alpha.py
winsorize_cross_section ¶
winsorize_cross_section(signal: DataFrame, lower: float = 0.01, upper: float = 0.99) -> pd.DataFrame
Winsorize each timestamp independently using cross-sectional quantiles.
Source code in src/asrquant/alpha.py
cross_sectional_zscore ¶
cross_sectional_zscore(signal: DataFrame, *, ddof: int = 0, clip: float | None = None) -> pd.DataFrame
Standardize each timestamp across assets.
Rows with zero cross-sectional dispersion are mapped to zero for the finite observations in that row. Missing values remain missing.
Source code in src/asrquant/alpha.py
cross_sectional_rank ¶
Rank assets independently at each timestamp.
Source code in src/asrquant/alpha.py
neutralize_cross_section ¶
neutralize_cross_section(signal: DataFrame, exposures: Mapping[str, DataFrame], *, add_constant: bool = True, min_assets: int | None = None) -> pd.DataFrame
Remove linear cross-sectional exposure to one or more characteristics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal
|
DataFrame
|
Date x asset score matrix. |
required |
exposures
|
Mapping[str, DataFrame]
|
Mapping from exposure name to a Date x asset matrix, for example
|
required |
add_constant
|
bool
|
Include a cross-sectional intercept. |
True
|
min_assets
|
int | None
|
Minimum complete observations required at a timestamp. By default the number of regressors plus two is used. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Cross-sectional OLS residuals with the same shape as |
Source code in src/asrquant/alpha.py
forward_returns ¶
forward_returns(prices: DataFrame, periods: int | Iterable[int] = (1, 5, 21), *, log: bool = False) -> dict[int, pd.DataFrame]
Compute future returns from time t to t+h without shifting signals.
The return labelled at time t uses price[t+h] / price[t]. The final
h observations are therefore missing by construction.
Source code in src/asrquant/alpha.py
information_coefficient ¶
information_coefficient(signal: DataFrame, forward_return: DataFrame, *, method: str = 'spearman', min_assets: int = 5) -> pd.Series
Cross-sectional correlation between a signal and a future return.
Source code in src/asrquant/alpha.py
ic_decay ¶
ic_decay(signal: DataFrame, prices: DataFrame, horizons: Iterable[int] = (1, 5, 10, 21), *, method: str = 'spearman', min_assets: int = 5) -> pd.DataFrame
Summarize information-coefficient decay across future horizons.
Source code in src/asrquant/alpha.py
quantile_portfolio_returns ¶
quantile_portfolio_returns(signal: DataFrame, forward_return: DataFrame, *, quantiles: int = 5, min_assets: int | None = None) -> pd.DataFrame
Equal-weight future returns for cross-sectional signal quantiles.
Source code in src/asrquant/alpha.py
long_short_return ¶
Return top-minus-bottom quantile performance.
Source code in src/asrquant/alpha.py
signal_to_weights ¶
signal_to_weights(signal: DataFrame, *, gross: float = 1.0, dollar_neutral: bool = True, max_abs_weight: float | None = None) -> pd.DataFrame
Convert continuous scores into normalized portfolio weights.
Dollar-neutral weights are demeaned cross-sectionally before gross scaling.
Long-only-style usage can set dollar_neutral=False; negative signals are
then allowed and are simply gross-normalized.
Source code in src/asrquant/alpha.py
weight_turnover ¶
One-way portfolio turnover: 0.5 * sum(|w_t - w_{t-1}|).
analyze_signal ¶
analyze_signal(signal: DataFrame, forward_return: DataFrame, *, quantiles: int = 5, ic_method: str = 'spearman', min_assets: int = 5, gross: float = 1.0) -> AlphaResearchReport
Run a standard cross-sectional alpha diagnostic in one call.