Workspace Add Analysis>EMA display different numbers than pd.ewm using Python

Using the following snippet as in a former question [Is it possible to pull Exponential Moving Average data using the RD Library?](https://community.developers.refinitiv.com/discussion/112022/is-it-possible-to-pull-exponential-moving-average-data-using-the-rd-library/p1?tab=accepted) for `TSLA.O` will give an EMA endpoint estimate of `412.071` at the time of writing.

Code:

import refinitiv.data as rd
rd.open_session()
import pandas as pd

df = rd.get_data(
universe = ['TSLA.O'],
fields = ['TR.PriceCloseDate','TR.PriceClose'],
parameters={"SDate":"-50" , "EDate":"0"})
df['EMA 10'] = df['Price Close'].ewm(span=10).mean().round(3)
df

Output:

image.png

I find it a bit puzzling that using Add Analysis > Moving Average Exponential produces different numbers. The three last numbers from the same scenario in the screenshot below are : 412.064, 415.999 and 418.578

image.png

And here are the settings for the EMA:

image.png

Does anyone know the exact method for EMA that us used in Workspaces.

Or does anyone have a possible explanation for the differences here?

Best Answers

  • arne_petter
    arne_petter Newcomer
    Answer ✓

    Thank you for your suggestion! The numbers may be similar, but definitely not equal as far as I can tell..? Do you have any further suggestions?

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @arne_petter

    I found that the first calculated values are different. On Workspace, the EMA 10 value on 13 Jul 10 is 1.272.

    image.png

    I found that the pandas_ta package can calculate the EMA values properly.

    import pandas_ta  as ta
    
    df = ld.get_data(
        universe = ['TSLA.O'],
        fields = ['TR.PriceCloseDate','TR.PriceClose'],
        parameters={"SDate":"2010-06-29" , "EDate":"0"})
    
    df["EMA 10"] = ta.ema(df["Price Close"], length=10).round(3)
    
    

Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭

    @arne_petter

    Thank you for reaching out to us.

    It may relate to the start date (SDate). I think Workspace calculates EMA since the first date.

    df = rd.get_data(
        universe = ['TSLA.O'],
        fields = ['TR.PriceCloseDate','TR.PriceClose'],
        parameters={"SDate":"2010-06-29" , "EDate":"0"})
    
    df['EMA 10'] = df['Price Close'].ewm(span=10).mean().round(3)
    df
    
    image.png

    Moreover, if I change the SDate to -100, the data is similar to Workspace.

    df = rd.get_data(
        universe = ['TSLA.O'],
        fields = ['TR.PriceCloseDate','TR.PriceClose'],
        parameters={"SDate":"-100" , "EDate":"0"})
    
    df['EMA 10'] = df['Price Close'].ewm(span=10).mean().round(3)
    df
    
    image.png