Hi all,
I am trying to select some securities over the universe selection. After that, I will send order under the OnData function. I hit errors and here is the message:
This asset symbol (KAL 0) was not found in your security list. Please add this security or check it exists before using it with 'Securities.ContainsKey("KAL 0")' in SecurityManager.cs:line 254
I am not able to share the backtest, so here is the main.py
# region imports
from AlgorithmImports import *
# endregion
class QCSymbolStudy(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2023, 2, 17) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddUniverse(self.CoarseSelect, self.FineSelect)
self.UniverseSettings.Resolution = Resolution.Daily
self.is_make_order = True
def OnData(self, data: Slice):
for d in data.Keys:
self.Debug(f"{self.UtcTime} OnData: {d}")
if self.is_make_order:
self.is_make_order = False
self.MarketOrder("KAL", 10)
def CoarseSelect(self, coarse):
return [c.Symbol for c in coarse]
def FineSelect(self, fine):
selected_list = list()
for f in fine:
if "KAL" in f.Symbol.Value:
selected_list.append(f.Symbol)
self.Debug(f"length: {len(selected_list)}")
return selected_list
I printed the keys in the function and I saw my target name:
2023-02-17 05:00:00+00:00 OnData: KAL XZPS318X97QD
2023-02-17 05:00:00+00:00 OnData: KALA WMCI69Z95F1H
2023-02-17 05:00:00+00:00 OnData: KALU TK3F5EFUQ739
2023-02-17 05:00:00+00:00 OnData: CBYL VZKASE9NEYCL
It seems that there is already data received but I still cannot send out order.
I tried to use
self.AddEquity("KAL", Resoltuion.Daily)
This can fix the issue, but the problem is that I need to use universe selection to do a dynamic selection.
I would like to ask how to fix this?
Thanks
Sulfred
Creating the symbol first and follow by making order resolved the issue.
Thanks all
Sulfred
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!