def Beta(self):
prixe = math.log(0.03637 / float(365) + 1)
df1 = self.sharedf
df1['change']=df1['change']-prixe
df2 = ShareClass().GetDayData(code='000001',zs=True)
print 11111111111
coef = []
intercept = []
residues=[]
ret= pandas.merge(df1,df2,how='inner',on='date')
array2 = []
if len(ret) > 252:
for z in range(0, 252):
array2.append(math.pow(math.pow(float(1) / 2, float(1 / float(63))), (252 - z - 1)))
for z in range(0, 251):
coef.append(numpy.NaN)
intercept.append(numpy.NaN)
residues.append(numpy.NaN)
for c in range(252, len(ret)+1):
array=[]
for x in ret[c - 252:c]['change_x']:
array.append([x])
clf = linear_model.LinearRegression()
clf.fit(X=array, y=ret[c - 252:c]["change_y"], sample_weight=array2)
coef.append(float(clf.coef_))
residues.append(clf._residues)
intercept.append(float(clf.intercept_))
ret['beta'] = coef
ret['alpha'] = intercept
ret['residues'] = residues
return ret[['date','beta','alpha','residues']]
评论列表
文章目录