I want to build logic avoiding the buying the security whose earning is due to 2 days or less, How do I get earning calendar for the symbol in QuantConnect. I want to build below dictionary for each symbol in my universe
self.calendar: Dict[Symbol, List[datetime.date]] = {}
def block_today_or_tomorrow(self, symbol: Symbol, time: datetime) -> bool:
if not self.enabled: return False
dates = self.calendar.get(symbol) or []
d0 = time.date()
window = {d0 + timedelta(days=i) for i in range(self.cfg.block_earnings_window_days + 1)}
return any(d in window for d in dates) if self.earnings.block_today_or_tomorrow(state.symbol, self.algo.Time):
return False, "earnings_window"
Mia Alissi
Here’s how you can construct the earnings calendar for each symbol in your universe and block trading around earnings in QuantConnect, as requested:
Key takeaways:
block_today_or_tomorrow(symbol, time)checks if a symbol has an earnings date within your blocking window—today, tomorrow or the day after.Let me know if you'd like to see further integration or adaptations!
Sources: Upcoming Earnings - QuantConnect.com, docs writing algorithms datasets eod historical data upcoming dividends, docs writing algorithms datasets eod historical data upcoming ipos, Dropbox Base Data Universe Selection Algorithm, Custom Data Universe Algorithm
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.
Dharmesh Khalasi
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!