MCPcopy Index your code
hub / github.com/SkyworkAI/DeepResearchAgent / main

Function main

tests/run_backtest_simple.py:37–465  ·  view source on GitHub ↗

主函数 - 简化的回测运行

()

Source from the content-addressed store, hash-verified

35
36
37async def main():
38 """主函数 - 简化的回测运行"""
39
40 print("=" * 80)
41 print("🚀 LLM 离线回测系统")
42 print("=" * 80)
43
44 # ============ 配置参数 ============
45 # 数据库路径:在 tests/hl_backtest/ 目录下
46 db_path = Path(__file__).parent / "hl_backtest" / "database.db" # 数据库路径
47 symbol = "BTC" # 交易币种
48 initial_equity = 1000.0 # 初始资金
49 max_leverage = 5.0 # 最大杠杆
50 taker_fee_rate = 0.0005 # 手续费率参数(已废弃,实际使用固定0.6块手续费)
51 fixed_fee = 0.6 # 固定手续费(开仓和平仓都收取0.6块)
52 slippage_bps = 1.0 # 滑点 (0.01%)
53
54 # 回测参数(测试模式:减少LLM调用次数)
55 steps_per_candle = 1 # 每个K线允许LLM决策的次数
56 max_total_steps = 10 # Agent最大步数(每个K线)- 减少以加快测试
57
58 # 限制回测的K线数量(测试模式:只处理少量K线)
59 max_bars = 10 # 最多处理10根K线(测试用)
60
61 # ============ 初始化配置 ============
62 print("\n" + "=" * 80)
63 print("初始化配置...")
64 print("=" * 80)
65
66 # 加载配置文件(与 online_trading_agent 完全一致)
67 default_config = root_dir / "configs" / "online_trading_agent.py"
68 if default_config.exists():
69 # config.init_config 需要两个参数:config_path 和 args (Namespace对象)
70 # 创建一个空的 Namespace 对象
71 empty_args = Namespace()
72 empty_args.cfg_options = None
73 config.init_config(str(default_config), empty_args)
74 logger.init_logger(config)
75 logger.info(f"| ✅ 配置加载成功")
76 else:
77 logger.warning(f"| ⚠️ 配置文件不存在,使用默认配置")
78 logger.init_logger(config)
79
80 # 从配置中读取配置(与 online_trading_agent 一致)
81 # 使用 GPT-5 模型(与 online_trading_agent 完全一致)
82 model_name = config.online_trading_agent.get('model_name', 'gpt-5') if hasattr(config, 'online_trading_agent') else 'gpt-5'
83 prompt_name = config.online_trading_agent.get('prompt_name', 'online_trading') if hasattr(config, 'online_trading_agent') else 'online_trading'
84
85 # 工作目录
86 workdir = root_dir / "workdir" / "llm_backtest"
87 workdir.mkdir(parents=True, exist_ok=True)
88
89 print(f"\n📊 回测配置:")
90 print(f" 数据库: {db_path}")
91 print(f" 币种: {symbol}")
92 print(f" 初始资金: ${initial_equity:,.2f}")
93 print(f" 最大杠杆: {max_leverage}x")
94 print(f" 手续费: 固定 ${fixed_fee:.2f}/笔(开仓和平仓都收取)")

Callers 1

Calls 15

printFunction · 0.85
warningMethod · 0.80
get_backtest_resultsMethod · 0.80
dumpMethod · 0.80
existsMethod · 0.45
infoMethod · 0.45
getMethod · 0.45
mkdirMethod · 0.45
initializeMethod · 0.45
keysMethod · 0.45
errorMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected