Skip to content

Prompt One Shot Failure: Incorrect AddUniverse Overload #2348

@AlexCatarino

Description

@AlexCatarino

Prompt

Build an algorithm that selects the 500 most liquid US Equities priced above $10 per share with daily dollar volume above $10 million. Schedule the universe to refresh at the start of each month, since the top 500 changes infrequently. No trading logic is required � the focus is defining a fundamental universe with liquidity and price filters. Backtest from September 1, 2024 to December 31, 2024.

Error

The backtest ended with a runtime error.

During the algorithm initialization, the following exception has occurred: returned a result with an exception set
at initialize
self._universe = self.add_universe(
^^^^^^^^^^^^^^^^^^
in main.py: line 16
returned a result with an exception set QuantConnect.Data.UniverseSelection.UniverseSettings value cannot be converted to System.Func`2[System.Collections.Generic.IEnumerable`1[QuantConnect.Data.Fundamental.FineFundamental],System.Object]

<slot wrapper 'repr' of 'object' objects> returned a result with an exception set
at initialize
self._universe = self.add_universe(
^^^^^^^^^^^^^^^^^^
in main.py: line 16
<slot wrapper 'repr' of 'object' objects> returned a result with an exception set QuantConnect.Data.UniverseSelection.UniverseSettings value cannot be converted to System.Func2[System.Collections.Generic.IEnumerable1[QuantConnect.Data.Fundamental.FineFundamental],System.Object]

Code

main.py

from AlgorithmImports import *
from typing import List


class LiquidUSEquitiesUniverse(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 9, 1)
        self.set_end_date(2024, 12, 31)
        self.set_cash(100_000)

        self.settings.seed_initial_prices = True

        # Schedule universe selection at the start of each month.
        # Using a scheduled universe refreshes the selection on the given schedule.
        self._universe = self.add_universe(
            self._select_assets,
            UniverseSettings(
                Resolution.Daily,
                -1,       # leverage
                True,     # fill_forward
                False,    # extended_market_hours
                timedelta(0)  # minimum_time_in_universe
            )
        )

        # Refresh the universe at the start of each month instead of daily.
        self._universe.universe_settings.schedule.on(
            self.date_rules.month_start(),
            self.time_rules.at(0, 0)
        )

    def _select_assets(self, fundamentals: List[Fundamental]) -> List[Symbol]:
        # Filter: price above $10 and daily dollar volume above $10 million.
        filtered = [
            f for f in fundamentals
            if f.price > 10
            and f.dollar_volume > 10_000_000
        ]
        # Sort by dollar volume descending and take the top 500.
        top_500 = sorted(filtered, key=lambda f: f.dollar_volume, reverse=True)[:500]
        return [f.symbol for f in top_500]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions