Can someone advise regarding how to address the 'Insufficient Buying Power' errors I'm getting when running the code shown below? I've searched the documentation and Community postings but didn't see anything that would directly help in this case.
Thanks,
Troy
Alexandre Catarino
Hi Troy B ,
The algorithm is using daily data. Consequently, the target quantities calculated by EqualWeightingPortfolioConstructionModel (and MaximumDrawdownPercentPerSecurity) models take into account the previous day closing price. Since the order, converted into MarketOnOpen order, will be filled with the current day's open price, a price gap can cause the Insufficient Buying Power error.
To fix this we recommend using minute resolution data. See also Trading and Orders: Common Order Errors.
Troy B
Hi Alexandre,
Thank you for the response. I've revised the algorithm to use minute resolution data, but am still getting the errors below. The backtest is attached. Are there other settings that need to be changed?
Troy
482 | 13:47:26:
Backtest Handled Error: Order Error: id: 97, Insufficient buying power to complete order (Value:988655.22), Reason: Id: 97, Initial Margin: 898793.6177272727272727272727, Free Margin: 92341.4721439090909090909091
483 | 13:47:36:
Backtest Handled Error: Order Error: id: 1425, Insufficient buying power to complete order (Value:860577.51), Reason: Id: 1425, Initial Margin: 782357.03590909090909090909092, Free Margin: 80649.69459076363636363636363
484 | 13:47:42:
Backtest Handled Error: Order Error: id: 2018, Insufficient buying power to complete order (Value:797302.99), Reason: Id: 2018, Initial Margin: 724833.58500000000000000000001, Free Margin: 74936.62417124545454545454545
Alexandre Catarino
Hi Troy B ,
The Alpha Model is emitting insights when the market is closed (4 pm). Consequently, market orders are converted into market on open orders, and there is insufficient buying power because the open price of the next dar moved against the insight direction.
One solution to this issue is to emit an empty array of insights when the market is closed:
# In Update Method if not all([algorithm.IsMarketOpen(x['symbol']) for x in self.mom]): return []
Troy B
Thanks Alexandre! That took care of it.
Troy
Troy B
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!