I have a dataframe containing daily historical prices of assets, their returns, weights, portfolio return, cumulative portfolio return. Example as shown below. The data ranges from September 13, 2018 to September 13, 2022 (daily data). I want to test an allocation strategy of 30% QQQ, 50% SPY, and 20% GLD, but with semiannual rebalancing, e.g.: if my allocation on September 13, 2018 is 30/50/20, I will rebalance my portfolio on March 13, 2019 to 30/50/20 again. The allocation between September 13, 2018 and March 13, 2019 will fluctuate according to price changes in the market.
Portfolio return = sum of weighted average of the return of each asset
Cumulative portfolio return = cumulative sum of portfolio return
How do I write a code in Python 3 that takes into account the semi annual rebalancing, as well as calculating the weight allocation of each asset, portfolio return and cumulative return from September 13, 2018 to September 13, 2022? Thanks!