Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

贡献两个函数:WMA函数及FORCAST函数 #21

Open
qzhjiang opened this issue Nov 22, 2021 · 3 comments
Open

贡献两个函数:WMA函数及FORCAST函数 #21

qzhjiang opened this issue Nov 22, 2021 · 3 comments

Comments

@qzhjiang
Copy link

def WMA(X, n):
    # type: (np.ndarray, int) -> np.ndarray
    """
    通达信WMA, X的N日加权移动平均,算法 Yn = (1*X1+2*X2+3*X3+...+n*Xn)/(1+2+3+...+Xn)
    :param X: 数组。源数据。

    :param n: 整数。周期。
    :return: 数组。X的N日加权移动平均
    """
    weights = np.array(range(1, n + 1))
    w = weights / np.sum(weights)
    S = pd.Series(X)

    res = S.rolling(window=n).apply(lambda x: np.sum(w * x), raw=False).values
    return res


def FORCAST(X, n):
    # type: (np.ndarray, int) -> np.ndarray
    """
    通达信FORCAST. 返回X的线性回归预测值,n暂时不支持变量
    参考资料:[FORCAST函数的真实含义](http://www.70822.com/soft/sort013/sort03/down-18804.html)
    
    :param X: 数组。源数据。
    :param n: 整数。周期。
    :return: 数组。线性回归预测值
    """
    return 3 * WMA(X, n) - 2 * MA(X, n)

FORCAST函数的实现,很另类,但反复核对,正确无误。

@qzhjiang
Copy link
Author

具体见我发在聚宽社区的文章:
[通达信WMA函数及FORCAST函数的Python实现] ( https://www.joinquant.com/view/community/detail/35525)

@yglpyn8888
Copy link

你好,看到你在聚宽发表的很多文章受益匪浅,想问下你之前阅读过网络上通达信或PYTHON上有好的趋势线算法的实现吗? 我在网上找过多个通达信的画趋势线公式,但都不甚理想。。谢谢!

@toolgood
Copy link

通达信导出后,经测试完全正确

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants