开通 QMT/PTRADE 专业版,10 万资金到位,却不知道跑什么策略?别盲目跟风搞复杂模型,这 3 个经典策略,逻辑简单、胜率稳定,还能直接在量化软件上复用,新手也能快速盈利!

def init(context):
context.security ="510300.SH"# 沪深300ETF
context.ma_short =5
context.ma_long =20
def handle_bar(context, bar_dict):
data = get_bars(context.security,21,'1d','close', skip_suspended=True)
ma5 = data['close'][-5:].mean()
ma20 = data['close'].mean()
position = get_position(context.security).volume
if position ==0and ma5 > ma20:
order_target_percent(context.security,0.5)# 半仓
elif position >0and ma5 < ma20:
order_target_percent(context.security,0)# 清仓
实操建议:优先选宽基 ETF,回测周期至少 1 年,避免小盘股流动性风险。