Hello-
I'm trying to add a 30 minute consolidator with rolling window to a stable code that already has a 1 day consolidator. When I added the 30 min consolidator I received this error.
Is the structure of the code correct? Not sure where the error is..
Runtime Error: For Symbol ABCL XK9GI7KK0Y1X can not consolidate bars of period: 00:30:00, using data of the same or higher period: 1.00:00:00 in PeriodCountConsolidatorBase.cs:line 159
class SymbolData:
def __init__(self, algorithm, symbol):
self.algorithm = algorithm
self.symbol = symbol
self.boundary = RollingWindow[TradeBar](20)
self.consolidator_two = TradeBarConsolidator(timedelta(minutes=30))
self.consolidator_two.DataConsolidated += self.OnDataConsolidated_two
algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator_two)
self.Bars = RollingWindow[TradeBar](12) #defines rolling window size, TradeBar defines bar type
self.consolidator = TradeBarConsolidator(timedelta(days=1))
self.consolidator.DataConsolidated += self.OnDataConsolidated
algorithm.SubscriptionManager.AddConsolidator(symbol, self.consolidator)
def OnDataConsolidated_two(self, sender, bar):
self.boundary.Add(bar)
def OnDataConsolidated(self, sender, bar):
self.Bars.Add(bar)
@property
def IsReady_two(self):
return self.boundary.IsReady
@property
def IsReady(self):
return self.Bars.IsReady
Mia Alissi
The error message you're seeing is due to the fact that you're trying to consolidate data into a smaller time frame (30 minutes) than the data you're receiving (1 day). In other words, you're trying to create a 30-minute bar from daily data, which is not possible.
In your code, you're creating two consolidators: one for 30 minutes and one for 1 day. However, the data you're receiving is likely daily data, which is why you're seeing this error.
If you want to create a 30-minute consolidator, you need to ensure that you're subscribing to data with a resolution of 30 minutes or less. For example, if you're subscribing to minute data, you can then consolidate this into 30-minute bars.
Here's an example of how you might subscribe to minute data and create a 30-minute consolidator:
In your main algorithm, when you add the security, make sure to specify the resolution as minute:
This will ensure that you're receiving minute data, which can then be consolidated into 30-minute bars.
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.
Justin E
Hi Mia Alissi-
I'm using 1 minute data as inputs to the algo. Here is the initialize function. I'm still confused as to why it thinks I'm passing daily bars into the consolidator when my universe setting is minute.
Mia Alissi
The error message you're seeing is due to the fact that you're trying to consolidate data into a smaller time frame than the data's resolution. In your
Initialize
method, you're adding "SPY" with a daily resolution:Then, in your
SymbolData
class, you're trying to create a 30-minute consolidator:This is not possible because you can't create 30-minute bars from daily data. You need to ensure that the resolution of your data is the same as or smaller than the period of your consolidator.
If you want to use a 30-minute consolidator, you should add "SPY" with a minute or second resolution. For example:
Also, make sure to remove the consolidator when the security leaves the universe. If you have a dynamic universe and don't remove consolidators, they compound internally, causing your algorithm to slow down and eventually die once it runs out of RAM. You can remove the consolidator using the
RemoveConsolidator
method:For more information, you can refer to the QuantConnect documentation on consolidators.
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.
Justin E
Hi Mia-
I did both of those things with no improvement. Here is the complete code to backtest and debug, if you would like.
Could it be due to the warmup period being in days?
Justin E
Solved and will close discussion.
Solution: I needed to change the warmup resolution from Daily to Minute as it was trying to consolidate the daily warmup data into minutes. Changed to:
Mia Alissi
Based on the information provided, it seems like 'Justin' was trying to consolidate daily data into 30-minute bars, which was causing an error. The error message suggests that the data cannot be consolidated into a smaller time frame than the original data.
In this case, 'Justin' solved the issue by changing the warmup resolution from Daily to Minute. This allowed the algorithm to have minute-level data, which can be consolidated into 30-minute bars. Here is the code 'Justin' used to change the warmup resolution:
This code sets the warmup period to 200 minutes, which provides enough minute-level data for the 30-minute consolidator.
Remember, when using consolidators, the resolution of the data you're consolidating should be the same or smaller than the resolution of the consolidator. For example, you can consolidate minute data into 30-minute bars, but you can't consolidate daily data into 30-minute bars.
Also, when adding an event handler to the consolidator, remember to pass the name of your method to the event system without parenthesis. If you use parenthesis, the method executes and the result is passed as the event handler instead of the method itself. For example, it should be
self.consolidation_handler
, notself.consolidation_handler()
.Here is an example of how to add an event handler to a consolidator:
In this line,
self.consolidation_handler
is the method that will handle the consolidated data.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.
Justin E
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!