Closed swisstackle closed 4 months ago
Hi @swisstackle,
When the algorithm adds a security, it creates a data subscription that will create the time slices and update the security cache so that the price differs from zero. Your algorithm might select very illiquid stocks so that ContainsKey
returns false
.
You can use GetLastKnowPrices to feed/warm up the security. See Set Security Initializer.
I suggest joining our Discord channel or contacting support for clarification.
Expected Behavior
I expect to be able to use SetHoldings and that SetHoldings can retrieve the current price of the equity asset.
Actual Behavior
The
SetHoldings
function needsSecurity.Price
to calculate the order quantity from the percentage given. TheSecurity.Price
attribute is populated by theUpdate
function which uses the data object.In my algorithm
data.ContainsKey(symbol)
returns false for many symbols, which means that the price won't be available toSetHoldings
which causes the following error:This does not just happen with NUE, this happens with other symbols too.
A quick check in the research environment shows me that there is actually data available in the dataset during the timeframe:
Potential Solution
I do not have a potential solution right now. I am a C# developer but I would have to dig deeper into the codebase. If this turns out to be a bug and not a mistake on my side, I'm willing to help to speed up the process.
Reproducing the Problem
This is the code for my algorithm. The algorithm utilizes a dynamic universe, which means I can't just use
SetWarmup
in the initialize method.The algorithm is initialized with a dynamic universe selection as such:
And the error happens in the
OnData
method in this for loop:System Information
OS is Windows 10 Professional, but this error happens in the cloud. I do not have a local setup of LEAN.
Checklist
master
branch