Good morning!
I'm facing a strange behaviour (described below) after deploying my QC code live. So, I written a simplified code to get some observation logs. Is anyone facing this as well?
Problem observed: OnData not being triggered hourly during extended hours but able to trigger minutely
Intention: Load active positions (CL20Z23) and perform run algo code which is based on hourly period including extended market hours
Live data source: QuantConnect
Code:
from AlgorithmImports import *
class EnergeticSkyBluePigeon(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2023, 10, 5)
self.SetCash(100000)
self.UniverseSettings.ExtendedMarketHours = True
self.UniverseSettings.Resolution = Resolution.Hour
def OnData(self, data: Slice):
self.Debug(f"{self.Time}: OnData triggered")
Observation (for hour resolution): OnData is not triggered after an hour while the logs doesn't show any irregularity during the initialization
2023-10-09 08:47:35 : BrokerageSetupHandler.Setup(): Open order detected. Creating order tickets for open order CL20Z23 with quantity 1. ...
2023-10-09 08:47:39 : Will use UniverseSettings for automatically added securities for open orders and holdings. UniverseSettings: Resolution = Hour; Leverage = 0; FillForward = True; ExtendedHours = True
2023-10-09 10:11:09 : Algorithm Stopped --> manually stopped the live trade
Observation (for minute resolution): Amended the code to "self.UniverseSettings.Resolution = Resolution.Minue". OnData is triggered after switching to minute.
2023-10-09 10:15:20 : Will use UniverseSettings for automatically added securities for open orders and holdings. UniverseSettings: Resolution = Minute; Leverage = 0; FillForward = True; ExtendedHours = True
2023-10-09 10:16:00 : 2023-10-09 06:16:00.227356: OnData triggered
2023-10-09 10:17:01 : 2023-10-09 06:17:00.102752: OnData triggered
Mia Alissi
Based on the information provided in the extracts, it seems that the issue you're facing might be related to the fact that extended market hours data is only available if you create the subscription with minute, second, or tick resolution. If you create the subscription with daily or hourly resolution, the bars only reflect the regular trading hours. This is mentioned in the Key Concepts section of the QuantConnect documentation.
Here is the relevant extract:
This could explain why your
OnData
method is not being triggered hourly during extended hours, but is able to trigger minutely. When you set theUniverseSettings.Resolution
toResolution.Hour
, the data subscription might not include the extended market hours, henceOnData
is not triggered. However, when you set it toResolution.Minute
, the data subscription includes the extended market hours, andOnData
is triggered as expected.You might want to consider using minute resolution and then consolidating the data into hourly bars if your algorithm is based on hourly data. Here is an example of how to do this in Python:
In this example,
OnHourlyData
is a method that will be called with the consolidated hourly data.Please note that this is just a possible explanation based on the information provided in the extracts. For a more accurate diagnosis of the issue, you might want to reach out to the QuantConnect support or community.
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.
Swiftmox
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!