有没有办法解决ValueError:操作数不能与Python pyfinance包中的重新映射形状一起广播

问题描述

我得到的错误

 [original->remapped]: (2552,4,90)->(2552,newaxis,newaxis) (2603,90,1)->(2603,newaxis) and requested shape (4,1)

我正在使用pyfinace软件包。导致错误的行

  model = PandasRollingOLS(y=ETF_return[c],x=df_FF,window=90)

这是代码

if __name__ == '__main__':
    #e)For each sector ETF,compute it’s β to the Fama-french factors using the above model.
    tickers = ['SPY','XLB','XLE','XLF','XLI','XLK','XLP','XLU','XLV','XLY']
    ETFs = ETF(tickers)
    price_data = ETFs.get_data("2010-01-01","2020-09-12")
    ETF_return = ETFs.return_data1()
    def Linear_reg(X,y,return_value):
        df = pd.merge(X,left_index=True,right_index=True)
        est = sm.OLS(df.iloc[:,-1],df.iloc[:,:3],missing='drop')
        result = est.fit()
        if return_value == 'beta':
            return result.params
        elif return_value == 'residual':
            return result.resid #y - est.predict()
    beta = ETF_return.apply(lambda x: Linear_reg(df_FF,x,return_value='beta'))
    print(beta.head)

    res = ETF_return.apply(lambda x: Linear_reg(df_FF,return_value='residual'))
    print("*****************************RESIDUAL********************************")
    print(res)

    beta_result = {}
    plt.figure(figsize = (15,40),dpi=120)
    for i,c in enumerate(ETF_return):
        plt.subplot(5,2,i+1)
        model = PandasRollingOLS(y=ETF_return[c],window=90)
        beta_result[c] = model.beta
        model.beta.plot(ax = plt.gca())

``

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)