简体   繁体   English

我怎样才能让我的指数移动平均线反映与我在雅虎财经上定义的相同的价值?

[英]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.

相关问题 我将如何计算指数移动平均线? - How would I calculate the Exponential Moving Average? 如何在 Python 中使用 yahoo_fin 计算移动平均线? - How can I calculate the moving average with yahoo_fin in Python? 如何计算 Python 中的指数移动平均线 - How do I calculate the Exponential Moving Average in Python 如何使用 Python Selenium 登录雅虎金融? - How can I log in to Yahoo FInance using Python Selenium? 我如何让外汇行情在雅虎金融工作? - How do I get a forex ticker working in yahoo finance? 在不考虑周末的情况下,如何确保日期显示为 Yahoo Finance/Google Finance 中的日期? - How can I make sure that dates display as in Yahoo Finance / Google Finance without accounting for weekends? 使用 python 和 yahoo 金融(还有其他东西)如何在 X 天的整个交易日内获取资产价格的数据 - Using python and yahoo finance (so something else) how can I get data for the price of an an asset throughout a trading day for X number of days 如何修复我的 python Yahoo Finance Webscrapper 中的类型错误、解析和所有其他错误 - How do I fix TypeError, Parsing, and all other errors in my python Yahoo Finance Webscrapper 如何通过解析包含代码列表的文本文件来刮取Yahoo Finance? - How can I scrape Yahoo Finance by parsing through a text file containing a list of tickers? 如何通过 pandas 和 yahoo finance 获取“USDJPY”(货币汇率)? - How can get ' USDJPY'(currency rates) with pandas and yahoo finance?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM