实盘风险提示
1)模拟盘与实盘存在差异;2)极端行情风险;3)系统故障风险;4)强平风险;5)保证金风险。务必做好风险预案。
项目二:期货CTA策略
实盘部署是策略从测试到生产的关键环节。本节介绍期货策略的实盘部署方案。
| 检查项 | 标准 | 状态 |
|---|---|---|
| 策略表现 | 夏普>1.2,回撤<20% | ⬜ 待检查 |
| 模拟盘测试 | 模拟盘运行3个月稳定 | ⬜ 待检查 |
| 风控系统 | 止损、限额完备 | ⬜ 待检查 |
| 交易接口 | 接口测试通过 | ⬜ 待检查 |
| 资金安排 | 资金充足,风险可控 | ⬜ 待检查 |
class FuturesTradingAPI:
"""
期货交易API封装
"""
def __init__(self, config):
self.api = init_ctp_gateway(config)
self.connected = False
def connect(self):
"""连接交易服务器"""
self.api.connect()
self.connected = True
def place_order(self, symbol, direction, volume, price=None):
"""
下单
"""
order = {
'symbol': symbol,
'direction': direction,
'volume': volume,
'price_type': 'MARKET' if price is None else 'LIMIT',
'price': price
}
order_id = self.api.send_order(order)
return order_id
def cancel_order(self, order_id):
"""撤单"""
return self.api.cancel_order(order_id)
def get_position(self, symbol):
"""查询持仓"""
return self.api.query_position(symbol)
def get_account(self):
"""查询账户"""
return self.api.query_account()
class RealTimeMonitor:
"""
实时监控系统
"""
def __init__(self, config):
self.alerts = []
self.alert_rules = config['alert_rules']
def check_position_risk(self, positions):
"""检查持仓风险"""
for symbol, position in positions.items():
# 检查止损
if position['pnl'] < position['stop_loss']:
self.alert(f"{symbol} 触发止损: {position['pnl']}")
# 检查仓位限制
if position['size'] > self.alert_rules['max_position']:
self.alert(f"{symbol} 仓位超限: {position['size']}")
def check_account_risk(self, account):
"""检查账户风险"""
# 检查保证金占用
margin_ratio = account['used_margin'] / account['total_asset']
if margin_ratio > self.alert_rules['max_margin_ratio']:
self.alert(f"保证金占用过高: {margin_ratio:.2%}")
# 检查当日盈亏
if account['daily_pnl'] < self.alert_rules['max_daily_loss']:
self.alert(f"当日亏损超限: {account['daily_pnl']}")
self.emergency_stop()
def alert(self, message):
"""发送警报"""
self.alerts.append({
'time': datetime.now(),
'message': message,
'level': 'WARNING'
})
send_notification(message)
def emergency_stop(self):
"""紧急停止"""
# 平掉所有持仓
self.close_all_positions()
# 停止策略
self.stop_strategy()
模拟盘运行,验证系统稳定性
10%资金试运行,密切监控
表现稳定后逐步增加仓位
全仓位运行,持续监控优化
1)模拟盘与实盘存在差异;2)极端行情风险;3)系统故障风险;4)强平风险;5)保证金风险。务必做好风险预案。