11.1 VWAP · Value-Weighted Average Price (VWAP)

来源:https://uqer.io/community/share/55462234f9f06c1c3d688033

You can find it in API doc

  1. start = '2011-01-01' # 回测起始时间
  2. end = '2015-01-01' # 回测结束时间
  3. benchmark = 'SH50' # 策略参考标准
  4. universe = set_universe('SH50')
  5. capital_base = 100000 # 起始资金
  6. longest_history = 40 # handle_data 函数中可以使用的历史数据最长窗口长度
  7. refresh_rate = 1 # 调仓频率,即每 refresh_rate 个交易日执行一次 handle_data() 函数
  8. threshold = 0.03
  9. def initialize(account): # 初始化虚拟账户状态
  10. pass
  11. def handle_data(account): # 每个交易日的买入卖出指令
  12. for s in account.universe:
  13. try:
  14. inter = 20
  15. hist = account.get_symbol_history(s, inter)
  16. except:
  17. continue
  18. vwampvalue = sum(hist['turnoverValue'])/sum(hist['turnoverVol'])
  19. if(hist['lowPrice'][-1] < vwampvalue*(1 - threshold)) and (s not in account.valid_secpos):
  20. order(s,100)
  21. if(hist['lowPrice'][-1] > vwampvalue) and (s in account.valid_secpos):
  22. order_to(s,0)

11.1 VWAP · Value-Weighted Average Price (VWAP) - 图1

easy strategy.. bad results….

It's very difficult to get a good alpha……