Back

Question on SetHoldings / Insufficient Buying Power

I am trying set 1% of my portfolio to each of 100 stocks.
Everyday I liquidate the whole portfolio and then set 1% to each stock.
If I understand correctly, looping through SetHoldings 100x and then setting 1% of my portfolio to each stock, I should never have unsufficient funds, but I am getting this error.

Example:
Liquidate();
for (i = 0; i< 100; i++)
{
SetHoldings(stock[i], .01);
}
Update Backtest








I forgot to mention i set leverage as 1m.


Im starting to wonder if that is the issue. I guess if I am liquidating everything, then buying back right away, it would take time to settle and therefore I would need to buy on margin for a few days?
0

Its probably a small margin of error Rob which would depend on the fill price of your assets and trade fees associated with the transaction. I'm guessing 99 of the requests go through fine, and the final one is failing? Can you share the algorithm?

If you set leverage to more than 1 it will give you a small buffer to work with, or alternatively you could use 0.0095 per stock to leave yourself a 5% cash buffer for the trading costs.
0

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.


I was trying it out on Lean first, so I don't currently have it easily shareable, but I was basically taking the S&P 500 constituents and applying weightings to them based off of price performance where I keep only the top 100 performers, 1% each. 1x a month i was basically liquidating and rebalancing. Just tried it on the web client, but hit the 10k max orders for non-subscribers. Might tempt me to subscribe soon, but just playing around for now.
0

Instead of liquidating everything, try only liquidating those symbols which aren't in the top 100 anymore. The SetHoldings function takes into account your existing holdings. This could save you thousands in transaction fees :)
1

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.


That's a very useful tip, thanks!
0

Update Backtest





0

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.


Loading...

This discussion is closed