LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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!
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.
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.
How you are going to use the previous day's open/high/low prices?
Can you describe your strategy?
1
T C
2k Pro
,
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!
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.
0
T C
2k Pro
,
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.
0
Vladimir
94.7k Pro
,
SymbolData is another option.
0
T C
2k Pro
,
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.
0
Varad Kabade
31.1k Pro
,
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)
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?
1
T C
2k Pro
,
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.
0
Fred Painchaud
12.3k Pro
,
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
0
T C
2k Pro
,
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.
0
Fred Painchaud
12.3k Pro
,
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
0
T C
2k Pro
,
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.
0
Fred Painchaud
12.3k Pro
,
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
0
T C
2k Pro
,
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
0
Fred Painchaud
12.3k Pro
,
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
0
T C
2k Pro
,
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
0
Fred Painchaud
12.3k Pro
,
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
0
T C
2k Pro
,
That's all right Fred. Thanks again for the help!
0
T C
2k Pro
,
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!
0
Louis Szeto
STAFF Pro
,
Hi T C
It is not possible to directly get OHL data from the CoarseFundamental object yet. A workaround would be creating a history call.
def MyCoarseFilterFunction(self, coarse):
# We suggest some initial filtering first to avoid performance drag
selected = []
for x in coarse:
symbol = x.Symbol
history = self.History(symbol, 1, Resolution.Daily)
if history.empty or not symbol: continue
open_ = float(history.open.values)
low = float(history.low.values)
high = float(history.high.values)
if high > low:
selected.append(symbol)
return selected
Note that we suggest doing some initial filtering before the logic to avoid performance dragging.
Best Louis
0
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.
T C
2k Pro
,
Hi Louis,
As I mentioned in my original post, I don't want to call history function because it's not going to work for large universe no matter how I filter the universe before the call. I am wondering if you guys could add adjusted OHL to the CoarseFundamental object similar to what you have done for the adjusted close. Thanks!
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.
Loading...
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!