[关闭]
@Channelchan 2017-07-08T15:47:11.000000Z 字数 789 阅读 35957

Pair_Trading


什么是统计套利?

统计套利是根据价差同时买入与卖出一样或极为相似的品种。


统计套利有哪些策略?

跨市场套利: 不同市场的相同或相似资产
期现套利: 期货与现货市场
跨期套利: 同一品种不同月份期限的合约
跨品种套利: 品种不同但高度相关
期权套利: 蝶式鹰式


如何执行价差套利策略?

价差区间超买超卖交易(买弱卖强)
在上安全边际买入弱的卖出强的
反向交易(买强卖弱)
在上穿均值后买入强的卖出弱的
在更强的位置重复加仓
在穿越安全边际后继续做空价差


常用代码:

  1. def init(context):
  2. context.s1 = '002290.XSHE'
  3. context.s2 = '002508.XSHE'
  4. def handle_bar(context, bar_dict):
  5. his1 = history_bars(context.s1, 50, '1d', 'close')
  6. his2 = history_bars(context.s2, 50, '1d', 'close')
  7. beta, alpha = np.polyfit(his1,his2,1)
  8. spread = his2 - (beta*his1+alpha)
  9. z_score = (spread-spread.mean())/spread.std()
  10. print z_score
  11. try:
  12. if z_score[-1]>1:
  13. order_target_percent(context.s1, 1)
  14. order_target_percent(context.s2, 0)
  15. elif z_score[-1]<-1:
  16. order_target_percent(context.s2, 1)
  17. order_target_percent(context.s1, 0)
  18. except KeyError:
  19. pass

notebook链接: http://localhost:8889/tree/Class_5_Statistical_Arbitrage

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注