Skip to content

ScheduledUniverse

QuantConnect.Data.UniverseSelection.ScheduledUniverse

ScheduledUniverse(
    time_zone: Any,
    date_rule: IDateRule,
    time_rule: ITimeRule,
    selector: Callable[[datetime], List[Symbol]],
    settings: UniverseSettings = None,
)
ScheduledUniverse(
    time_zone: Any,
    date_rule: IDateRule,
    time_rule: ITimeRule,
    selector: Any,
    settings: UniverseSettings = None,
)
ScheduledUniverse(
    date_rule: IDateRule,
    time_rule: ITimeRule,
    selector: Any,
    settings: UniverseSettings = None,
)
ScheduledUniverse(
    date_rule: IDateRule,
    time_rule: ITimeRule,
    selector: Callable[[datetime], List[Symbol]],
    settings: UniverseSettings = None,
)

Bases: Universe, ITimeTriggeredUniverse

Defines a user that is fired based on a specified IDateRule and ITimeRule

Initializes a new instance of the ScheduledUniverse class

Parameters:

Name Type Description Default
time_zone Optional[Any]

The time zone the date/time rules are in

None
date_rule IDateRule

Date rule defines what days the universe selection function will be invoked

required
time_rule ITimeRule

Time rule defines what times on each day selected by date rule the universe selection function will be invoked

required
selector Callable[[datetime], List[Symbol]] | Any

Selector function accepting the date time firing time and returning the universe selected symbols

required
settings UniverseSettings

Universe settings for subscriptions added via this universe, null will default to algorithm's universe settings

None

UNCHANGED

UNCHANGED: UnchangedUniverse = ...

Gets a value indicating that no change to the universe should be made

securities

securities: ConcurrentDictionary[Symbol, Member]

Gets the internal security collection used to define membership in this universe

selected

selected: HashSet[Symbol]

The currently selected symbol set

asynchronous

asynchronous: bool

True if this universe filter can run async in the data stack

selection_changed

selection_changed: _EventContainer[
    Callable[[Object, EventArgs], Any], Any
]

Event fired when the universe selection has changed

security_type

security_type: SecurityType

Gets the security type of this universe

market

market: str

Gets the market of this universe

symbol

symbol: Symbol

Gets the symbol of this universe

data_type

data_type: Type

Gets the data type of this universe

dispose_requested

dispose_requested: bool

Flag indicating if disposal of this universe has been requested

universe_settings

universe_settings: UniverseSettings

Gets the settings used for subscriptions added for this universe

configuration

configuration: SubscriptionDataConfig

Gets the configuration used to get universe data

members

members: Dictionary[Symbol, Security]

Gets the current listing of members in this universe. Modifications to this dictionary do not change universe membership.

UnchangedUniverse

Bases: Object, Iterable[str]

Provides a value to indicate that no changes should be made to the universe. This value is intended to be returned by reference via Universe.select_symbols

INSTANCE

INSTANCE: UnchangedUniverse = ...

Read-only instance of the UnchangedUniverse value

__iter__

__iter__() -> Iterator[Symbol]

Member

Member(
    added: Union[datetime, date],
    security: Security,
    is_internal: bool,
)

Bases: Object

Member of the Universe

Initialize a new member for the universe

Parameters:

Name Type Description Default
added Union[datetime, date]

DateTime added

required
security Security

Security to add

required
is_internal bool

True if internal member

required

added

added: datetime

DateTime when added

security

security: Security

The security that was added

is_internal

is_internal: bool

True if the security was added as internal by this universe

SelectionEventArgs

SelectionEventArgs(current_selection: HashSet[Symbol])

Bases: EventArgs

Event fired when the universe selection changes

Creates a new instance

current_selection

current_selection: HashSet[Symbol]

The current universe selection

get_trigger_times

get_trigger_times(
    start_time_utc: Union[datetime, date],
    end_time_utc: Union[datetime, date],
    market_hours_database: MarketHoursDatabase,
) -> Iterable[datetime]

Get an enumerator of UTC DateTimes that defines when this universe will be invoked

Parameters:

Name Type Description Default
start_time_utc Union[datetime, date]

The start time of the range in UTC

required
end_time_utc Union[datetime, date]

The end time of the range in UTC

required

Returns:

Type Description
Iterable[datetime]

An enumerator of UTC DateTimes that defines when this universe will be invoked.

select_symbols

select_symbols(
    utc_time: Union[datetime, date],
    data: BaseDataCollection,
) -> Iterable[Symbol]

Performs universe selection using the data specified

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The current utc time

required
data BaseDataCollection

The symbols to remain in the universe

required

Returns:

Type Description
Iterable[Symbol]

The data that passes the filter.

get_subscription_requests

get_subscription_requests(
    security: Security,
    current_time_utc: Union[datetime, date],
    maximum_end_time_utc: Union[datetime, date],
    subscription_service: ISubscriptionDataConfigService,
) -> Iterable[SubscriptionRequest]
get_subscription_requests(
    security: Security,
    current_time_utc: Union[datetime, date],
    maximum_end_time_utc: Union[datetime, date],
) -> Iterable[SubscriptionRequest]

Gets the subscription requests to be added for the specified security

Parameters:

Name Type Description Default
security Security

The security to get subscriptions for

required
current_time_utc Union[datetime, date]

The current time in utc. This is the frontier time of the algorithm

required
maximum_end_time_utc Union[datetime, date]

The max end time

required
subscription_service Optional[ISubscriptionDataConfigService]

Instance which implements ISubscriptionDataConfigService interface

None

Returns:

Type Description
Iterable[SubscriptionRequest]

All subscriptions required by this security.

can_remove_member

can_remove_member(
    utc_time: Union[datetime, date], security: Security
) -> bool

Determines whether or not the specified security can be removed from this universe. This is useful to prevent securities from being taken out of a universe before the algorithm has had enough time to make decisions on the security

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The current utc time

required
security Security

The security to check if its ok to remove

required

Returns:

Type Description
bool

True if we can remove the security, false otherwise.

contains_member

contains_member(
    symbol: Union[Symbol, str, BaseContract],
) -> bool

Determines whether or not the specified symbol is currently a member of this universe

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol whose membership is to be checked

required

Returns:

Type Description
bool

True if the specified symbol is part of this universe, false otherwise.

create_security

create_security(
    symbol: Union[Symbol, str, BaseContract],
    algorithm: IAlgorithm,
    market_hours_database: MarketHoursDatabase,
    symbol_properties_database: SymbolPropertiesDatabase,
) -> Security

Creates and configures a security for the specified symbol

CreateSecurity is obsolete and will not be called. The system will create the required Securities based on selected symbols

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The symbol of the security to be created

required
algorithm IAlgorithm

The algorithm instance

required
market_hours_database MarketHoursDatabase

The market hours database

required
symbol_properties_database SymbolPropertiesDatabase

The symbol properties database

required

Returns:

Type Description
Security

The newly initialized security object.

dispose

dispose() -> None

Marks this universe as disposed and ready to remove all child subscriptions

on_selection_changed

on_selection_changed(
    selection: HashSet[Symbol] = None,
) -> None

Event invocator for the selection_changed event

This codeEntityType is protected.

Parameters:

Name Type Description Default
selection HashSet[Symbol]

The current universe selection

None

perform_selection

perform_selection(
    utc_time: Union[datetime, date],
    data: BaseDataCollection,
) -> Iterable[Symbol]

Performs universe selection using the data specified

Parameters:

Name Type Description Default
utc_time Union[datetime, date]

The current utc time

required
data BaseDataCollection

The symbols to remain in the universe

required

Returns:

Type Description
Iterable[Symbol]

The data that passes the filter.