Files
backtrader/config.py.backup_test
2026-01-17 21:21:30 +08:00

92 lines
4.1 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import os
from datetime import datetime
class Config:
"""全局配置类"""
# ========== TuShare Pro 配置 ==========
TUSHARE_TOKEN = '9343e641869058684afeadfcfe7fd6684160852e85332a7734c8d' # TuShare Pro Token
TUSHARE_CALL_INTERVAL = 0.1 # 调用间隔(秒),避免超限
# ========== 数据配置 ==========
DATA_DIR = 'D:\gp_data\day' # 本地数据路径
START_DATE = '20230101' # 开始日期
END_DATE = '20251201' # 结束日期
# ========== 股票池配置 ==========
# 设置为 None 则使用全市场股票池(根据 STOCK_FILTER_CONFIG 筛选)
# 设置为列表则使用指定股票
STOCK_POOL = None # 全市场模式,根据筛选条件自动获取
# STOCK_POOL = ['002402.SZ','600362.SH','002863.SZ','300086.SZ'] # 自定义股票池(取消注释以启用)
LOCAL_HQ = True # 是否启用本地数据
# ========== 个股筛选配置 ==========
STOCK_FILTER_CONFIG = {
'include_st': False, # 是否包含ST/*ST股票
'include_bse': False, # 是否包含北交所股票代8开头
'include_sse_star': False, # 是否包含科创板股票代码688开头
'include_gem': True, # 是否包含创业板股票代码3开头
'include_main': True, # 是否包含主板股票代码0/6开头
'custom_stocks': STOCK_POOL # 自定义股票列表,优先级最高,设置 STOCK_POOL 为 None 即启用全市场筛选
}
# ========== 策略参数 ==========
# 均线参数
MA_PARAMS = {
'short': 5, #短周期均线
'medium': 10, #中周期均线
'long': 30, #长周期均线
'extra_long': 60 # 用于趋势判断
}
# 一阳穿三线条件(放宽后的参数)
YIYANG_CONDITIONS = {
'min_pct_change': 3, # 最小涨幅%从3.0降低到1.5
'min_volume_ratio': 1.5, # 最小量比从1.5降低到1.2
'max_ma_gap_pct': 8.0, # 均线最大间距%从5.0增加到8.0
'min_entity_ratio': 0.4, # 实体最小比例从0.6降低到0.4
'confirm_days': 1 # 确认天数从3减少到1
}
# 双均线策略参数
DUAL_MA_CONDITIONS = {
'short_period': 7, # 短期均线周期
'long_period': 21 # 长期均线周期
}
# ========== 策略配置 ==========
# 策略列表,只有在这个列表中的策略才会被回测
STRATEGY_LIST = ['YiYangStrategy'] # 策略列表,只有在这个列表中的策略才会被回测
# ========== 回测配置 ==========
BACKTEST = {
'initial_capital': 100000, # 初始资金
'commission_rate': 0.0003, # 佣金费率
'stamp_tax_rate': 0.001, # 印花税
'slippage_rate': 0.001, # 滑点
'position_ratio': 0.2, # 单笔仓位比例
'stop_loss': 0.05, # 止损比例
'take_profit': 0.20, # 止盈比例
'max_positions': 2, # 最大持股个数(同时最多持有多少只股票)
'max_holding_days': 20 # 最大持股天数(超过此天数未止盈止损则强制卖出)
}
# ========== 参数优化配置 ==========
RUN_PARAMETER_OPTIMIZATION = False # 是否运行参数优化
OPTIMIZATION_CONFIG = {
'strategy_name': 'YiYangStrategy', # 要优化的策略名称
'metric': 'sharpe_ratio', # 优化目标指标
'method': 'grid', # 优化方法grid(网格搜索) 或 random(随机搜索)
'n_iter': 50, # 随机搜索迭代次数
'max_workers': 10 # 多线程数量
}
# 参数优化搜索空间
OPTIMIZATION_PARAM_SPACE = {
'min_pct_change': [1.5, 2.0, 2.5, 3.0],
'min_volume_ratio': [1.0, 1.2, 1.5, 2.0],
'max_ma_gap_pct': [4.0, 5.0, 6.0, 8.0],
'min_entity_ratio': [0.4, 0.5, 0.6, 0.7],
'confirm_days': [1, 2, 3]
}