We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
mytt.py的py2版本中,SMA定义为:
def SMA(S, N, M=1): #中国式的SMA,至少需要120周期才精确 (雪球180周期) alpha=1/(1+com) return pd.ewma(S,com=N-M,adjust=True)
已知: alpha =1/(1+com)
又知道,SMA正确的alpha是M/N alpha = M/N
容易求出: com = N/M-1=(N-M)/M
所以,py2中SMA中正确的定义应该是:
def SMA(S, N, M=1): #中国式的SMA,至少需要120周期才精确 (雪球180周期) alpha=1/(1+com) return pd.ewma(S,com=((N-M)*1.0)/M,adjust=False)
或者:
def SMA(S, N, M=1): #中国式的SMA,至少需要120周期才精确 (雪球180周期) alpha=1/(1+com) return pd.ewma(S,com=(N*1.0)/M - 1,adjust=False)
注意到画蛇添足地乘以了1.0,是因为直接除,py2中会变成整除。先乘以1.0,int转化为float后,再除,就是正确的了。
已经在一创聚宽验证过了,上述两个修改版,计算结果都是正确的。
The text was updated successfully, but these errors were encountered:
感谢,已经修正
Sorry, something went wrong.
No branches or pull requests
mytt.py的py2版本中,SMA定义为:
已知:
alpha =1/(1+com)
又知道,SMA正确的alpha是M/N
alpha = M/N
容易求出:
com = N/M-1=(N-M)/M
所以,py2中SMA中正确的定义应该是:
或者:
注意到画蛇添足地乘以了1.0,是因为直接除,py2中会变成整除。先乘以1.0,int转化为float后,再除,就是正确的了。
已经在一创聚宽验证过了,上述两个修改版,计算结果都是正确的。
The text was updated successfully, but these errors were encountered: