Hi there,
I'm new here and learning how to build strategy with QC while I'm struggling for couple of days when using FundamentalUniverseSelectionModel. Below is a piece of code copying from official documents. Whenever I run backtest with it, i always get below error. I'm sure the select function has been overrided and I've also tried to use Select with upper case. However it sill no go. I hope if someone can give me some guidance of what goes wrong and how to fix it.
Thank you!
Runtime Error: If inheriting, please overrride the 'Select' fundamental function, else provide it as a constructor parameter in FundamentalUniverseSelectionModel.cs:line 203 (Open Stack Trace)
class CustomUniverseSelection(FundamentalUniverseSelectionModel):
def __init__(self, universe_count=10, universe_settings=None):
super().__init__(False, universe_settings)
self.universe_count = universe_count
self._selection_data_by_symbol = {}
def select(self, algorithm: QCAlgorithm, fundamental: list[Fundamental]) -> list[Symbol]:
for f in fundamental:
# Create/Update the EMA indicators of each stock.
if f.symbol not in self._selection_data_by_symbol:
self._selection_data_by_symbol[f.symbol] = self.SelectionData(algorithm, f.symbol, 200)
self._selection_data_by_symbol[f.symbol].update(f.end_time, f.adjusted_price, f.dollar_volume)
# Select the Equities above their EMA and have a daily volume of $1B.
# These assets are in an uptrend and are very liquid.
selected = [x for x in self._selection_data_by_symbol.values() if x.is_above_ema and x.volume > 1_000_000_000]
# Select the 10 most liquid Equities to avoid extra slippage.
return [x.symbol for x in sorted(selected, key=lambda x: x.volume)[-self.universe_count:]]
class SelectionData():
def __init__(self, algorithm: QCAlgorithm, symbol: Symbol, period: int):
self.symbol = symbol
self._ema = ExponentialMovingAverage(period)
self.is_above_ema = False
self.volume = 0
algorithm.warm_up_indicator(symbol, self._ema, Resolution.DAILY)
def update(self, time: datetime, price: float, volume: float) -> None:
self.volume = volume
if self._ema.update(time, price):
self.is_above_ema = price > self._ema.current.value
Mia Alissi
Here's a corrected version of your CustomUniverseSelection class that resolves the runtime error and follows QuantConnect's framework conventions:
Key Fixes:
select(notSelect).universe_settingsor nothing).This code should eliminate your runtime error and provide a working foundation for your fundamental universe selection. Let me know if you need further help!
Sources: docs writing algorithms datasets morningstar us fundamental data, Custom Universe Selection Model Regression Algorithm, Fundamental Universe Selection Algorithm, Fundamental Universes - QuantConnect.com, Fundamental Universe Selection Regression Algorithm
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.
Jervis Qian
it doesn't work. I still got below error.
Runtime Error: If inheriting, please overrride the 'Select' fundamental function, else provide it as a constructor parameter in FundamentalUniverseSelectionModel.cs:line 203 (Open Stack Trace)
Scott Taylor
I ran into this too…super frustrating.
I think it was a missing import:
`from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel `
Jervis Qian
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!