"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
# ============================================================
# 中文名称: GTJA Alpha #64
# 简要说明: 国泰君安191短周期交易型alpha因子第64号,详见公式定义。
# 典型用途: 在A股市场经中性化处理后用于选股或股指期货日内交易。
# ============================================================
"""GTJA Alpha #64.
Formula: (MAX(RANK(DECAYLINEAR(CORR(RANK(VWAP),RANK(VOLUME),4),4)),RANK(DECAYLINEAR(MAX(CORR(RANK(CLOSE),RANK(MEAN(VOLUME,60)),4),13),14)))*-1)
Source: 国泰君安 191 alpha 研报 (2014), alpha 64."""
from __future__ import annotations
import numpy as np
import pandas as pd
from src.factors.base import (
decay_linear,
delta,
rank,
safe_div,
signed_power,
ts_argmax,
ts_argmin,
ts_corr,
ts_cov,
ts_max,
ts_mean,
ts_min,
ts_rank,
ts_std,
vwap,
)
__alpha_meta__ = {
"id": "gtja191_064",
"theme": ['volume'],
"formula_latex": '(MAX(RANK(DECAYLINEAR(CORR(RANK(VWAP),RANK(VOLUME),4),4)),RANK(DECAYLINEAR(MAX(CORR(RANK(CLOSE),RANK(MEAN(VOLUME,60)),4),13),14)))*-1)',
"columns_required": ['close', 'volume', 'amount'],
"extras_required": [],
"requires_sector": False,
"universe": ["equity_cn"],
"frequency": ["1d"],
"decay_horizon": 14,
"min_warmup_bars": 30,
"notes": '60d mean truncated to 10d; ts_max window 13→4 and decay_linear 14→6 for warmup feasibility.',
}
def compute(panel: dict) -> pd.DataFrame:
c = panel["close"]
v = panel["volume"]
vw = vwap(panel, "equity_cn")
p1 = rank(decay_linear(ts_corr(rank(vw), rank(v), 4), 4))
x = rank(c)
y = rank(ts_mean(v, 10))
# fillna(0.0) reads a constant window's undefined correlation as no co-movement;
# a window that holds a missing input is not that, so it stays missing (#1452, #1463).
present = (x.notna() & y.notna()).astype(float).rolling(4, min_periods=4).min() == 1.0
inner = ts_corr(x, y, 4).fillna(0.0).where(present)
p2 = rank(decay_linear(ts_max(inner, 4), 6))
return -1.0 * pd.DataFrame(np.maximum(p1.to_numpy(), p2.to_numpy()),
index=c.index, columns=c.columns)