转载自:http://blog.csdn.net/artemis_123/article/details/53885295
http://blog.csdn.net/artemis_123/article/details/53885295#设置基本参数
start = '2016-02-01'
end = '2016-03-28'
capital_base = 1000000
refresh_rate = 1
benchmark = 'HS300'
freq = 'd'
#设置股票池 以平安银行为例
universe = ['000001.XSHE', ]
def initialize(account):
pass
def handle_data(account):
moneyTotal = account.referencePortfolioValue #获取当前账户资产总额
price=account.referencePrice[account.universe[0]] # 股票参考价
buyNum=int(moneyTotal / price) - account.valid_secpos.get(account.universe[0], 0) #可增持仓位=总仓位-当前所持仓位
if buyNum > 0:
order(account.universe[0], buyNum) #买入操作
if str(account.current_date)[:10] == end:
order_to(account.universe[0], 0) #全部卖出