Skip to content

linear_decay按定义应是权重逐渐递减 #3

@damondd

Description

@damondd

decay_linear(x,d) = weighted moving average over the past d days with linearly decaying weights d,d-1,…,1 (rescaled up to 1)
x中时间从最远到最近的值,分别乘权重d,d-1,…,1(权重要进行标准化,使和为1)

def linear_decay(data, window):
result = pd.DataFrame(np.nan, index=data.index, columns=data.columns)
weight = np.arange(window) + 1.
weight = weight / weight.sum()
for i in range(window, data.shape[0]):
t = data.index[i]
result.ix[t, :] = data[i-window:i].T.dot(weight)
return result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions