OptionContractUniverse
QuantConnect.Algorithm.Selection.OptionContractUniverse
OptionContractUniverse(
configuration: SubscriptionDataConfig,
universe_settings: UniverseSettings,
)
Bases: UserDefinedUniverse
This universe will hold single option contracts and their underlying, managing removals and additions
Creates a new empty instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configuration
|
SubscriptionDataConfig
|
The universe configuration to use |
required |
universe_settings
|
UniverseSettings
|
The universe settings to use |
required |
UNCHANGED
UNCHANGED: UnchangedUniverse = ...
Gets a value indicating that no change to the universe should be made
securities
Gets the internal security collection used to define membership in this universe
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
market
market: str
Gets the market 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
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
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
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
create_symbol
create_symbol(
market: str, security_type: SecurityType
) -> Symbol
Creates a user defined universe symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
market
|
str
|
The market |
required |
security_type
|
SecurityType
|
The underlying option security type |
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 UserDefinedUniverse.collection_changed event
This Class is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
e
|
NotifyCollectionChangedEventArgs
|
The notify collection changed event arguments |
required |
select_symbols
select_symbols(
utc_time: Union[datetime, date],
data: BaseDataCollection,
) -> Sequence[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 |
|---|---|
Sequence[Symbol]
|
The data that passes the filter. |
get_trigger_times
get_trigger_times(
start_time_utc: Union[datetime, date],
end_time_utc: Union[datetime, date],
market_hours_database: MarketHoursDatabase,
) -> Sequence[datetime]
Returns an enumerator that defines when this user defined universe will be invoked
Returns:
| Type | Description |
|---|---|
Sequence[datetime]
|
An enumerator of DateTime that defines when this universe will be invoked. |
try_get_universe
try_get_universe(
result: Optional[
QuantConnect_Data_UniverseSelection_UniverseExtensions_TryGetUniverse_T
],
) -> Tuple[
bool,
QuantConnect_Data_UniverseSelection_UniverseExtensions_TryGetUniverse_T,
]
Gets the given universe as the requested type, checking the universe it decorates, if any
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
Optional[QuantConnect_Data_UniverseSelection_UniverseExtensions_TryGetUniverse_T]
|
The universe as the requested type, if any |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, QuantConnect_Data_UniverseSelection_UniverseExtensions_TryGetUniverse_T]
|
True if the universe, or one it decorates, is of the requested type. |
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. |
chained_to
Creates a new universe that logically is the result of wiring the two universes together such that the first will produce subscriptions for the second and the second will only select on data that has passed the first.
NOTE: The first and second universe instances provided to this method should not be manually added to the algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
second
|
Universe
|
The second universe in this 'chain' |
required |
configuration_per_symbol
|
bool
|
True if each symbol as its own configuration, false otherwise |
required |
Returns:
| Type | Description |
|---|---|
Universe
|
A new universe that can be added to the algorithm that represents invoking the first universe and then the second universe using the outputs of the first. |
contains_member
contains_member(
symbol: Union[Symbol, str, BaseContract, Security],
) -> 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, Security]
|
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, Security],
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, Security]
|
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
get_subscription_requests
get_subscription_requests(
security: Security,
current_time_utc: Union[datetime, date],
maximum_end_time_utc: Union[datetime, date],
subscription_service: ISubscriptionDataConfigService,
) -> Sequence[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 |
|---|---|
Sequence[SubscriptionRequest]
|
All subscriptions required by this security. |
on_selection_changed
on_selection_changed(
selection: HashSet[Symbol] = None,
) -> None
Event invocator for the selection_changed event
This Class 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,
) -> Sequence[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 |
|---|---|
Sequence[Symbol]
|
The data that passes the filter. |
prefilter_using
Creates a new universe that restricts the universe selection data to symbols that passed the first universe's selection criteria
NOTE: The second universe instance provided to this method should not be manually added to the algorithm. The first should still be manually (assuming no other changes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
Universe
|
The universe providing the set of symbols used for filtered |
required |
Returns:
| Type | Description |
|---|---|
Universe
|
A new universe that can be added to the algorithm that represents invoking the second using the selections from the first as a filter. |
add
add(
symbol: Union[Symbol, str, BaseContract, Security],
) -> 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, Security]]
|
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.] |
remove
remove(
symbol: Union[Symbol, str, BaseContract, Security],
) -> bool
Removes the specified Symbol from this universe
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[Symbol, str, BaseContract, Security]
|
The symbol to be removed |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the symbol was removed, false if the symbol was not present. |