I have a weights vector representing the portfolio target hourly. The weights vector also includes the ratio of the cash. The absolute sum of the weight vector is the leverage. I am currently using setHoldings method for rebalancing according to that weight vector. However, I couldn't figure out how the cash amount can be considered for rebalancing.


weights = np.array([0.21934296190738678, 0.07689524441957474, 0.02108154632151127, -0.01785222627222538, -0.04997013136744499, -0.08549412339925766, 0.09435564279556274, 0.10972453653812408, -0.08650565147399902, -0.08091041445732117, 0.14116396009922028])

for i, asset in enumerate(assets): self.SetHoldings(asset, weights[i])

Here, if I just use the setHoldings function on the assets without specifying the cash amount. It wouldn't now which leverage to employ for the remaining positions as they wouldn't sum up to the leverage amount. I also did not understand what the boolean liquidateExistingHoldings parameter is for since that if the setHoldings called with a smaller weight wouldn't the possition difference already be liquidated, without setting the liquidateExistingHoldings? Why would someone want to liquidate the whole position beforehand as that would result in unnecessary comission?

Please also advise me on how I can perform this rebalancing hourly rather than each time the onData method is called?