I've attached an algorithm that uses coarse and fine filters to select a universe and rebalances every 20 days. Everything is working as expected, however, I'm seeing “The security does not have an accurate price” even though I'm only placing orders if `data.ContainsKey(symbol)` is True. I've searched through the forum and that seems like it should be the solution but it's not working.
This works fine with daily data but I'd like to use minute data as recommended here. If I'm rebalancing every 20 days, does minute data even matter? Will I get more accurate results with minute data?
I've noticed not all of the changes in `onSecuritiesChanged` are making it to `onData` within the same minute, hence my use of buy and sell lists. Is there a better way to place orders when using minute data? Thanks in advance for any help!
Fred Painchaud
Hi Justin,
Done some modifs in your code (attached) but it did not solve the issue. Since in 2010 there is only 1 asset on 1 day (most likely the day of a rebalance) that triggers the inaccurate price, it looks to me like some error in the data for that security.
Done some speed improvements in the code but one change is crucial as before Python 3.7, dictionaries cannot be sorted (deterministically - in other words, the order of insertions in dictionaries are not guaranteed to be preserved). Thus, converting the sorted tuples list into a dict (by dict(sorted(ranked.items(), key=lambda x: x[1], reverse=True))) will work most of the time (preserve order. thus sort) but CAN change sometimes………………………….. one reason one can wonder why the exact same algo sometimes can return different results.
Fred
Justin Busa
Thanks for the info on dictionary sorting! That's super helpful.
As for the error, I'm going to see about reworking this using the algorithm framework and do some more digging. Is it common for data errors to come up now and then?
Fred Painchaud
Re sorting dicts, once Python gets updated in LEAN, it won't be an issue any longer - from 3.7+, dictionaries do guarantee preservation of insertion order and iteration order.
Data errors do happen, no data in trading is perfect. Check out: https://www.quantconnect.com/forum/discussions/1/dataissues. If you come to the same conclusion than myself after going framework style, you can report a potential error at https://www.quantconnect.com/data/issues/open. If using the framework makes the error disappear (for the same assets (some selection criteria) and same period of time), please report back as I would find that very interesting to know.
Fred
Varad Kabade
Hi Justin,
The above error occurs because the security has not received a data bar. Data does not necessarily all arrive simultaneously, so your algorithm should confirm the data is ready before using it. To check if there is trade data, we recommend using:
Note that data.ContainsKey(symbol) checks for whether the current slice object has data for the given symbol, which can be of trade and non-trade type(splits, dividends).
Best,
Varad Kabade
Justin Busa
Thanks, Varad. Now that I'm seeing it, that makes total sense. Appreciate the help!
Justin Busa
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!