The following call from the AlphaModel to ETFConstituentsData returns an empty dictionary or at least an empty symbols list. Any idea why?
import typing
from AlgorithmImports import *
from datetime import timedelta
from QuantConnect.Indicators import SimpleMovingAverage
from AlphaModel import *
from QuantConnect.DataSource import *
#endregion
class TechnicalAlphaModel(AlphaModel):
def Update(self, algorithm, data):
insights = []
c_data = []
symbols = []
constituents = data.Get(ETFConstituentData)
#symbols = constituents.keys()
#c_data = constituents.values()
for kvp in constituents:
symbol = kvp.Key
constituentData = kvp.Value
c_data.append(constituentData)
symbols.append(symbol)
algorithm.Debug(f'symbols {symbols}')
Mia Alissi
Based on the information provided in the extracts, it's not clear why the
ETFConstituentsData
is returning an empty dictionary. However, it's important to note that theUpdate
method in theAlphaModel
must return a list of insights. If there are no insights, it should return an empty list.Here is an example of how to structure the
Update
method:In your case, you might want to ensure that
ETFConstituentsData
is properly set up and that the data is available at the time of the call. If the data is not available, it could result in an empty dictionary.Unfortunately, without more information or context, it's difficult to provide a more specific solution. You might find it helpful to review the QuantConnect documentation or ask for help in the QuantConnect forum.
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.
Amir Goren
Here is a whole script. The symbols list is empty and I'm not sure why.
Mia Alissi
Based on the provided script, it seems like you are trying to access the ETF constituents data in your
Update
method of theTechnicalAlphaModel
. However, theUpdate
method is not the correct place to access this data.The ETF constituents data should be accessed in the
FilterETFConstituents
method, which is called when the universe selection model is determining which securities to include in the universe.Here is an example of how you might modify your
FilterETFConstituents
method to access the ETF constituents data:In this modified method, we iterate over the constituents and add the symbol of each constituent with a non-null weight to the
symbols
list. This list is then returned by the method, which means these symbols will be included in the universe.Please note that the
Update
method in yourAlphaModel
should return a list of insights, not a list of symbols. If you want to generate insights based on the ETF constituents data, you should do this in theUpdate
method of yourAlphaModel
, using the symbols that were included in the universe by theFilterETFConstituents
method.Unfortunately, without more information or context, it's difficult to provide a more specific solution. You might find it helpful to review the QuantConnect documentation or ask for help in the QuantConnect forum.
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.
Amir Goren
I'm trying to change your example:
Â
Â
Â
Â
Â
Â
Â
Amir Goren
Your example from github also doesn't work:
Amir Goren
Is it possible to have a human take a look?
Louis Szeto
Hi Amir
Sorry for the delay. You can try this:
Basically we're setting up a cache in the main algorithm instance, and set up a point to the main algorithm when constructing the custom alpha model. Then, we can have access to the cache through the pointer. Note that the cache will only be updated on every ETFConstituent filter call in the main algorithm.
Best
Louis
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.
Amir Goren
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!