[英]How can I get my exponential moving average to reflect the same value as the one I defined on Yahoo Finance?
How can I get my exponential moving average to reflect the same value as the one I defined on Yahoo Finance?我怎样才能让我的指数移动平均线反映与我在雅虎财经上定义的相同的价值?
I've tried using the pandas_ta package to calculate them as follows:我尝试使用 pandas_ta package 来计算它们,如下所示:
df['ema48'] = ta.ema(df.close, length=48)
Tried using the pandas package:尝试使用 pandas package:
df['ema48'] = pd.Series.ewm(df['close'], span=48).mean()
When on Yahoo Finance, I click on on 'Moving average', change period to 48, and change type to 'Exponential' (and 'Close' is selected as field) but my code doesn't return the same value as seen on YF.在 Yahoo Finance 上时,我单击“移动平均线”,将周期更改为 48,并将类型更改为“指数”(并且选择“关闭”作为字段),但我的代码没有返回与 YF 上相同的值. Using both calculations, I got 1991.70 today at 08:39 whilst YF displayed 1992.00.
使用这两种计算,我今天 08:39 得到了 1991.70,而 YF 显示的是 1992.00。
minimal reproducible example最小可重现示例
from datetime import date, timedelta
import pandas as pd
import pandas_ta as pdta
import yfinance as yf
pair = 'ETH-GBP'
today = str(date.today())
yesterday = str(date.today() - timedelta(days=1))
def get_historical_data(symbol, start_date, interval):
df1 = yf.download(symbol, start=start_date, interval=interval)
df1 = df1.drop(columns=['Open', 'High', 'Low', 'Adj Close', 'Volume'])
df1 = df1.astype(float)
return df1
df = get_historical_data(pair, yesterday, '1m')
df['ema48'] = pdta.ema(df.Close, length=48)
df['ema48two'] = pd.Series.ewm(df['Close'], span=48).mean()
print(df.tail(1))
I got the same value in both columns, did you check it twice?我在两列中都得到了相同的值,你检查了两次吗?
I just copied your code and ran it on my computer.我刚刚复制了您的代码并在我的计算机上运行它。
By the way, this is the code of the pandas_ta function, take a look to it in case that you want to know further, it seems to me that if you have TA installed you might see little differences but at the end both columns should converge to the same value.顺便说一句,这是 pandas_ta function 的代码,如果您想进一步了解,请查看它,在我看来,如果您安装了 TA,您可能会看到一些差异,但最后两列应该会聚为相同的值。
https://github.com/twopirllc/pandas-ta/blob/main/pandas_ta/overlap/ema.py https://github.com/twopirllc/pandas-ta/blob/main/pandas_ta/overlap/ema.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.