In [1]:
from sys import path
path.append('/home/bingnan/ecworkspace/HFT1')
In [2]:
%matplotlib inline
In [3]:
from init import *
In [4]:
_xin_mean = xin.mean(axis=0)
_xin_std = xin.std(axis=0)
xin_stdzd = (xin - _xin_mean) / _xin_std
xout_stdzd = (xout - _xin_mean) / _xin_std
xtest_stdzd = (xtest - _xin_mean) / _xin_std
In [5]:
yin2 = yin.ix[::50]
print len(yin2)
yout2 = yout.ix[::15]
print len(yout2)
In [60]:
def Lag_and_Corr(x, y, max_lag=50):
# max_lag = 50
lag_arr = range(-max_lag, max_lag, 1)
corr_arr = np.zeros_like(lag_arr, dtype=float)
for i, lag in enumerate(lag_arr):
x_lag = x.shift(periods=lag, axis=0)
x_with_y = pd.concat([x_lag, y], axis=1)
x_with_y.dropna(inplace=True)
corr = np.corrcoef(x_with_y.values.T)[0, 1]
corr_arr[i] = corr
return (lag_arr, corr_arr)
In [77]:
%matplotlib inline
In [79]:
for i in range(80):
lag_arr, corr_arr = Lag_and_Corr(xin_stdzd.ix[:, i], yin, 10)
plt.plot(lag_arr, corr_arr, marker='D')
plt.ylim([-.3, .3])
plt.xlabel('periods (parameter in pd.shift func)')
plt.ylabel('Coef. of Corr')
plt.title('X%d' %i)
plt.savefig('./lag_and_corr/lag_and_corr_X%d' % i)
plt.close()
print '%d done' % i
In [65]:
plt.plot(lag_arr, corr_arr)
Out[65]:
In [74]:
temp = xin_stdzd.ix[:30, 3].copy()
pd.concat([temp, temp.shift(periods=1, axis=0)], axis=1)
Out[74]:
In [28]:
temp1.dropna(inplace=True)
In [31]:
np.corrcoef(temp1.values.T)
Out[31]:
In [ ]: