"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
Merge PR #2051: correct signed GTJA 17 exponent and matching metadata
Haozhe Wufe15be893995
diff --cc agent/src/factors/zoo/gtja191/alpha_017.pyindex 03d177235,b43eeefe2..ee7c1aa68--- a/agent/src/factors/zoo/gtja191/alpha_017.py+++ b/agent/src/factors/zoo/gtja191/alpha_017.py@@@ -1,8 -1,8 +1,8 @@@# ============================================================--# 中文名称: GTJA #17 - 价格振幅比--# 简要说明: RANK(DELTA(VWAP, 1))^3 / RANK(CORR(LOW, MEAN(VOLUME,50), 12)),VWAP变化与量价相关的比率。--# 典型用途: VWAP变化速度相对于成交量-价格关系的归一化指标。++# 中文名称: GTJA #17 - VWAP回撤排名的价格变化幂++# 简要说明: RANK(VWAP - MAX(VWAP,15)) ^ DELTA(CLOSE,5),幂指数保留涨跌方向。++# 典型用途: 衡量VWAP回撤横截面排名与五日价格变化的非线性关系。# ============================================================"""GTJA Alpha #17.@@@ -15,20 -15,20 +15,9 @@@ import numpy as nimport pandas as pdfrom 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,)diff --cc agent/tests/factors/fixtures/goldens/gtja191_017.csvindex b30f8d661,b30f8d661..3bf14a9dd--- a/agent/tests/factors/fixtures/goldens/gtja191_017.csv+++ b/agent/tests/factors/fixtures/goldens/gtja191_017.csv@@@ -13,19 -13,19 +13,19 @@@2024-01-12,,,,,2024-01-13,,,,,2024-01-14,,,,,--2024-01-15,1.0,0.9875668011220564,0.562953920107327,0.21589435203616916,0.4879812055553432--2024-01-16,1.0,0.8888171391883999,0.6828302306480283,0.3476453817871338,0.003788910110558139--2024-01-17,0.6631602904676617,1.0,0.5877869436230023,0.7571813221122062,0.00021454813474718832--2024-01-18,0.39505243748829055,1.0,0.5755914266189773,0.4111442284579084,0.00013254156843811536--2024-01-19,0.882739306726763,1.0,0.6748853507772032,0.7732029788379194,0.00019915885726476184--2024-01-20,0.3134890271943107,1.0,0.7881917874803348,0.520350230516808,0.00925451157274438--2024-01-21,0.0403572726695053,1.0,0.7959166088654683,0.32957520336388896,0.1749325718320325--2024-01-22,0.07147037215007762,1.0,0.939351297386615,0.4898570477299514,0.5700960030527273--2024-01-23,0.01950919778847001,0.5469850858255441,0.7554857271842884,1.0,0.18311963408063248--2024-01-24,0.02352914374345864,0.6842436908629206,0.595259182596741,1.0,0.86619289194643--2024-01-25,0.18568658706699512,0.8954401667368038,1.0,0.42839548717339576,0.2309137214557651--2024-01-26,0.40523003460423934,0.933617566651855,1.0,0.5646419995138086,0.40052556901102454--2024-01-27,0.8429932348489217,0.6555252464755212,0.5058214071760223,1.0,0.6408483271703573--2024-01-28,0.48074158786752313,0.08825254564103696,0.41608902812130477,1.0,0.12046823925036115--2024-01-29,0.19420514951077988,0.7469524139495382,0.1387711709645867,1.0,0.05456877512133521--2024-01-30,0.489760726907602,0.2235395217215515,0.0003890478097785163,1.0,0.34261476956++2024-01-15,1.0,0.9875668011220564,1.7763443228343634,0.21589435203616916,2.0492592514130905++2024-01-16,1.0,0.8888171391883999,1.46449286384255,0.3476453817871338,263.9281404996677++2024-01-17,0.6631602904676617,1.0,0.5877869436230023,0.7571813221122062,4660.958722285536++2024-01-18,0.39505243748829055,1.0,0.5755914266189773,0.4111442284579084,7544.802825137137++2024-01-19,0.882739306726763,1.0,0.6748853507772032,0.7732029788379194,5021.11738204342++2024-01-20,3.1899043132382667,1.0,0.7881917874803348,1.9217825636529604,108.05540542464901++2024-01-21,24.778681359100325,1.0,0.7959166088654683,3.0342088536797016,5.716488299046928++2024-01-22,13.991811850372658,1.0,1.064564452917792,2.0414118866598003,1.7540905297445342++2024-01-23,51.257873893256786,0.5469850858255441,1.3236517435306443,1.0,5.4609108685728++2024-01-24,42.50048411889238,0.6842436908629206,1.6799404851473767,1.0,0.86619289194643++2024-01-25,5.385418601286497,0.8954401667368038,1.0,0.42839548717339576,0.2309137214557651++2024-01-26,0.40523003460423934,1.0711023825164367,1.0,0.5646419995138086,0.40052556901102454++2024-01-27,1.1862491401597268,1.5254942588047862,1.9769823613890802,1.0,1.5604316303913344++2024-01-28,0.48074158786752313,11.331117904150352,2.4033318170275435,1.0,8.300943105192783++2024-01-29,0.19420514951077988,1.3387733693937254,7.206107673871197,1.0,18.325498378449428++2024-01-30,0.489760726907602,4.473481880513434,2570.3781768346075,1.0,2.918729981443127diff --cc agent/tests/factors/test_gtja191_alpha017_power.pyindex 000000000,c35bc6079..bcd343f47mode 000000,100644..100644--- a/agent/tests/factors/test_gtja191_alpha017_power.py+++ b/agent/tests/factors/test_gtja191_alpha017_power.py@@@ -1,0 -1,34 +1,37 @@@+ """GTJA #17 raises the percentile rank to the signed 5-day close change.++ A rank of 0.5 and a close change of -2 is 0.5 ** -2 = 4. Taking the absolute+ value of the exponent reported 0.25.+ """++ from __future__ import annotations++ import numpy as np+ import pandas as pd++import pytest++ from src.factors.zoo.gtja191 import alpha_017++-def test_negative_close_change_inverts_the_rank_power():[email protected]("width", [2, 5, 100])++def test_negative_close_change_inverts_the_rank_power(width):+ idx = pd.bdate_range("2024-01-01", periods=20)- close = pd.DataFrame(10.0, index=idx, columns=["A", "B"])- close.iloc[-1] = [8.0, 12.0]- vwap = pd.DataFrame(10.0, index=idx, columns=["A", "B"])- vwap.iloc[-1] = [8.0, 10.0]++ columns = ["A", *[f"X{i}" for i in range(width - 2)], "B"]++ close = pd.DataFrame(10.0, index=idx, columns=columns)++ close.loc[idx[-1], ["A", "B"]] = [8.0, 12.0]++ vwap = pd.DataFrame(10.0, index=idx, columns=columns)++ vwap.iloc[-1] = np.linspace(8.0, 10.0, width)+ panel = {+ "close": close,+ "vwap": vwap,- "volume": pd.DataFrame(1.0, index=idx, columns=["A", "B"]),- "amount": pd.DataFrame(1.0, index=idx, columns=["A", "B"]),++ "volume": pd.DataFrame(1.0, index=idx, columns=columns),++ "amount": pd.DataFrame(1.0, index=idx, columns=columns),+ }++ got = alpha_017.compute(panel).iloc[-1]++ # vwap - 15-day max is -2 and 0, so the percentile ranks are 0.5 and 1.+ # Deltas are -2 and +2.- assert got["A"] == 4.0++ assert got["A"] == pytest.approx((1.0 / width) ** -2)+ assert got["B"] == 1.0+ assert not np.isclose(got["A"], 0.25)diff --cc wiki/alpha-library/i18n.zh.jsonindex 707198fad,707198fad..ae41e1ba4--- a/wiki/alpha-library/i18n.zh.json+++ b/wiki/alpha-library/i18n.zh.json@@@ -301,8 -301,8 +301,8 @@@"zh": "成交量排名与 vwap 排名的滚动相关系数,其排名在 5 日内的最大值。"},"gtja191_017": {-- "en": "rank(vwap - 15d max(vwap)) is non-positive; we use signed_power for safety.",-- "zh": "rank(vwap - 15 日 max(vwap)) 非正;为稳妥起见使用 signed_power(带符号幂)。"++ "en": "The base is a percentile rank in (0, 1], so a negative 5-day close change is a real power, not a complex one.",++ "zh": "底数是 (0, 1] 范围内的横截面百分位排名,因此五日收盘价变化即使为负,也能直接计算实数幂;幂指数保留原符号。"},"gtja191_018": {"en": "5d price ratio.",