Currently we can get the AdjustedPrice in the CoarseSelectionFunction. I am wondering if we can also get the previous day's open/high/low prices as well? I don't want to call the History function for the entire universe on the daily basis which will be time consuming. Thanks!
Vladimir
T C
How you are going to use the previous day's open/high/low prices?
Can you describe your strategy?
T C
Hi Vladimir,
The idea is that I want to calculate some indicators based on daily open/high/low prices and use those to filter a large universe down to a much smaller universe. Thanks!
Vladimir
T C
Here is the sample algorithm that create indicator using previous day's open-high-low prices to filter universe down to a much smaller universe. (5 years backtest completed in 12.64 sec).
If you are satisfied with my answer, please accept it and don't forget to like it.
T C
Thanks Vladimir! I don't want to use self.History function on the daily basis for the entire universe because it's going to be very slow.
Vladimir
SymbolData is another option.
T C
Thanks Vladimir! The problem is how do I use the SymbolData in CoarseSelectionFunction since the securities haven't been registered yet. Remember my goal is to use OHLC to filter down the coarse universe to a much smaller set.
Varad Kabade
Hi TC,
We recommend going through the following thread for example in using SymbolData/SelectionData class for universe selection(when the security is not in the universe)
Please also refer to this Bootcamp lesson.
Best,
Varad Kabade
Arthur Asenheimer
Hi Varad Kabade ,
the linked thread doesn't answer the question.
TC would like to get the previous day's open, high and low. The linked thread provides a solution if we only need the (adjusted) close which is something he was already aware of.
To me it seems there is no solution other than calling the History function for the entire universe on a daily basis which is inefficient and time consuming and also something the OP would like to avoid as he stated in his original post.
Is there any chance the fields High, Low and Open will be added as properties to CoarseFundamental?
T C
Thanks Arthur and I completely agree! Besides High, Low and Open, it would be better if we can also add MarketCap to CoarseFundamental so that we don't have to go through the FineSelectionFunction. I know we probably could use DollarVolume, but that's really not good enough.
Fred Painchaud
Hi,
Use three rolling windows of 1 item to keep the last day open, high and low price. Update your 3 windows at the end of the day.
Fred
T C
Hi Fred,
My goal is to use the historical Open or High or Low to filter the coarse universe (4000+ symbols) down to a very small set (e.g. 100 symbols). I can't achieve that goal by using the rolling windows to only track the last day OHL of the final filtered universe.
Fred Painchaud
Hey TC,
I was answering your original question: I am wondering if we can also get the previous day's open/high/low prices as well?
If you want the previous day's OHL without using History for all equities, simply track those 3 values for all equities. I mentioned rolling windows because most people know/understand them but since you only track the latest value of each 3 values, you only need 3 variables, not 3 rolling windows.
Attached is a dumb and simple example of what I meant.
Fred
T C
Thanks Fred! But I don't think the code could track all of the historical OHL for the entire universe except for the first day.
Here is my understanding: for the first day, the OnData could save down the OHL for the entire coarse universe. However after that, each day the OnData is only able to save the OHL for the filtered universe and the rest symbols would have stale OHL afterwards.
Fred Painchaud
TC,
Yeah, well, change the code to the attached then.
Then “if len(self.OHL) == 0:” is only there to avoid working on filtered on empty OHL.
Fred
T C
Hi Fred,
Maybe I didn't put it clear. The reason I want to get OHL in CoarseSelection function to filter it to a smaller set is to make the entire algorithm run faster. Without considering performance issue, we can always find out the OHL in OnData or using Consolidator by going through the bar data. However, if the universe is at smaller resolution, e.g. Minute, Second, the algorithm is going to be very slow. Thanks!
TC
Fred Painchaud
Hi TC,
Sorry that I don't understand. But you know that even though the Universe is “at Second or Minute resolution”, Universe Selection will still only happen once per day, right? End then, do you want the previous day's OHL, or the previous second's or minute's OHL???
You said Daily so I did Daily but the above code can run at the exact (or almost) same speed if the Universe is at Second or Minute and you want the previous day's OHL… You just need to use OnEndOfDay (as written in my original post) instead of OnData…
Do you need that code?
Fred
T C
Hi Fred,
Yes, I know universe selection only happens once per day and I only need the historical daily OHL. However to place trades, I need minute or second level OnDarta. That's why my universe selection needs to set as Minute or Second. Hope that clarifies. Thanks!
TC
Fred Painchaud
Hi again,
I was replying when you last posted the above.
Yeah, I got that.
Sorry I'm getting too used to working in my stuff so I forgot about a thing or two, such as the fact that at Second or Minute, the algo is going to iterate on each asset for each second or minute (calling OnData)… which yes, 😊, will take forever.
I've been working differently for a few months so that escaped me for a moment.
Fred
T C
That's all right Fred. Thanks again for the help!
T C
Can anyone from QuantConnect comment on this? To summarize, I want adjusted OHL prices in the CoarseSelectionFunction. If we use OnData to track OHL, that's very inefficient and probably impossible for large universe. Thanks!
T C
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!