import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
cqlq = pd.read_excel("cqlq.xls",sep='s+')
dxnt = pd.read_excel("dxnt.xls",sep='s+')
cqlq.columns=["","date","open","high","low","close","vol","",""]
dxnt.columns=["","date","open","high","low","close","vol","",""]
ccqlq=cqlq['close']
cdxnt=dxnt['close']
rcqlq=(ccqlq-ccqlq.shift(1))/ccqlq.shift(1)
rdxnt=(cdxnt-cdxnt.shift(1))/cdxnt.shift(1)
r=pd.concat([rcqlq,rdxnt],axis =1)
r.dropna()
u=r.mean()+0.003
jz=r.cov()
yi=np.ones(2)
u=np.mat(u)
jz=np.mat(jz)
yi=np.mat(yi)
nijz=jz
a = u*nijz*u.T
b = yi*nijz*u.T
c = yi*nijz*yi.T
deta = a*c-b*b
sgp =[]
sy = []
for i in range(5):
rp = 0.0001*i
sy.append(rp)
ld1= (rp*c-b)/deta
ld2 = (a-rp*b)/deta
sgpi=np.sqrt(( c/deta)*(rp-b/c)**2+1/c)
sgpi = sgpi.max()
sgp.append(sgpi)
plt.plot(sgp,sy)
plt.show()
2020-05-27