trading.ai/scripts/init_container.sh
2025-10-01 09:58:52 +08:00

126 lines
3.6 KiB
Bash
Raw 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.

#!/bin/bash
# 容器初始化脚本
# 确保配置文件存在
CONFIG_DIR="/app/config"
CONFIG_FILE="$CONFIG_DIR/config.yaml"
# 创建配置目录(如果不存在)
mkdir -p $CONFIG_DIR
# 如果配置文件不存在,创建默认配置文件
if [ ! -f "$CONFIG_FILE" ]; then
echo "创建默认配置文件: $CONFIG_FILE"
cat > "$CONFIG_FILE" << 'EOF'
# A股量化交易配置文件
trading:
# 交易时间配置
trading_hours:
start: "09:30:00"
end: "15:00:00"
lunch_break_start: "11:30:00"
lunch_break_end: "13:00:00"
# 股票池配置
stock_pool:
# 默认关注的指数成分股
index_codes: ["000001.SZ", "000300.SZ", "000905.SZ"] # 上证指数、沪深300、中证500
# 排除的股票代码
exclude_codes: []
# 风险控制
risk_management:
max_position_per_stock: 0.05 # 单股最大仓位比例
max_total_position: 0.9 # 最大总仓位比例
stop_loss_ratio: 0.05 # 止损比例
take_profit_ratio: 0.15 # 止盈比例
# 数据配置
data:
# 数据源配置
sources:
primary: "tushare"
# 数据更新频率
update_frequency:
realtime: "1min" # 实时数据更新频率
daily: "after_close" # 日线数据更新时机
# 数据存储
storage:
path: "data/"
format: "parquet" # 数据存储格式
# 策略配置
strategy:
# 技术指标参数
indicators:
ma_periods: [5, 10, 20, 50] # 移动平均线周期
rsi_period: 14 # RSI周期
macd_params: [12, 26, 9] # MACD参数
# 选股条件
selection_criteria:
min_market_cap: 1000000000 # 最小市值(元)
max_pe_ratio: 30 # 最大市盈率
min_volume_ratio: 1.5 # 最小成交量比率
# K线形态策略配置
kline_pattern:
enabled: true # 是否启用K线形态策略
min_entity_ratio: 0.55 # 前两根阳线实体最小占振幅比例55%
final_yang_min_ratio: 0.40 # 最后阳线实体最小占振幅比例40%
timeframes: ["daily", "weekly"] # 支持的时间周期
scan_stocks_count: 100 # Docker环境默认扫描股票数量
analysis_days: 60 # 分析的历史天数
follow_up_days: 30 # 后续强势验证天数形态完成后N天内不回踩阴线高点且不跌破EMA20
# 回踩监控配置
pullback_tolerance: 0.02 # 回踩容忍度2%),价格接近阴线最高点的阈值
monitor_days: 30 # 监控回踩的天数信号触发后30天内监控
# 监控配置
monitor:
# 实时监控
realtime:
enabled: true
refresh_interval: 60 # 刷新间隔(秒)
# 报警配置
alerts:
price_change_threshold: 0.05 # 价格变动报警阈值
volume_spike_threshold: 3.0 # 成交量异常报警阈值
# 日志配置
logging:
level: "INFO"
format: "{time:YYYY-MM-DD HH:mm:ss} | {level} | {name} | {message}"
rotation: "1 day"
retention: "30 days"
file_path: "logs/trading.log"
# 通知配置
notification:
# 钉钉机器人配置
dingtalk:
enabled: false # Docker环境默认关闭通知
webhook_url: "" # 钉钉机器人webhook地址
secret: "" # 加签密钥
at_all: false # 是否@所有人
at_mobiles: [] # @指定手机号列表
# 其他通知方式
email:
enabled: false # 邮件通知(预留)
wechat:
enabled: false # 微信通知(预留)
EOF
echo "默认配置文件已创建"
else
echo "配置文件已存在: $CONFIG_FILE"
fi
# 执行传入的命令
exec "$@"