我在聚宽上的斜率公式是这样的
def get_rank(etf_pool):
score_list = []
for etf in etf_pool:
df = attribute_history(etf, 20, '1d', ['close'])
y = df['log'] = np.log(df.close) #对收盘价取对数并添加log列
x = df['num'] = np.arange(df.log.size)#返回一个log列的元素数量的等差数列
slope, intercept = np.polyfit(x, y, 1)#进行线性拟合,求出斜率与截距
annualized_returns = math.pow(math.exp(slope), 250) - 1#计算年化收益率
r_squared = 1 - (sum((y - (slope * x + intercept))**2) / ((len(y) - 1) * np.var(y, ddof=1)))#R^2,一般为0-1的值,值越大,拟合度越高
score = annualized_returns * r_squared#风险调整的得分
但在果仁上不知道如何实现
