-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
122 lines (104 loc) · 3.98 KB
/
Copy pathmain.py
File metadata and controls
122 lines (104 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""
入口脚本:在预设方向中挑一个跑完整流程。
MVP 阶段锁定美股(config.runtime.markets.DEFAULT_MARKET = "USA"):美股的研究资料、示例 alpha、
字段覆盖度都最齐全,先把单市场闭环跑通。未来要加 CHN / EUR / ASI 等,把它们
加回 config.MARKET_CONFIGS 并在这里加回市场选择菜单即可。
用法:
uv run python main.py
"""
import logging
import os
from config.env.loader import load_project_env
load_project_env()
from discover import orchestrator
from config.runtime.logging import setup_logging
from config.runtime.discover import MAX_ITER, PERFORMANCE_CRITERIA
from config.runtime.markets import DIRECTIONS, DEFAULT_MARKET
from config.runtime.submission_profiles import SUBMISSION_PROFILE_SPECS
from config.runtime.network import use_system_proxy
logger = logging.getLogger(__name__)
def _prompt_choice(title: str, options: list[tuple[str, str]]) -> str:
"""
让用户从 options 中选一项。
options: list of (key, description)
返回用户选中的 key。
"""
print(f"\n{title}")
for i, (key, desc) in enumerate(options, 1):
print(f" {i}. {key:<16} {desc}")
while True:
raw = input("请选择编号: ").strip()
if raw.isdigit():
idx = int(raw)
if 1 <= idx <= len(options):
return options[idx - 1][0]
print(f"请输入 1~{len(options)} 之间的数字")
def _prompt_optional_positive_int(prompt: str, default: int) -> int:
"""读取可选正整数;空输入则使用默认值。"""
while True:
raw = input(f"{prompt}(直接回车使用默认 {default}): ").strip()
if not raw:
return default
if raw.isdigit() and int(raw) > 0:
return int(raw)
print("请输入正整数,或直接回车使用默认值。")
def _prompt_run_mode() -> str:
"""选择运行模式:test(不写记忆) / real(真实运行)。"""
return _prompt_choice(
"=== 选择运行模式 ===",
[
("test", "测试运行(DISCOVER_TEST_MODE=1,不写 Stage-1 轻量记忆)"),
("real", "真实运行(会按正常逻辑写入记忆)"),
],
)
def main() -> None:
log_file = setup_logging()
run_mode = _prompt_run_mode()
if run_mode == "test":
os.environ["DISCOVER_TEST_MODE"] = "1"
else:
os.environ["DISCOVER_TEST_MODE"] = "0"
market = DEFAULT_MARKET
submission_profile = _prompt_choice(
"=== 选择 Alpha 类型 / Submission Profile ===",
[
(
key,
f"{spec['label']} - {spec['description']}"
+ ("(默认当前主线)" if key == "PPAC" else "(experimental,占位探索)")
)
for key, spec in SUBMISSION_PROFILE_SPECS.items()
],
)
direction = _prompt_choice(
f"=== 选择策略方向(市场锁定为 {market})===",
[(k, v["desc"]) for k, v in DIRECTIONS.items()],
)
max_iter = _prompt_optional_positive_int("请输入本次最大回测轮次 max_iter", MAX_ITER)
logger.info(
"启动配置: profile=%s market=%s direction=%s max_iter=%d criteria=%s",
submission_profile, market, direction, max_iter, PERFORMANCE_CRITERIA,
)
logger.info(
"运行模式: %s (DISCOVER_TEST_MODE=%s)",
run_mode,
os.environ.get("DISCOVER_TEST_MODE", "0"),
)
logger.info(
"代理策略: %s (PROJECT_USE_SYSTEM_PROXY=%s)",
"启用系统代理" if use_system_proxy() else "禁用系统代理",
os.environ.get("PROJECT_USE_SYSTEM_PROXY", "false"),
)
logger.info("日志文件: %s", log_file)
try:
orchestrator.run_pipeline(
market=market,
direction=direction,
max_iter=max_iter,
submission_profile=submission_profile,
)
except Exception:
logger.exception("Pipeline 运行失败")
raise
if __name__ == "__main__":
main()