python13 之线性回归(WLS加权最小二乘法)

加权最小二乘法(weighted least square,WLS)回归。

OLS是minimize sum(residuals^2),而WLS是minimize sum(w*residuals^2),即将权数与残差平方相乘后再求和,所以要先定义权重。

1. WLS 加权回归

import statsmodels.api as sm 

x = factor0_market2

y = returns0_market2

model = sm.WLS(y, x, weights=weight1).fit()

z = model.params[:]

barra_returns.loc[:, this_day[i]] = z

x:

 

y:

 

weight1:

 

 

作者:HaileeRPIJNU 原文地址:https://blog.csdn.net/HaileeRPIJNU/article/details/127861943

%s 个评论

要回复文章请先登录注册