策略原理

策略基本思路是:买入低于X元的股票, 持有到1.25X元以上则卖出.

  1. start = datetime(2014, 6, 1)
  2. end = datetime(2015, 3, 27)
  3. benchmark = 'HS300' # 策略参考标准
  4. universe = set_universe('HS300')
  5. capital_base = 1000000
  6. def initialize(account):
  7. account.buy_price_flag = 4
  8. account.sell_price_flag = account.buy_price_flag*1.25
  9. def handle_data(account):
  10. signals = []
  11. acc_cash = account.cash
  12. for stock in account.universe:
  13. p = account.referencePrice[stock]
  14. if p < account.buy_price_flag:
  15. #满足买入条件,加入signals列表中
  16. signals.append(stock)
  17. elif p >= account.sell_price_flag and account.secpos.get(stock, 0) > 0:
  18. #将卖出股票所得现金加入到本次的可用现金
  19. acc_cash += account.referencePrice[stock]*account.secpos.get(stock,0)
  20. order_to(stock, 0)
  21. for stock in signals:
  22. # 平均买入signals列表中的股票
  23. amount = acc_cash/len(signals)/account.referencePrice[stock]
  24. order(stock, amount)

策略原理 - 图1