ShareData.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:SharesData 作者: xjkj123 项目源码 文件源码
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']]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号