feat(qmt): 添加策略权重配置功能
- 在 qmt_engine.py 中增加权重计算逻辑 - 下单金额公式改为: target_amt = total_equity * weight / total_weighted_slots - 更新 qmt_config.md 添加 weight 字段配置说明 - 保持向后兼容,不配置 weight 时默认为 1
This commit is contained in:
@@ -528,14 +528,24 @@ class MultiEngineManager:
|
||||
asset = unit.xt_trader.query_stock_asset(unit.acc_obj)
|
||||
# 计算该终端的总槽位之和
|
||||
terminal_strategies = self.get_strategies_by_terminal(unit.qmt_id)
|
||||
total_slots = sum(self.config['strategies'][s]['total_slots'] for s in terminal_strategies)
|
||||
|
||||
if not asset or total_slots <= 0: return
|
||||
# 计算加权槽位总和(支持策略权重配置)
|
||||
# 权重默认为 1,支持通过 weight 字段调整资金分配比例
|
||||
# 示例:strategies = {"strategy_a": {"total_slots": 5, "weight": 1}, "strategy_b": {"total_slots": 5, "weight": 2}}
|
||||
total_weighted_slots = sum(
|
||||
self.config['strategies'][s].get('total_slots', 1) * self.config['strategies'][s].get('weight', 1)
|
||||
for s in terminal_strategies
|
||||
)
|
||||
|
||||
if not asset or total_weighted_slots <= 0: return
|
||||
|
||||
# 3. 资金等权分配 (基于该终端总资产)
|
||||
# 获取当前策略的权重
|
||||
weight = strat_cfg.get('weight', 1)
|
||||
|
||||
# 4. 资金加权分配 (基于该终端总资产)
|
||||
total_equity = asset.cash + asset.market_value
|
||||
target_amt = total_equity / total_slots
|
||||
actual_amt = min(target_amt, asset.cash * 0.98) # 预留手续费滑点
|
||||
target_amt = total_equity * weight / total_weighted_slots
|
||||
actual_amt = min(target_amt, asset.cash * 0.98) # 预留手续费滑点
|
||||
|
||||
if actual_amt < 2000:
|
||||
self.logger.warning(f"[{strategy_name}] 单笔预算 {actual_amt:.2f} 不足 2000 元,取消买入")
|
||||
|
||||
Reference in New Issue
Block a user