以茅台和五粮液研究配对交易策略
“”" 以茅台和五粮液研究配对交易策略 以茅台和五粮液近4年的行情,分析出两者之间的线性关系,根据y=ax+b+ζ公式,计算出ζ值,ζ趋向于零,表示y和x具有稳定性,ζ过大或者ζ过小,都具有套利机会,ζ都具有回归到零的机会。 “”" #抓取茅台和五粮液近4年的行情 mt = ts . get_k_data ( '600519' , start = '2015-01-01' , end = '2019-12-31' , ktype = 'D' ) [ [ 'date' , 'close' ] ] wly = ts . get_k_data ( '000858' , start = '2015-01-01' , end = '2019-12-31' , ktype = 'D' ) [ 'close' ] data = pd . concat ( [ mt , wly ] , axis = 1 ) data . set_index ( 'date' , inplace = True ) data . index = pd . to_datetime ( data . index ) data . columns = ( [ '600519' , '000858' ] ) #简单地看看两者的价格走势 data . plot ( figsize = ( 10 , 6 ) )