I am working on adjusting the prices for dividends and therefore need to calculate total return index for every given day. This is the function is wrote:
def get_ts_for_ric(ric): ric_tr = ek.get_data(ric, ["TR.TotalReturn.date","TR.TotalReturn.value"], parameters={"Frq": "D", "SDate": "2011-01-01", "EDate": "2020-12-31"})[0].set_index("Date").sort_index() for i in range(ric_tr.shape[0]): if i == 0: ric_tr.loc[ric_tr.index[i], 'tri'] = 1 + ric_tr['value'][i]/100 else: ric_tr.loc[ric_tr.index[i], 'tri'] = ric_tr['tri'][i-1] * (1 + ric_tr['value'][i]/100) ric_close = ek.get_data(ric, ['TR.ClosePrice.Date', 'TR.ClosePrice.Value'], parameters={"Frq": "D", "SDate": "2011-01-01", "EDate": "2020-12-31"})[0].set_index("Date").sort_index().dropna() ric_ts = ric_tr.join(ric_close['Close Price'], how='inner') cp_to_tri = ric_ts['Close Price'][-1]/ric_ts['tri'][-1] ric_ts['adjusted'] = ric_ts['tri'] * cp_to_tri return ric_ts
When I use it for a RIC, for example:
get_ts_for_ric('PKN.WA')
I get the following last row as a result:
So that the total return index ('tri' column) indicates a Total Return for the period of 48,88%.
However when I try to get from the API the Total Return for this period directly:
ek.get_data('PKN.WA',['TR.TotalReturn'],{'SDate':'2011-01-01', 'EDate':'2020-12-31'})[0]
I get this:
So over 10 percentage points more than calculated from daily total returns.