Back

Documentation discussion algorithm-reference/universes

Update Backtest







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.


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?

0

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.

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.


Update Backtest





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.


Loading...

This discussion is closed