Very often (cca 20% of time) I am getting following error in my backtesting:
Backtest Handled Error: Order Error: id: 11, Insufficient buying power to complete order (Value:24955.9785), Reason: Id: 11, Initial Margin: 12478.9892365, Free Margin: 154.669432942
Derek MelchinĀ proposed the lower percentage in self.SetHoldings function and using cash buffers, that is usingĀ self.Settings.FreePortfolioValuePercentage function.
I implemented both things using:
self.Settings.FreePortfolioValuePercentage = 0.5
self.SetHoldings("SPY", .5)
but it didn't help. I am still getting trhe same error (not as often as before, but still).
Attached you can find the whole code of the backtest. It's relatively long, but most important are the lines of code above.
I can try with even lower percentage values and higher cash bufferrs, but that changes my strategy a lot since I invest only small fraction of available cash when I want to invest almost everything (say 90%).
Ray Trader
Only 2 weeks old in Quantconnect so take it with a pinch of salt., as I can see you are trying to execute based on minute resolution.
So you can at a time only place 2 orders (but I read there are some buffer kept so not sure if the second trade will be executed )
I am not sure when the prediction is 1 and -1 but maybe you can
- check first that there are no active trades going on from Portfolio and setHoldings only if there are none
- Or you can only use 10% (0.1) of the equity to place orders, so that at least you can take 9-10 orders
May be someone else may have better answers.Jared Broad
HiĀ Mislav; out of respect for the community please do not double post. Price and portfolio buying power discipline is an important part of designing an algorithm.Ā
@Ray "So you can at a time only place 2 orders" - This is not true. You can place as many orders as the brokerage will allow for your account type and buying power. For a margin account this is generally up to 2x buying power.
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.
Dee Znut
I Have come across at least 50 different threads where people are complaining about QC not being able to handle the buying power of a simple vertical spread and keeps crashing the backtest with āinsufficient buying powerā and āmargin callsā.Ā
I have seen many posts from QC team members including Alex and Jared back in 2020 stating that they are working hard on making sure options and spreads can be easily handled. However, in 2024 I have the same issue and thers is nobody to offer any help
Mislav Sagovac
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!