量化策略思想大致来源于以下几个方面:经典理论、逻辑推理、经验总结、数据挖掘、机器学习等。不论基本面还是技术面,都可以使用量化的方法进行分析,进而得出量化交易策略。比如,在基本面上,国内生产总值(GDP)增幅、货币发行量增幅、供需平衡表等都可以使用量化方法进行描述和分析;在技术面上,移动平均线、指数平滑移动平均线(MACD)等绝大部分技术分析指标都是量化策略思想来源。
“量化交易”有着两层含义:
【一】是从狭义上来讲,是指量化交易的内容,将交易条件转变成为程序,自动下单;
【二】是从广义上来讲,是指系统交易方法,就是一个整合的交易系统。
即为根据一系列交易条件,智能化辅助决策体系,将丰富的从业经验与交易条件相结合,在交易过程管理好风险控制。
常见的量化交易策略有很多种,例如趋势型,网格型,剥头皮,概率法则,高频交易等,今天主要给大家介绍2种低频的交易策略,高抛低吸网格交易策略、日内做T策略。
量化交易策略源码(部分)
#你选择的证券的数据更新将会触发此段逻辑,例如日或分钟历史数据切片或者是实时数据切片更新
def handle_bar(context,bar_dict):
...
if newPrice>=context.nextSellPrice:
logger.info("执行高抛交易,对应价格:{}".format(newPrice))
amount=context.portfolio.positions[context.s1].quantity
if amount>=context.tradeNumber:
logger.info("执行高抛交易,对应数量:{}".format(context.tradeNumber))
order_shares(context.s1,-context.tradeNumber)
plot("S",newPrice)
elif amount>=100:
logger.info("执行高抛交易,对应数量:{}".format(amount))
order_shares(context.s1,-amount)
plot("S",newPrice)
calc_next_trade_price(context,newPrice)
obj={
"nextSellPrice":context.nextSellPrice,
"nextBuyPrice":context.nextBuyPrice,
"curTradePrice":context.curTradePrice
}
context.buyTradeList.append(obj)
if newPrice<=context.nextBuyPrice:
logger.info("执行低吸交易,对应价格:{}".format(newPrice))
amount=int(context.portfolio.cash/newPrice/100.0)*100
if amount>=context.tradeNumber:
logger.info("执行低吸交易,对应数量:{}".format(context.tradeNumber))
order_shares(context.s1,context.tradeNumber)
plot("B",newPrice)
calc_next_trade_price(context,newPrice)
obj={
"nextSellPrice":context.nextSellPrice,
"nextBuyPrice":context.nextBuyPrice,
"curTradePrice":context.curTradePrice
}
context.sellTradeList.append(obj)