I've recently created a Python package called pyTAA as a side hobby to analyse low-frequency strategies. This is very much in alpha and can change at any point in time. To answer your question, I've added some tools to do precisely what you're asking. You can find the implementation here, all that is needed is yfinance
really.
And a small code snippit to compare price vs total returns:
from pytaa.backtest.returns import get_historical_total_return
from pytaa.tools.data import get_historical_price_data
start, end = "2013-01-01", "2023-05-01"
assets = ["SPY", "AGG", "IEF", "GLD", "EEM"]
prices = get_historical_price_data(assets, start, end).loc[:, "Close"]
total_returns = get_historical_total_return(prices, "USD", "total")
price_returns = get_historical_total_return(prices, "USD", "price")
# plot price returns
cpr = price_returns.add(1).cumprod()
cpr.plot(figsize=(8,5), title="Cumulative Price Returns")
print(cpr.tail(1).rank(axis=1, ascending=False))
# plot total returns
ctr = total_returns.add(1).cumprod()
ctr.plot(figsize=(8,5), title="Cumulative Total Returns")
ctr.tail(1).rank(axis=1, ascending=False)
# show the last period cum returns
comp = pd.concat([
cpr.tail(1).rename({cpr.index[-1]: "Price Return"}),
ctr.tail(1).rename({ctr.index[-1]: "Total Return"})
])
comp.index.name = ""
comp.mul(100).round(2)
