Skip to content

CustomUniverse

QuantConnect.Algorithm.Framework.Selection.CustomUniverse

CustomUniverse(
    configuration: SubscriptionDataConfig,
    universe_settings: UniverseSettings,
    interval: timedelta,
    selector: Callable[[datetime], List[str]],
)

Bases: UserDefinedUniverse

Defines a universe as a set of dynamically set symbols.

Creates a new instance of the CustomUniverse

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.

collection_changed

collection_changed: _EventContainer[
    Callable[
        [Object, NotifyCollectionChangedEventArgs], Any
    ],
    Any,
]

Event fired when a symbol is added or removed from this universe

interval

interval: timedelta

Gets the interval of this user defined universe

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_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]

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 ISubscriptionDataConfigService

Instance which implements ISubscriptionDataConfigService interface

required

Returns:

Type Description
Iterable[SubscriptionRequest]

All subscriptions required by this security.

get_trigger_times

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

Returns an enumerator that defines when this user defined universe will be invoked

Returns:

Type Description
Iterable[datetime]

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

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.

select_symbols

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

Returns the symbols defined by the user for this universe

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.

add

add(symbol: Union[Symbol, str, BaseContract]) -> bool
add(
    subscription_data_config: SubscriptionDataConfig,
) -> bool

Signature descriptions:

  • Adds the specified Symbol to this universe

  • Adds the specified SubscriptionDataConfig to this universe

Parameters:

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

The symbol to be added to this universe

None
subscription_data_config Optional[SubscriptionDataConfig]

The subscription data configuration to be added to this universe

None

Returns:

Type Description
bool

Depends on the signature used. Case 1: [True if the symbol was added, false if it was already present.]; Case 2: [True if the subscription_data_config was added, false if it was already present.]

create_symbol

create_symbol(
    security_type: SecurityType, market: str
) -> Symbol

Creates a user defined universe symbol

Parameters:

Name Type Description Default
security_type SecurityType

The security

required
market str

The market

required

Returns:

Type Description
Symbol

A symbol for user defined universe of the specified security type and market.

on_collection_changed

on_collection_changed(
    e: NotifyCollectionChangedEventArgs,
) -> None

Event invocator for the collection_changed event

This codeEntityType is protected.

Parameters:

Name Type Description Default
e NotifyCollectionChangedEventArgs

The notify collection changed event arguments

required

remove

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

Removes the specified Symbol from this universe

Parameters:

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

The symbol to be removed

required

Returns:

Type Description
bool

True if the symbol was removed, false if the symbol was not present.