Would the following code successfully rebalance portfolio each hour randomly according to the random portfolio weights that are sampled (and then normalized)? I think that setHoldings doesn't work incrementally hence causes errors if not being liquidated before each rebalancing. However, that would mean extreme commission expenditure if the rebalancing is done somehow in high frequency. Please, enlighten me on the right way of doing this incrementally. I have also tried to do so manually by using CalculateOrderQuantity and then placing market orders. However, that also failed the same way the setHoldings did. Although the shared code supposed to put all portfolio into these currencies. The report says that +90% of the portfolio were in cash. Also, I never used more than 1.0 leverage but the report states that the leverage varies up to 150. I would welcome if anybody can help me.
https://www.quantconnect.com/terminal/processReports/get/pdf/c8cb4b9a8cfa0a84e1599cd5be549fe7
https://www.quantconnect.com/reports/c8cb4b9a8cfa0a84e1599cd5be549fe7
Kamer Ali Yüksel
Flame
The errors are likely due to using too much margin being used. To fix this you will want to make sure that trades that will free up margin are placed before those that will reduce margin (e.g. place sales before purchases). I use something like this in my algos, but if your algo also goes short you may want to compare the absolute value of the current_weight to absolute value of the new weight (e.g. if abs(allocate[s]) < abs(current_weight))
for s in self.securities:
current_weight = float((self.Portfolio[s].Quantity * self.Portfolio[s].Price) / self.Portfolio.TotalPortfolioValue)
if (allocate[s]) < current_weight:
self.SetHoldings(s, allocate[s])
for s in self.securities:
current_weight = float((self.Portfolio[s].Quantity * self.Portfolio[s].Price) / self.Portfolio.TotalPortfolioValue)
if (allocate[s]) > current_weight:
self.SetHoldings(s, allocate[s])
Kamer Ali Yüksel
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!