量化投资(一):在python平台上设置买入卖出

来源:互联网 发布:人工智能硬件解决方案 编辑:程序博客网 时间:2024/04/30 22:49

转载自: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)   #全部卖出  


更多操作可以参考

阅读全文
0 0
原创粉丝点击