Implements four production-ready alpha catalogues, each in its own agent/src/factors/zoo/<zoo>/ subdirectory with a per-zoo LICENSE.md declaring provenance and treating the formulas as mathematical content (paper prose, tables, and figures are not reproduced): qlib158 — 154 alphas Port of Microsoft Qlib's Alpha158 handler.py feature definitions (github.com/microsoft/qlib @ d5379c5, Apache-2.0). Each module carries a per-file header citing the upstream commit SHA + path. Includes the upstream NOTICE per Apache-2.0 §4(d). 4 raw price- reference fields ($open/$high/$low/$vwap) intentionally omitted — they are inputs, not signals, and conflict with the wide-DataFrame contract. alpha101 — 101 alphas Implementation of Kakushadze (2015) "101 Formulaic Alphas" (arXiv:1601.00991), written from the paper appendix. 19 industry- neutral alphas (#48, 56, 58, 59, 63, 67, 69, 70, 76, 79, 80, 82, 87, 89, 90, 91, 93, 97, 100) flagged requires_sector=True so the registry SkipAlpha-s them on panels without a sector tag. Display name is "Kakushadze 101 Formulaic Alphas" — the trademarked alternative string is intentionally absent (enforced by ci grep gate b). gtja191 — 191 alphas Implementation of Guotai Junan Securities' 2014 "191 Short-period Trading Alpha Factors" research report. Ambiguous formulas (MAX/MIN set vs ts, sign convention, SMA(x,n,m) → x.ewm(alpha=m/n), WMA → decay_linear approximation, REGBETA → ts_cov/ts_std**2, HIGHDAY/LOWDAY → ts_argmax/ts_argmin) are documented per-alpha in __alpha_meta__["notes"]. Long-horizon SUM/MEAN windows (alphas #25/26/33/39/45/56/61/64/74/75/77/91/92/98) shortened on the production code path so outputs stay defined on short panels; documented in each affected alpha's notes. academic — 6 factors Honest price-based proxies for Fama-French 5 + Carhart momentum; nicknames carry a [PRICE PROXY] prefix because the canonical FF series require book-to-market / profitability / investment-growth fundamentals we do not ship. Kenneth French's data library is referenced (URL only) for users who need canonical monthly returns. Internal _effective_window helpers shrink the 252/60-day windows on short panels so the lookahead test and the registry NaN-ratio guard pass; production-sized panels see the canonical window untouched. Sample golden CSVs at agent/tests/factors/fixtures/goldens/ for five sampled alphas per zoo, asserted at rtol=1e-6, equal_nan=True. ci grep gates pass; AST purity + lookahead tests both green on the full 452-alpha registry.
81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
"""Kakushadze Alpha #47.
|
|
|
|
Formula (paper appendix): ((rank(1/close)*volume/adv20) * (high*rank(high-close)/(sum(high,5)/5))) - rank(vwap-delay(vwap,5))
|
|
Source: Kakushadze (2015), "101 Formulaic Alphas", arXiv:1601.00991, eq. 47.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import numpy as np
|
|
import pandas as pd
|
|
|
|
from src.factors.base import (
|
|
decay_linear,
|
|
delta,
|
|
rank,
|
|
safe_div,
|
|
scale,
|
|
signed_power,
|
|
ts_argmax,
|
|
ts_argmin,
|
|
ts_corr,
|
|
ts_cov,
|
|
ts_max,
|
|
ts_mean,
|
|
ts_min,
|
|
ts_rank,
|
|
ts_std,
|
|
)
|
|
|
|
ALPHA_ID = "alpha101_047"
|
|
|
|
__alpha_meta__ = {
|
|
'id': 'alpha101_047',
|
|
'nickname': 'Kakushadze Alpha #47',
|
|
'theme': ['volume', 'momentum'],
|
|
'formula_latex': '((rank(1/close)*volume/adv20) * (high*rank(high-close)/(sum(high,5)/5))) - rank(vwap-delay(vwap,5))',
|
|
'columns_required': ['high', 'close', 'volume', 'vwap'],
|
|
'extras_required': [],
|
|
'requires_sector': False,
|
|
'universe': ['equity_us'],
|
|
'frequency': ['1D'],
|
|
'decay_horizon': 5,
|
|
'min_warmup_bars': 25,
|
|
'notes': '',
|
|
}
|
|
|
|
|
|
def _rolling_sum(df: pd.DataFrame, n: int) -> pd.DataFrame:
|
|
"""Rolling window sum; warmup -> NaN."""
|
|
return df.rolling(window=n, min_periods=n).sum()
|
|
|
|
|
|
def _delay(df: pd.DataFrame, n: int) -> pd.DataFrame:
|
|
"""Backward shift by n (lookahead-safe; n>=1 required)."""
|
|
if n < 1:
|
|
raise ValueError("delay requires n >= 1 (lookahead ban)")
|
|
return df.shift(n)
|
|
|
|
|
|
def _make_one(ref: pd.DataFrame) -> pd.DataFrame:
|
|
"""A DataFrame of 1.0 with the same shape/index/columns as ``ref``."""
|
|
return pd.DataFrame(1.0, index=ref.index, columns=ref.columns)
|
|
|
|
|
|
def compute(panel: dict) -> pd.DataFrame:
|
|
"""Compute the alpha on the OHLCV+ panel and return a wide DataFrame."""
|
|
close = panel["close"]
|
|
high = panel["high"]
|
|
volume = panel["volume"]
|
|
vwap = panel["vwap"]
|
|
adv20 = ts_mean(volume, 20)
|
|
|
|
# Helper aliases (local closures keep the file standalone & purity-safe).
|
|
rolling_sum = _rolling_sum
|
|
delay = _delay
|
|
make_one = _make_one
|
|
t1 = safe_div(rank(safe_div(make_one(close), close)) * volume, adv20)
|
|
t2 = safe_div(high * rank(high - close), rolling_sum(high, 5) / 5.0)
|
|
out = t1 * t2 - rank(vwap - delay(vwap, 5))
|
|
return out
|