Portfolio Returns

Course Name: Python for Trading: Basic, Section No: 10, Unit No: 1, Unit type: Notebook

 

I am not able to understand why cumprod on percentage change gives us  the portfolio returns.

To understand why cumprod() on percentage changes gives us the portfolio returns, we need to break down the code and understand the underlying concepts.



First, the monthly_percent_change dataframe contains the monthly percentage changes of different stocks. Each column represents a particular stock, and each row represents the monthly percentage change of that stock.



Second, to calculate the portfolio returns, we take the mean of the monthly percentage changes of all the stocks. This gives us a single value for each month that represents the average monthly return of the portfolio.



Third, to calculate the cumulative portfolio returns, we need to use the cumprod() function. This function calculates the cumulative product of the input array. We add 1 to the portfolio returns because we want to calculate the total returns, not just the return for that month. The cumulative product then gives us the total return of the portfolio over time.



For example, let's say that the portfolio returns for three months are 1%, 2%, and 3%. If we calculate the cumulative product of these returns using cumprod(), we get the following:

(1 + 0.01) * (1 + 0.02) * (1 + 0.03) = 1.0606



This means that the portfolio returns for the three months combined is 6.06%.



Thank you.

Thanks for your answer. I understood well now.