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:
df['ema48'] = ta.ema(df.close, length=48)
Tried using the 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. Using both calculations, I got 1991.70 today at 08:39 whilst YF displayed 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))
