Lean
Lean copied to clipboard
Security Cache Reset
Expected Behavior
- The securities cache is reset only when it's no longer used
Actual Behavior
If a universe removes a configuration from the data stack which isn't being used by any other universe, the data manager will return true and we will clear the securities cache and set it as non tradable. This will cause issues if the security is being used by another universe.
if (_dataManager.RemoveSubscription(subscription.Configuration, universe))
{
_internalSubscriptionManager.RemovedSubscriptionRequest(subscription);
member.IsTradable = false;
// We need to mark this security as untradeable while it has no data subscription
// it is expected that this function is called while in sync with the algo thread,
// so we can make direct edits to the security here.
// We only clear the cache once the subscription is removed from the data stack
member.Cache.Reset();
}
- Ref https://github.com/QuantConnect/Lean/blob/master/Engine/DataFeeds/UniverseSelection.cs#L501
Potential Solution
- Check ActiveSecurities to determine if the security is not a member of another universe
- This is sad though because it's pooling. Ideally we should get an event when the security has been removed from all universes and only then we could clear it's cache and set it to non tradable
Reproducing the Problem
- This issue was reproduced
public override void Initialize()
{
var dc = AddFuture(Futures.Dairy.ClassIIIMilk, Resolution.Daily, Market.CME);
dc.SetFilter(1, 120);
// FOPs will use Universe.Settings default to Minute resolution
AddFutureOption(dc.Symbol, universe => universe.Strikes(-2, 2));
}
System Information
N/A
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue