ema指标,通过测试输出的结果和软件一致
import pandas as pddfad_csv(r'E:程序开发测试_阙辉PYTHON股票研究红米电脑备份MACD分析 00002.csv',encoding='gbk')# 默认按照列排序,即纵向排序;如果axis 为1,则是横向排序。
# by:str or list of str;如果axis=0,那么by="列名";如果axis=1,那么by="行名"。
# ascending:布尔型,True则升序,如果by=['列名1','列名2'],则该参数可以是[True, False],即第一字段升序,第二个降序。
# inplace:布尔型,是否用排序后的数据框替换现有的数据框。
# kind:排序方法,{‘quicksort’, ‘mergesort’, ‘heapsort’}, default ‘quicksort’。似乎不用太关心。
# na_position:{‘first’, ‘last’}, default ‘last’,默认缺失值排在最后面
df = df.sort_values(by=["日期"], axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')def QH_Get_EMA(qh_df,qh_days=5,qh_close = "收盘价"):qh_df = qh_dfqh_days = qh_daysqh_close = qh_closefor qh_i in range(len(qh_df)):qh_close_jia = qh_df.loc[qh_df.index[qh_i],qh_close] #当天收盘价if qh_i == 0:qh_ema = qh_close_jiaelif qh_i > 0:qh_close_ema = qh_df.loc[qh_df.index[qh_i - 1], "QH_EMA_{}".format(qh_days)] #前一日的emaqh_ema = ((qh_days - 1) * qh_close_ema + 2 * qh_close_jia) / (qh_days + 1)qh_df.loc[qh_df.index[qh_i], "QH_EMA_{}".format(qh_days)] = qh_emareturn qh_dfaa = QH_Get_EMA(df,qh_days=50)
print(aa)
aa_csv(r'E:程序开发测试_阙辉PYTHON股票研究红米电脑备份MACD分析 00002_ema.csv',encoding='gbk')
本文发布于:2024-01-30 22:45:46,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170662594923370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |