Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
Discussing documentation for algorithm universes in QuantConnect.
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Documentation discussion algorithm-reference/universes
QuantConnect Robot | September 2018
QuantConnectâ„¢ 2025. All Rights Reserved
Ofir Shmulevich
Question about the resolution :
self.UniverseSettings.Resolution = Resolution.Daily // What resolution should added assets use
suppose I want to perform a universe selection every 7days or month ,
how could it be implemented ?consolidating data and then use it as resolution?
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.
Link Liang
Hi Ofir,
There are many options to achieve your goal.1. We could use Scheduled Universe Selection. Here is an example of performing an universe selection every Monday:
# in self.Initialize():
self.AddUniverseSelection(ScheduledUniverseSelectionModel(
self.DateRules.Every(DayOfWeek.Monday),
self.TimeRules.Every(timedelta(hours = 12)),
self.SelectSymbols # selection function in algorithm.
))
def SelectSymbols(self):
# your strategy here
To preform it monthly, we could use this as our date rule:
# self.AddEquity("SPY")
self.DateRules.MonthStart("SPY")
Here is more information regarding scheduled event.
2. We could use data consolidator. Here is an example to consolidate "SPY" daily data into 7-day bar:
from datetime import timedelta
# in self.Initialize():
self.AddEquity("SPY", Resolution.Daily)
consolidator = TradeBarConsolidator(timedelta(days=7))
consolidator.DataConsolidated += self.OnDataConsolidated
self.SubscriptionManager.AddConsolidator("SPY", consolidator)
# later in the algorithm:
def OnDataConsolidated(self, sender, bar):
# perform your strategy here
3. We could use a flag. Here is an example with a monthly flag:
# in self.Initialize():
self.month = -1
# before universe selection:
if self.month == self.Time.month: return
# after universe selection:
self.month = self.Time.month # ensure the universe selection only run once in every month
Hope it helps.
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.
Aleksandr Nalivajko
Please explain to me on what date the data are taken in the Universe Selection. For example if self.SetStartDate(2019,6,4) how can I understand that Coarsefundmental is taking data from the previous trading day(2019-06-03)?
By default, self.UniverseSettings.fillForward == False?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.
Aleksandr Nalivajko
ok...I helped myself.
for x in coarse:
self.Log(x.Time)
Coarsefundmental takes data from the current trading day. Why??
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.
Aleksandr Nalivajko
*Coarsefundmental starts with data from self.SetStartDate.
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.
Aleksandr Nalivajko
Sorry, I was wrong. I didn't count the following when I checked the data:
"Finally, when reviewing the results of your history requests remember they are indexed by the EndTime of each data point. For daily data, this results in makes it appear datapoints appear on Saturday, and skipping Monday's bar."
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.
Daniel Chen
Hi Bill,
Thank you for your question. Generally speaking, the subscribed data for the filtered symbols are in the slice variable in the OnData(Slice slice) method. You can just simply access any of them with slice[symbol]. For example, if "AAPL" is in your filtered symbols set, then you can assess its data using slice["AAPL"] in the OnData(Slice slice) method.
If you only want the added or removed universe, then the changes variable in the OnSecuritiesChanged() method would suffice. We provide many examples of how to use filtered symbols after Universe Selection. Please check out the examples on the top of the same page. Thank you!
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.
Hielke Hagendoorn
Hi, I'm a beginner here, so sorry if I ask for the obvious, but could somebody please help me with the following. I would like to select stocks which have a (weekly)close above the weekly upper bollingerband. Is there an example available about using a indicator with weekly data in the universe selection? Any help would be welcome.
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.
Ivan Baev
Is is possible to use Currencies Market in the Universe Selection? If I want top 10 winners / losers for the past week?
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.
Jared Broad
Currencies do not delist as frequently as stocks so do not require universes. It is perfectly acceptable to manually add all 20-30 FOREX assets to your algorithm and perform the winners/losers tests on your entire portfolio.
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!