I am looking for a way to compute YTD return and I found this question (calculate YTD return / find first available datapoint of a year in python), however, it seems that it does not include the paid dividend in the year. How can I compute YTD return including the paid dividends?
My goal is to add this into my Python code for more accurate backtesting, so I would appreciate it if your answer considers Python implementation.