You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A manual call to SubscriptionManager.RemoveConsolidator(symbol, consolidator) removes registered consolidator when called from Python algorithm
Actual Behavior
When the consolidator is resolved to an IdentityDataConsolidator (might also be in other cases) SubscriptionManager.RemoveConsolidator doesn't remove the consolidator.
Potential Solution
The source of the bug might be because RegisterIndicator will try to convert the consolidator PyObject to an IDataConsolidator and fails, wrapping the object in a DataConsolidatorPythonWrapper. So after this, the actual stored consolidator referenced is wrapped and SubscriptionManager.RemoveConsolidator won't find it.
We might need to detect the wrapper and remove by its underlying python model.
class TestAlgorithm(QCAlgorithm):
def initialize(self):
self.set_start_date(2013,10,7)
self.set_end_date(2013,10,11)
self.spy = self.add_equity("SPY").symbol
self.consolidator = self.resolve_consolidator(self.spy, Resolution.MINUTE)
name = self.create_indicator_name(self.spy, "close", Resolution.MINUTE)
identity = Identity(name)
self.indicator = self.register_indicator(self.spy, identity, self.consolidator)
self.schedule.on(self.date_rules.today, self.time_rules.before_market_close(self.spy), self.remove_consolidator)
def remove_consolidator(self):
self.subscription_manager.remove_consolidator(self.spy, self.consolidator)
consolidator_count = sum(s.consolidators.count for s in self.subscription_manager.subscriptions)
if consolidator_count >0:
raise Exception(f"The number of consolidator should be zero. Actual: {consolidator_count}")
NOTE: This fix is required in order to be able to use PearsonCorrelationPairsTradingAlphaModel in PearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm and any other algorithm. As of now, that algorithm is not importing the actual python model (with from Alphas.PearsonCorrelationPairsTradingAlphaModel import PearsonCorrelationPairsTradingAlphaModel) so it's using the C# one.
The Python PearsonCorrelationPairsTradingAlphaModel does a manual consolidator removal that has this bug and the algorithm final assertion for the consolidators count fails when using the python model.
System Information
Windows 11
QC Cloud
Checklist
I have completely filled out this template
I have confirmed that this issue exists on the current master branch
I have confirmed that this is not a duplicate issue by searching issues
I have provided detailed steps to reproduce the issue
The text was updated successfully, but these errors were encountered:
Expected Behavior
A manual call to
SubscriptionManager.RemoveConsolidator(symbol, consolidator)
removes registered consolidator when called from Python algorithmActual Behavior
When the consolidator is resolved to an
IdentityDataConsolidator
(might also be in other cases)SubscriptionManager.RemoveConsolidator
doesn't remove the consolidator.Potential Solution
The source of the bug might be because
RegisterIndicator
will try to convert the consolidatorPyObject
to anIDataConsolidator
and fails, wrapping the object in aDataConsolidatorPythonWrapper
. So after this, the actual stored consolidator referenced is wrapped andSubscriptionManager.RemoveConsolidator
won't find it.We might need to detect the wrapper and remove by its underlying python model.
Reproducing the Problem
Attached backtest: https://www.quantconnect.com/terminal/clone/-/ba9a391ee0a14a56cdc0729838675305/clone-of%3A-calculating-red-seahorse
NOTE: This fix is required in order to be able to use
PearsonCorrelationPairsTradingAlphaModel
inPearsonCorrelationPairsTradingAlphaModelFrameworkAlgorithm
and any other algorithm. As of now, that algorithm is not importing the actual python model (withfrom Alphas.PearsonCorrelationPairsTradingAlphaModel import PearsonCorrelationPairsTradingAlphaModel
) so it's using the C# one.The Python
PearsonCorrelationPairsTradingAlphaModel
does a manual consolidator removal that has this bug and the algorithm final assertion for the consolidators count fails when using the python model.System Information
Windows 11
QC Cloud
Checklist
master
branchThe text was updated successfully, but these errors were encountered: