Back

Algorithm warmup does not actually warm-up an Alpha model

I am still learning the QC framework, so will try to explain what I understand about the sequence of function calls (pls correct me).



# Algo framework init creates class for Alpha model and initializes all other methods called within it:

2019-01-01 00:00:00 Launching analysis for 8567ee4b7e4176fdba2b70a63d1819f3 with LEAN Engine v2.4.0.0.7443
2018-11-16 00:00:00 alpha init: initializing securities

# Then, since I had self.SetWarmUp(30)
# it starts warmup for 30 bars (in this case days),
# since in this case my securities are subscribed to daily:
# self.AddEquity("SPY", Resolution.Daily)?
2018-11-16 00:00:00 Algorithm warming up...

# Then OnData is called 30 times to 'warmup indicators'
# also Alpha model 'Update' is also called 30 times
2018-11-16 00:00:00 2018-11-16 00:00:00: algo warming up
2018-11-16 00:00:00 2018-11-16 00:00:00 num items in symbol data: 0
2018-11-17 00:00:00 2018-11-17 00:00:00: algo warming up
2018-11-17 00:00:00 2018-11-17 00:00:00 num items in symbol data: 0
2018-11-20 00:00:00 2018-11-20 00:00:00: algo warming up
2018-11-20 00:00:00 2018-11-20 00:00:00 num items in symbol data: 0

# however Alpha model Update isnt able to warm up, since
# symbolDataBySymbol was not initialized:
num = len(self.symbolDataBySymbol.items())
algorithm.Debug(time + " num items in symbol data: " + str(num))

2019-01-01 00:00:00 Algorithm finished warming up.
# but real warmup hasn't even started :)

2019-01-01 00:00:00 >> OnSecuritiesChanged started
# This really warms up RSI, using the history call
2019-01-01 00:00:00 warming up RSI
2019-01-01 00:00:00 >> OnSecuritiesChanged complete

1. In case we are using the 'algorithm framework' coding framework, does  self.SetWarmUp() help at all? It seems it just calls data loops and does not really warmup anything...

2. in terms for performance how different is warmup vs history calls?

3. Indicators have a IsReady property, how reliable is it, what does is check to insure an indicator is ready? Can I skip warmup, and just rely on this property?

 

 

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.


The RSI values are really off vs the test data available here:

https://github.com/QuantConnect/Lean/blob/master/Tests/TestData/spy_with_indicators.txt

Date RSI 14 Wilder RSI with warmup (wilders)
1/9/13 0:00 52.21
1/10/13 0:00 51.76
1/11/13 0:00 51.33
1/14/13 0:00 51.72
1/15/13 0:00 52.78
1/16/13 0:00 52.82
1/17/13 0:00 52.66
1/18/13 0:00 52.73
1/22/13 0:00 53.60
1/23/13 0:00 54.00
1/24/13 0:00 54.73
1/25/13 0:00 55.00
1/28/13 0:00 55.80
1/29/13 0:00 55.60
1/30/13 0:00 88.04 56.21
1/31/13 0:00 81.63 55.51
2/1/13 0:00 85.12 55.15
2/4/13 0:00 72.26 56.54
2/5/13 0:00 75.33 54.50
2/6/13 0:00 75.54 55.96
2/7/13 0:00 71.64 56.05
2/8/13 0:00 73.35 55.81
2/11/13 0:00 71.29 56.60
2/12/13 0:00 73.07 56.57
2/13/13 0:00 69.58 56.81
2/14/13 0:00 68.64 56.96
2/15/13 0:00 69.03 57.09
2/19/13 0:00 71.53 56.90
2/20/13 0:00 60.93 57.96
2/21/13 0:00 56.98 55.48
2/22/13 0:00 63.49 54.37
2/25/13 0:00 49.07 55.80
2/26/13 0:00 54.97 52.49
2/27/13 0:00 62.12 53.48
2/28/13 0:00 60.88 55.29
3/1/13 0:00 62.24 54.94
3/4/13 0:00 63.72 55.43
3/5/13 0:00 68.16 56.12
3/6/13 0:00 69.52 57.42
3/7/13 0:00 70.57 57.59
3/8/13 0:00 72.65 57.84

 

0

Hey Seersquant,

Algorithm warmup isn't available with universe selection. This is because securities are constantly being added/removed from your universe. Instead you must make a history call to manually warm up any indicators, rolling windows, etc. The 200-50 EMA bootcamp provides a good example of this in action. The key is to create a SymbolData class which can house all our relevant data, including indicators and rolling windows, for each symbol. When we initialize our indicators and rolling windows, we also make a history call to warm up them up with historical data.

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.


Hi Rahul, 

Yes I understand that during universe selection warm-up does not help, since warm-up happens only once. 

However in this example, I am using ManualUniverseSelection, and was thus hoping that

self.SetWarmUp(30)
would wamup:self.AddAlpha(RsiAlphaModel(self, 60, Resolution.Daily, warmup = False))(without an explicit call by RsiAlphaModel to history).To understand the internal mechanics, am trying to find an example in the newer framework approach, where self.SetWarmUp(30) doesactually warm-up the indicators.
 
 
0

Hey Seersquant,

Unfortunately, SetWarmUp does not work for any algorithm that uses universe selection, even if it is manual universe selection. I attached an example which highlights this. Instead of using warmup, we need to use historical data to prime our indicators. This makes sure our algorithm is stateless and is ready to emit insights at any time.

As an alternative approach, you can add all your symbols using AddEquity. This can be done easily using a for loop with the array of symbols you wish to add.

tickers = ["SPY", "TLT", "GOOG", "TSLA", "XOM", "GS", "JNJ", "AMZN", ...]
for ticker in tickers:
AddEquity(ticker, Resolution.Daily)

This allows you to use warmup while having similar functionalities to manual universe selection.

1

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