Retreive historical data for daily price change percent

Hello,

I tried to retrieve historical data for price change percent and price daily. The price part is ok but just last price change percent shows up.

Code:

1626283410320.png

Result:

1626283453274.png

Thanks in advance,

Best Answer

  • @Fatemeh

    The field TR.PricePctChg1D is not available as timeseries. In other words, it only returns the latest value and does not provide any history. See the answer on this thread for explanation how to check whether a field as available as timeseries or not.

    Fortunately it's very easy to calculate percent change from the price history using pandas:

    df, err = ek.get_data('.SPX',['TR.PriceCloseDate','TR.PriceClose'],
                         {'SDate':'2019-01-01','EDate':'2019-12-31'})
    df['Percent Chg'] = df['Price Close']/df['Price Close'].shift(1) -1
    df

Answers