成交量因子

来源:https://uqer.io/community/share/5652bf20f9f06c4446b48636

投资于沪深300成份股,每月调仓,每月调入成交量最低的成份股

  1. start = '2015-1-1' # 回测起始时间
  2. end = '2015-11-22' # 回测结束时间
  3. benchmark = 'HS300' # 策略参考标准
  4. universe = set_universe('HS300') # 证券池,支持股票和基金
  5. capital_base = 10000000 # 起始资金
  6. refresh_rate = 20 # 调仓频率,表示执行handle_data的时间间隔,若freq = 'd'时间间隔的单位为交易日,若freq = 'm'时间间隔为分钟
  7. stk_num = 60
  8. def initialize(account): # 初始化虚拟账户状态
  9. pass
  10. def handle_data(account): # 每个交易日的买入卖出指令
  11. #取出每日成交量
  12. hist = account.get_attribute_history('turnoverValue',1)
  13. #print account.current_date
  14. #print hist
  15. cjl = {}
  16. # 排序
  17. for stock in account.universe:
  18. cjl[stock] = hist[stock][0]
  19. dd = sorted(cjl.iteritems(),key = lambda d:d[1],reverse = False)
  20. #print dd
  21. cash = account.cash
  22. # 卖出持有的
  23. for s,a in account.valid_secpos.items():
  24. order_to(s,0)
  25. cash += a*account.referencePrice[s]
  26. # 买入
  27. i = 0
  28. for s in dd:
  29. if i < stk_num :
  30. i = i + 1
  31. order(s[0],cash/60/account.referencePrice[s[0]])
  32. #print s[0]

成交量因子 - 图1

  1. bt
tradeDatecashsecurity_positionportfolio_valuebenchmark_returnblotter
02015-01-06980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1000650.1468-0.000132[Order(order_time: 2015-01-06 09:30, symbol: 0…
12015-01-07980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1000573.24680.000750[]
22015-01-08980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1000781.2468-0.023198[]
32015-01-09980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1000992.8468-0.003523[]
42015-01-12980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001146.3468-0.009344[]
52015-01-13980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001283.94680.000131[]
62015-01-14980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001027.0468-0.003307[]
72015-01-15980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001017.44680.029037[]
82015-01-16980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001257.64680.008607[]
92015-01-19980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1000788.4468-0.077023[]
102015-01-20980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1001703.54680.012241[]
112015-01-21980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002298.94680.044950[]
122015-01-22980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002567.54680.005278[]
132015-01-23980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002212.64680.001155[]
142015-01-26980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002646.44680.010149[]
152015-01-27980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1003116.3468-0.009160[]
162015-01-28980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002968.9468-0.013877[]
172015-01-29980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002741.4468-0.012348[]
182015-01-30980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002465.6468-0.013614[]
192015-02-02980827.6468{u'002252.XSHE': {u'amount': 100, u'cost': 22….1002310.2468-0.023419[]
202015-02-03979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002687.75050.024890[Order(order_time: 2015-02-03 09:30, symbol: 6…
212015-02-04979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002527.6505-0.010380[]
222015-02-05979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002320.0505-0.010236[]
232015-02-06979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1001810.1505-0.016193[]
242015-02-09979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002149.15050.010113[]
252015-02-10979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002526.55050.018237[]
262015-02-11979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1002846.55050.007978[]
272015-02-12979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1003098.65050.002548[]
282015-02-13979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1003569.55050.007828[]
292015-02-16979846.9505{u'601158.XSHG': {u'amount': 400, u'cost': 7.9…1004382.45050.008548[]
1842015-10-12979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1011749.08470.032208[]
1852015-10-13979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1011658.0847-0.000769[]
1862015-10-14979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1011279.0847-0.011301[]
1872015-10-15979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1011943.08470.023694[]
1882015-10-16979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012667.08470.013551[]
1892015-10-19979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012613.08470.000033[]
1902015-10-20979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012848.08470.012314[]
1912015-10-21979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1011284.0847-0.029194[]
1922015-10-22979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012610.08470.014764[]
1932015-10-23979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1013730.08470.013252[]
1942015-10-26979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1013604.08470.005046[]
1952015-10-27979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1013456.08470.001008[]
1962015-10-28979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012937.0847-0.018915[]
1972015-10-29979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1013093.08470.002379[]
1982015-10-30979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012739.08470.000218[]
1992015-11-02979810.0847{u'601158.XSHG': {u'amount': 400, u'cost': 8.2…1012311.0847-0.016445[]
2002015-11-03984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1012266.4817-0.003012[Order(order_time: 2015-11-03 09:30, symbol: 6…
2012015-11-04984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1013422.48170.047048[]
2022015-11-05984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014069.48170.021340[]
2032015-11-06984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014599.48170.023585[]
2042015-11-09984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1015194.48170.012385[]
2052015-11-10984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1015158.4817-0.001853[]
2062015-11-11984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1015091.48170.000106[]
2072015-11-12984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014932.4817-0.009996[]
2082015-11-13984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014318.4817-0.012932[]
2092015-11-16984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014373.48170.004774[]
2102015-11-17984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014520.4817-0.001525[]
2112015-11-18984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014182.4817-0.011390[]
2122015-11-19984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014563.48170.015984[]
2132015-11-20984251.4817{u'600011.XSHG': {u'amount': 400, u'cost': 9.0…1014545.4817-0.000155[]
  1. 214 rows × 6 columns