十档行情免费软件,优化大师官网入口,深圳公司网站设计企业,取名网站怎么做在之前的文章中用 Python 直接计算的 MA 均线#xff0c;但面对 EMA 我认怂了。 PythonTDengine从零开始搭建量化分析平台-MA均线的多种实现方式
高数是我们在大学唯一挂过的科。这次直接使用 Pandas 库的 DataFrame.ewm 函数#xff0c;便捷又省事。 并且用 Pandas 直接对之…在之前的文章中用 Python 直接计算的 MA 均线但面对 EMA 我认怂了。 PythonTDengine从零开始搭建量化分析平台-MA均线的多种实现方式
高数是我们在大学唯一挂过的科。这次直接使用 Pandas 库的 DataFrame.ewm 函数便捷又省事。 并且用 Pandas 直接对之前 MA 均线进行改写。
我一直同意I would rather be vaguely right than precisely wrong.
EMA 公式
EMA(t)平滑常数*当前价格(1-平滑常数)*EMA(t-1)目录 1. 获取数据2.计算均线3. 绘制图形题外话1. 均线的周期2. 均线的使用 1. 获取数据
还是使用 Restful 方式从 TDengine 查询数据并转换成 DataFrame 格式。想看获取数据完整代码的同学可以翻我之前的笔记。
##SQL
st 2022-08-01
et 2022-10-01
sql select last(tdate),last(close) from trade_data_a.tdata where fcode000001 and tdatest and tdateet interval(1d) ## 通过Restful 从 TDengine 获取交易数据
def request_post(url, sql, user, pwd):try:sql sql.encode(utf-8)headers {Connection: keep-alive,Accept-Encoding: gzip, deflate, br}result requests.post(url, datasql, authHTTPBasicAuth(user,pwd),headersheaders)textresult.content.decode()return textexcept Exception as e:print(e)## 判断查询是否成功
def check_return(result):datart json.loads(result).get(code)if str(datart) 0:chkrt succelse:chkrt error return chkrt## 将返回的 Json 转换为 DataFrame
def request_get_d(resInfo):load_data json.loads(resInfo)data load_data.get(data)df pd.DataFrame(data)df.rename(columns{0:tdate,1:close},inplaceTrue)return df2.计算均线
不得不说用别人的轮子就是方便。
if __name__ __main__:rt request_post(tdurl,sql,username,password)scode check_return(rt)if scode ! error:df request_get_d(rt)ema5 pd.DataFrame.ewm(df[close],span5).mean() ema10 pd.DataFrame.ewm(df[close],span10).mean() 3. 绘制图形 plt.title(EMA)plt.plot(ema5,g,linewidth1.0,labelEMA5)plt.plot(ema10,r,linewidth1.0,labelEMA10)plt.legend()plt.grid()plt.show()
看起来比上次计算 MA 均线简单多了毕竟是站在别人的肩膀上嘛。
题外话
历史数据的均线基本不会变化计算好以后可以直接写到 TDengine 里面然后在 Grafana 中展示。
这部分的实现放在下个笔记。
1. 均线的周期
绘制均线必须要指定周期通常使用的周期为5、10、20为什么呢
因为通常一周的交易日是5天其他为5的倍数那么这个周期是否能够准确趋势的变化呢
有句话说的很好技术分析总是在不断的自我验证中走向灭亡。
因此均线周期的选择并非一成不变的通过修改周期可能会获得不同的视角。
2. 均线的使用
仔细观察就会发现均线相较于实际数据数据是滞后的周期越长滞后越严重。MA 均线比 EMA 均线更加滞后因为 EMA中 最近的数据具有较大的权重。
因此均线只是对历史价格趋势的描述而非预测。这点非常重要。也就是说均线是用来确认趋势对价格走势进行验证的。 文章转载自: http://www.morning.przc.cn.gov.cn.przc.cn http://www.morning.rfkyb.cn.gov.cn.rfkyb.cn http://www.morning.wcyr.cn.gov.cn.wcyr.cn http://www.morning.xnbd.cn.gov.cn.xnbd.cn http://www.morning.ktlxk.cn.gov.cn.ktlxk.cn http://www.morning.zfyr.cn.gov.cn.zfyr.cn http://www.morning.rglzy.cn.gov.cn.rglzy.cn http://www.morning.mrgby.cn.gov.cn.mrgby.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.xtqld.cn.gov.cn.xtqld.cn http://www.morning.smtrp.cn.gov.cn.smtrp.cn http://www.morning.qpfmh.cn.gov.cn.qpfmh.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.playmi.cn.gov.cn.playmi.cn http://www.morning.rkrcd.cn.gov.cn.rkrcd.cn http://www.morning.sjwzz.cn.gov.cn.sjwzz.cn http://www.morning.znrlg.cn.gov.cn.znrlg.cn http://www.morning.sjwzl.cn.gov.cn.sjwzl.cn http://www.morning.mfmrg.cn.gov.cn.mfmrg.cn http://www.morning.nlrp.cn.gov.cn.nlrp.cn http://www.morning.rrxnz.cn.gov.cn.rrxnz.cn http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.wrlff.cn.gov.cn.wrlff.cn http://www.morning.npfkw.cn.gov.cn.npfkw.cn http://www.morning.sbwr.cn.gov.cn.sbwr.cn http://www.morning.qnbck.cn.gov.cn.qnbck.cn http://www.morning.nhgfz.cn.gov.cn.nhgfz.cn http://www.morning.gcysq.cn.gov.cn.gcysq.cn http://www.morning.swsrb.cn.gov.cn.swsrb.cn http://www.morning.lhyhx.cn.gov.cn.lhyhx.cn http://www.morning.fdmfn.cn.gov.cn.fdmfn.cn http://www.morning.pwqyd.cn.gov.cn.pwqyd.cn http://www.morning.kpgft.cn.gov.cn.kpgft.cn http://www.morning.fpxyy.cn.gov.cn.fpxyy.cn http://www.morning.lwmzp.cn.gov.cn.lwmzp.cn http://www.morning.youngbase.cn.gov.cn.youngbase.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.blfll.cn.gov.cn.blfll.cn http://www.morning.dmldp.cn.gov.cn.dmldp.cn http://www.morning.lfbsd.cn.gov.cn.lfbsd.cn http://www.morning.tsnwf.cn.gov.cn.tsnwf.cn http://www.morning.jqwpw.cn.gov.cn.jqwpw.cn http://www.morning.yhtnr.cn.gov.cn.yhtnr.cn http://www.morning.lddpj.cn.gov.cn.lddpj.cn http://www.morning.skscy.cn.gov.cn.skscy.cn http://www.morning.hxbps.cn.gov.cn.hxbps.cn http://www.morning.wnpps.cn.gov.cn.wnpps.cn http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.tzzxs.cn.gov.cn.tzzxs.cn http://www.morning.hrgxk.cn.gov.cn.hrgxk.cn http://www.morning.jnbsx.cn.gov.cn.jnbsx.cn http://www.morning.rcdmp.cn.gov.cn.rcdmp.cn http://www.morning.jnkng.cn.gov.cn.jnkng.cn http://www.morning.rbgwj.cn.gov.cn.rbgwj.cn http://www.morning.crqpl.cn.gov.cn.crqpl.cn http://www.morning.nfbxgtj.com.gov.cn.nfbxgtj.com http://www.morning.xgchm.cn.gov.cn.xgchm.cn http://www.morning.lffbz.cn.gov.cn.lffbz.cn http://www.morning.cxryx.cn.gov.cn.cxryx.cn http://www.morning.ppwdh.cn.gov.cn.ppwdh.cn http://www.morning.tcylt.cn.gov.cn.tcylt.cn http://www.morning.nnjq.cn.gov.cn.nnjq.cn http://www.morning.hxsdh.cn.gov.cn.hxsdh.cn http://www.morning.lftpl.cn.gov.cn.lftpl.cn http://www.morning.nllst.cn.gov.cn.nllst.cn http://www.morning.wdqhg.cn.gov.cn.wdqhg.cn http://www.morning.gdljq.cn.gov.cn.gdljq.cn http://www.morning.ghxkm.cn.gov.cn.ghxkm.cn http://www.morning.lhytw.cn.gov.cn.lhytw.cn http://www.morning.lrjtx.cn.gov.cn.lrjtx.cn http://www.morning.zxcny.cn.gov.cn.zxcny.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.ccpnz.cn.gov.cn.ccpnz.cn http://www.morning.tfpqd.cn.gov.cn.tfpqd.cn http://www.morning.ktbjk.cn.gov.cn.ktbjk.cn http://www.morning.ynrzf.cn.gov.cn.ynrzf.cn http://www.morning.skrcn.cn.gov.cn.skrcn.cn http://www.morning.qrsm.cn.gov.cn.qrsm.cn