Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Continuous Future Mapped with Null Value On Start of Algorithm

Open AlexCatarino opened this issue 3 years ago • 2 comments

Expected Behavior

The Mapped should not be Null

Actual Behavior

Mapped is always null without warm up.

Potential Solution

N/A.

Reproducing the Problem

class MappedNoneAlgorithm(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 6, 30)  
        
        self.liquidContract = self.AddFuture(Futures.Metals.Silver, Resolution.Second, \
                        dataNormalizationMode = DataNormalizationMode.BackwardsRatio, \
                        dataMappingMode = DataMappingMode.OpenInterestAnnual, \
                        contractDepthOffset = 0)

        self.liquidContractC = self.AddFuture(Futures.Grains.Corn, Resolution.Minute, \
                        dataNormalizationMode = DataNormalizationMode.BackwardsRatio, \
                        dataMappingMode = DataMappingMode.OpenInterestAnnual, \
                        contractDepthOffset = 0)

    def OnData(self, data):
        # Market opens at midnight for Silver and 1am for Corn
        self._currentContractC = self.Securities[self.liquidContractC.Mapped]

throws exception

Runtime Error: Value cannot be null. (Parameter 'key') in SecurityManager.cs:line 252: StackTrace: Value cannot be null. (Parameter 'key') in SecurityManager.cs:line 252

because Mapped if null.

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar Jul 11 '22 21:07 AlexCatarino

Currently universe selection for the continuous contract universe is happening on each tradable date in exchange time zone, which might be different depending on the asset, this issue. Believe the missing piece in Lean might be always triggering universe selection right away for the added universes, would avoid any time zone issues or depending on warmup

Martin-Molinero avatar Jul 12 '22 20:07 Martin-Molinero

It feels like a bug - the Mapped is null on launch. SetWarmup worked around it to trigger selection a day early.

jaredbroad avatar Sep 27 '23 18:09 jaredbroad