克隆策略
In [1]:
import matplotlib.pyplot as plt
In [2]:
zhisu=D.history_data(instruments=['000001.SHA'], start_date='2012-01-01', end_date=None,
               fields=['open', 'high', 'low', 'close'])
zhisu['return'] = zhisu['close'].shift(250) /zhisu['close'] - 1
zhisu['return']=zhisu['return']*100
In [3]:
df=D.macro_data(start_date='2012-01-01', end_date=None, fields=['ppi', 'gdp','m2'])
In [4]:
data= zhisu.merge(df, 'left', ['date']) 
data.dropna(inplace=True)
In [5]:
data['cha']=data['m2']-data['return']
In [6]:
data['biao']=(zhisu['close']-zhisu['close'].min())/(zhisu['close'].max()-zhisu['close'].min())
In [7]:
plt.plot(data.biao*200)
plt.plot(data.cha)
Out[7]:
[<matplotlib.lines.Line2D at 0x7f01435772b0>]
In [8]:
plt.plot(data.cha)
Out[8]:
[<matplotlib.lines.Line2D at 0x7f01324c9f98>]