修复未来函数bug

This commit is contained in:
2025-07-15 22:45:51 +08:00
parent 5de1a43b02
commit 5a2d0fb984
19 changed files with 15019 additions and 9388 deletions

View File

@@ -2,6 +2,7 @@ from datetime import timedelta
from src.analysis.result_analyzer import ResultAnalyzer
# 导入 TqsdkEngine而不是原来的 BacktestEngine
from src.indicators.indicators import RSI, HistoricalRange
from src.tqsdk_real_engine import TqsdkEngine
# 导入你的策略类
@@ -17,29 +18,34 @@ initial_capital = 100000.0
slippage_rate = 0.000 # 在 Tqsdk 模拟中,滑点通常由 TqSim 处理或在策略中手动模拟
commission_rate = 0.0001 # 同上
# 主力合约的 symbol
main_symbol = "KQ.m@CZCE.MA"
main_symbol = "KQ.m@DCE.jm"
strategy_parameters = {
'symbol': main_symbol, # 根据您的数据文件中的品种名称调整
'trade_volume': 1,
'range_factor': 1.8, # 示例值,需要通过网格搜索优化
'profit_factor': 2.8, # 示例值
# 'range_factor': 0.7, # 示例值,需要通过网格搜索优化
# 'profit_factor': 71, # 示例值
# 'range_factor_l': 2, # 示例值,需要通过网格搜索优化
# 'profit_factor_l': 3, # 示例值
# 'range_factor_s': 1.6, # 示例值,需要通过网格搜索优化
# 'profit_factor_s': 5.6, # 示例值
'lag': 1,
# 'range_factor': 1.3, # 示例值,需要通过网格搜索优化
# 'profit_factor': 4.8, # 示例值
# 'range_factor': 1.1, # 示例值,需要通过网格搜索优化
# 'profit_factor': 4.9, # 示例值
'range_factor_l': 1.3, # 示例值,需要通过网格搜索优化
'profit_factor_l': 4.8, # 示例值
'range_factor_s': 1.1, # 示例值,需要通过网格搜索优化
'profit_factor_s': 4.9, # 示例值
'max_position': 10,
'enable_log': True,
'stop_loss_points': 20,
'use_indicator': True
'use_indicator': True,
# 'indicator': RSI(5, 63, 95),
# 'indicator': RSI(5, 5, 25),
'indicator_l': RSI(5, 63, 95),
'indicator_s': RSI(5, 0, 100),
}
api = TqApi(TqKq(), auth=TqAuth("emanresu", "dfgvfgdfgg"))
# --- 1. 初始化回测引擎并运行 ---
print("\n初始化 Tqsdk 回测引擎...")
engine = TqsdkEngine(
strategy_class=SimpleLimitBuyStrategyLong,
strategy_class=SimpleLimitBuyStrategy,
strategy_params=strategy_parameters,
api=api,
symbol=main_symbol,