260 | 12:20:33:
Backtest Handled Error: Order Error: id: 53, Insufficient buying power to complete order (Value:1112095.7532), Reason: Id: 53, Initial Margin: 1011014.9642465454545454545455, Free Margin: 103632.6538046989706545454545
261 | 12:20:33:
Your algorithm messaging has been rate limited to prevent browser flooding
Rahul Chowdhury
Hey Troy,
Tiingo news data can be emitted when the market is closed. Your algorithm is taking the insights from these overnight emissions and creating market on open orders. If the gap between the market close price and market open price is large, you may get an insufficient margin error.
One way to work around this error is to not emit any insights during market close.
You can accomplish this by returning at the beginning of AlphaModel.Update if the market is closed.
if not algorithm.IsMarketOpen("SPY"):
return insights
You can also consolidate all insights generated overnight in a class variable and then emit them at market open. However keep in mind that QC's PortfolioConstructionModels only take into account the latest insight when creating portfolio targets.
If you want to take into consideration all of the overnight news data when emitting an insight at market open. You could store all the overnight news data, calculate a sentiment, and then emit one insight at market open.
I modified your algorithm to store all overnight insights and emit them at market open, which effectively trades on the latest overnight insight for each symbol.
Best
Rahul
Troy B
Thanks Rahul! I appreciate the detailed explanation and information. This is exactly what I was looking for.
Thanks again,
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!