def check(context):
#先检查持仓股是不是在所选股票池内,不在的清掉
cdata = get_current_data()
for s in context.portfolio.positions:
# 过滤掉停牌、跌停的个股
if cdata[s].paused or cdata[s].last_price < = cdata[s].low_limit or cdata[s].last_price >= cdata[s].high_limit :
continue
if s not in g.stocks:
order_target(s,0,MarketOrderStyle(0.99*cdata[s].last_price))
#再检查所选股票是不是在持仓池内,不在的买入
for s in g.stocks:
# 检查资金是否用完
if context.portfolio.available_cash < 1.0/g.S1*context.portfolio.total_value:
break
# 过滤掉停牌、涨停的个股
if cdata[s].paused or cdata[s].last_price >= cdata[s].high_limit or cdata[s]\
.last_price < = cdata[s].low_limit or 'ST' in cdata[s].name or '退' in cdata[s].name :
continue
if s not in context.portfolio.positions:
order_value(s,1/g.S1*context.portfolio.total_value,MarketOrderStyle(1.01*cdata[s].last_price))
实例来得最快。
不知道什么时候聚宽不能购买688的股票,通过几种方法尝试,如下代码可以实现
for key in gridas.keys():
if key[:3] in ('688'):
current_data = get_current_data()
last_prices = current_data[key].last_price
order_target_value(key, 1000000,LimitOrderStyle(last_prices*1.019))
这个是我很久前发的,你可以直接用,如果解决了,请选择采纳我的答案,谢谢