本周市场,美股A股一齐下跌,沪深300下跌10.08%,标普500下跌5.16%,道指更是两次单日下跌超过1000点。由于美股A股存在高度的相关性,能否利用美股隔夜收益情况,对A股市场投资进行指导呢? 这里针对美股隔夜收益,与A股表现进行相关性分析。
import matplotlib
import scipy
import matplotlib.pyplot as plt
# 读取美股数据
dataM = D.history_data(instruments=['SPX.NYSE'], start_date='2010-01-01', end_date='2018-02-01',fields=['open', 'high', 'low', 'close'])
dataM.index = dataM['date']
dataM.head()
# 读取A股数据
dataA = D.history_data(instruments=['000300.SHA'], start_date='2010-01-01', end_date='2018-02-01',fields=['open', 'high', 'low', 'close'])
dataA.index = dataA['date']
dataA.head()
# 合并数据
dataA['closeM'] = dataM['close']
dataA.dropna(axis=0, how='any',inplace='True')
dataA.head()
# 计算美股隔夜收益
dataA['dM'] = np.nan
dataA['dM'][1:] = np.array(dataA['closeM'][1:])/np.array(dataA['closeM'][0:-1])-1
dataA.dropna(axis=0, how='any',inplace='True')
dataA.head()
# 分析美股隔夜收益与A股当日收益
hs300closeReturn = np.array(dataA['close'][1:])/np.array(dataA['close'][0:-1])-1
coeff = np.corrcoef(np.array(dataA['dM'][0:-1]), (hs300closeReturn))
fig = plt.figure()
axes = fig.add_axes([1.5, 1.5, 1.5, 1.5])
plt.axis([-8, 8, -8, 8])
plt.plot(100*dataA['dM'][0:-1], 100*hs300closeReturn, '.')
plt.grid(True, color = "k",linestyle =':')
plt.title('SP500 Overnight Returns - HS300 Close Returns')
plt.xlabel('SP500 Overnight Returns(percent)')
plt.ylabel('HS300 Close Returns(percent)')
z2 = np.polyfit(np.array(dataA['dM'][0:-1]), hs300closeReturn, 1)
p = np.poly1d(z2)
fx = scipy.linspace(-8, 8, 1000)
plt.plot(fx, p(fx), linewidth=1)
print ('SP500隔夜收益与HS300当日收益相关系数:',coeff[1][0])
相关系数达到了0.15,说明美股隔夜收益与A股当日收益相关性明显。 当日收益可以拆分成开盘收益和盘中收益,下面分别分析美股隔夜收益与这两个变量的相关性。
# 分析美股隔夜收益与A股当日开盘收益
hs300openReturn = np.array(dataA['open'][1:])/np.array(dataA['close'][0:-1])-1
coeff = np.corrcoef(np.array(dataA['dM'][0:-1]), (hs300openReturn))
fig = plt.figure()
axes = fig.add_axes([1.5, 1.5, 1.5, 1.5])
plt.axis([-8, 8, -8, 8])
plt.plot(100*dataA['dM'][0:-1], 100*hs300openReturn, '.')
plt.grid(True, color = "k",linestyle =':')
plt.title('SP500 Overnight Returns - HS300 Open Returns')
plt.xlabel('SP500 Overnight Returns(percent)')
plt.ylabel('HS300 Open Returns(percent)')
z2 = np.polyfit(np.array(dataA['dM'][0:-1]), hs300openReturn, 1)
p = np.poly1d(z2)
fx = scipy.linspace(-8, 8, 1000)
plt.plot(fx, p(fx), linewidth=1)
print ('SP500隔夜收益与HS300开盘收益相关系数:',coeff[1][0])
可以看出,美股隔夜收益与A股开盘收益高度正相关,相关系数达到0.44。
# 分析美股隔夜收益与A股当日盘中收益
hs300IntradayReturn = np.array(dataA['close'][1:])/np.array(dataA['open'][1:])-1
coeff = np.corrcoef(np.array(dataA['dM'][0:-1]), (hs300IntradayReturn))
fig = plt.figure()
axes = fig.add_axes([1.5, 1.5, 1.5, 1.5])
plt.axis([-8, 8, -8, 8])
plt.plot(100*dataA['dM'][0:-1], 100*hs300IntradayReturn, '.')
plt.grid(True, color = "k",linestyle =':')
plt.title('SP500 Overnight Returns - HS300 Intraday Returns')
plt.xlabel('SP500 Overnight Returns(percent)')
plt.ylabel('HS300 Intraday Returns(percent)')
z2 = np.polyfit(np.array(dataA['dM'][0:-1]), hs300IntradayReturn, 1)
p = np.poly1d(z2)
fx = scipy.linspace(-8, 8, 1000)
plt.plot(fx, p(fx), linewidth=1)
print ('SP500隔夜收益与HS300当日盘中收益相关系数:',coeff[1][0])
这里可以看出,美股隔夜收益,与A股盘中收益相关性不高,呈现弱的负相关。 因此,美股隔夜收益的信息,大部分在A股当日开盘价中得到了体现。
如果在当日开盘买入,次日开盘卖出,美股隔夜信息会有怎样的相关性呢?
# 分析美股隔夜收益与A股当日开盘买入次日开盘卖出
hs300dayReturn = np.array(dataA['open'][2:])/np.array(dataA['open'][1:-1])-1
coeff = np.corrcoef(np.array(dataA['dM'][0:-2]), hs300dayReturn)
fig = plt.figure()
axes = fig.add_axes([1.5, 1.5, 1.5, 1.5])
plt.axis([-8, 8, -8, 8])
plt.plot(100*dataA['dM'][0:-2], 100*hs300dayReturn, '.')
plt.grid(True, color = "k",linestyle =':')
plt.title('SP500 Overnight Returns - HS300 Day Returns')
plt.xlabel('SP500 Overnight Returns(percent)')
plt.ylabel('HS300 Day Returns(percent)')
z2 = np.polyfit(np.array(dataA['dM'][0:-2]), hs300dayReturn, 1)
p = np.poly1d(z2)
fx = scipy.linspace(-8, 8, 1000)
plt.plot(fx, p(fx), linewidth=1)
print ('SP500隔夜收益与HS300当日开盘买入次日开盘卖出收益相关系数:',coeff[1][0])
美股隔夜收益与A股当日开盘买入次日开盘卖出,呈现较弱的负相关。
初步分析结论: (1)美股隔夜收益与A股当日收益相关性明显; (2)美股隔夜收益的信息,大部分已经在A股开盘价上得到了体现; (3)美股隔夜收益,与A股盘中走势相关性,明显弱于其与A股开盘收益的相关性。能否利用该信息,还需要进一步研究。