SecurityPositionGroupModel
QuantConnect.Securities.Positions.SecurityPositionGroupModel
Bases: ExtendedDictionary[PositionGroupKey, IPositionGroup]
Responsible for managing the resolution of position groups for an algorithm
NULL
NULL: SecurityPositionGroupModel = ...
Gets an implementation of SecurityPositionGroupModel that will not group multiple securities
position_group_buying_power_model
position_group_buying_power_model: (
IPositionGroupBuyingPowerModel
)
Get's the single security position group buying power model to use
This codeEntityType is protected.
is_only_default_groups
is_only_default_groups: bool
Gets whether or not the algorithm is using only default position groups
count
count: int
Gets the number of position groups in this collection
get_keys
get_keys: Iterable[PositionGroupKey]
Gets all the available position group keys
This codeEntityType is protected.
get_values
get_values: Iterable[IPositionGroup]
Gets all the available position groups
This codeEntityType is protected.
is_read_only
is_read_only: bool
Gets a value indicating whether the IDictionary object is read-only.
__getitem__
__getitem__(key: PositionGroupKey) -> IPositionGroup
Gets the IPositionGroup matching the specified key. If one is not found, then a new empty position group is returned.
__setitem__
__setitem__(
key: PositionGroupKey, value: IPositionGroup
) -> None
Gets the IPositionGroup matching the specified key. If one is not found, then a new empty position group is returned.
create_default_key
create_default_key(security: Security) -> PositionGroupKey
Creates a PositionGroupKey for the security's default position group
get_impacted_groups
get_impacted_groups(
positions: Sequence[IPosition],
) -> Iterable[IPositionGroup]
Determines which position groups could be impacted by changes in the specified positions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
Sequence[IPosition]
|
The positions to be changed |
required |
Returns:
| Type | Description |
|---|---|
Iterable[IPositionGroup]
|
All position groups that need to be re-evaluated due to changes in the positions. |
get_items
get_items() -> (
Iterable[KeyValuePair[PositionGroupKey, IPositionGroup]]
)
Gets all the items in the dictionary
Returns:
| Type | Description |
|---|---|
Iterable[KeyValuePair[PositionGroupKey, IPositionGroup]]
|
All the items in the dictionary. |
get_or_create_default_group
get_or_create_default_group(
security: Security,
) -> IPositionGroup
Gets or creates the default position group for the specified security
get_position_group_resolver
get_position_group_resolver() -> IPositionGroupResolver
Get the position group resolver instance to use
This codeEntityType is protected.
Returns:
| Type | Description |
|---|---|
IPositionGroupResolver
|
The position group resolver instance. |
initialize
initialize(securities: SecurityManager) -> None
Initializes a new instance of the SecurityPositionGroupModel class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
securities
|
SecurityManager
|
The algorithm's security manager |
required |
resolve_position_groups
resolve_position_groups(
positions: PositionCollection,
) -> PositionGroupCollection
Resolves position groups using the specified collection of positions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
positions
|
PositionCollection
|
The positions to be grouped |
required |
Returns:
| Type | Description |
|---|---|
PositionGroupCollection
|
A collection of position groups containing all of the provided positions. |
try_create_position_group
try_create_position_group(
orders: List[Order], group: Optional[IPositionGroup]
) -> Tuple[bool, IPositionGroup]
Creates a position group for the specified order, pulling
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orders
|
List[Order]
|
The order |
required |
group
|
Optional[IPositionGroup]
|
The resulting position group |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, IPositionGroup]
|
A new position group matching the provided order. |
try_get_value
try_get_value(
key: PositionGroupKey, value: Optional[IPositionGroup]
) -> Tuple[bool, IPositionGroup]
Tries to get the position group matching the specified key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
PositionGroupKey
|
The key to search for |
required |
value
|
Optional[IPositionGroup]
|
The position group matching the specified key |
required |
Returns:
| Type | Description |
|---|---|
Tuple[bool, IPositionGroup]
|
True if a group with the specified key was found, false otherwise. |
fromkeys
fromkeys(
sequence: List[QuantConnect_ExtendedDictionary_TKey],
) -> Dict[Any, Any]
fromkeys(
sequence: List[QuantConnect_ExtendedDictionary_TKey],
value: QuantConnect_ExtendedDictionary_TValue,
) -> Dict[Any, Any]
Signature descriptions:
-
Creates a new dictionary from the given sequence of elements.
-
Creates a new dictionary from the given sequence of elements with a value provided by the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequence
|
List[QuantConnect_ExtendedDictionary_TKey]
|
Sequence of elements which is to be used as keys for the new dictionary |
required |
value
|
Optional[QuantConnect_ExtendedDictionary_TValue]
|
Value which is set to each each element of the dictionary |
None
|
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Returns a new dictionary with the given sequence of elements as the keys of the dictionary. |
get
get(
key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
get(
key: QuantConnect_ExtendedDictionary_TKey,
value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue
Returns the value for the specified key if key is in dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
key to be searched in the dictionary |
required |
value
|
Optional[QuantConnect_ExtendedDictionary_TValue]
|
Value to be returned if the key is not found. The default value is null. |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_ExtendedDictionary_TValue
|
The value for the specified key if key is in dictionary. |
pop
pop(
key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
pop(
key: QuantConnect_ExtendedDictionary_TKey,
default_value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue
Removes and returns an element from a dictionary having the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
Key which is to be searched for removal |
required |
default_value
|
Optional[QuantConnect_ExtendedDictionary_TValue]
|
Value which is to be returned when the key is not in the dictionary |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_ExtendedDictionary_TValue
|
If key is found - removed/popped element from the dictionary |
setdefault
setdefault(
key: QuantConnect_ExtendedDictionary_TKey,
) -> QuantConnect_ExtendedDictionary_TValue
setdefault(
key: QuantConnect_ExtendedDictionary_TKey,
default_value: QuantConnect_ExtendedDictionary_TValue,
) -> QuantConnect_ExtendedDictionary_TValue
Returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
Key with null/None value is inserted to the dictionary if key is not in the dictionary. |
required |
default_value
|
Optional[QuantConnect_ExtendedDictionary_TValue]
|
Default value |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_ExtendedDictionary_TValue
|
The value of the key if it is in the dictionary |
clear
clear() -> None
Removes all items from the System.Collections.Generic.ICollection`1.
copy
copy() -> Dict[Any, Any]
Creates a shallow copy of the IExtendedDictionary{TKey, TValue}.
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Returns a shallow copy of the dictionary. It doesn't modify the original dictionary. |
items
items() -> List[Any]
Returns a view object that displays a list of dictionary's (key, value) tuple pairs.
Returns:
| Type | Description |
|---|---|
List[Any]
|
Returns a view object that displays a list of a given dictionary's (key, value) tuple pair. |
keys
keys() -> List[Any]
Returns a view object that displays a list of all the key objects in the dictionary
Returns:
| Type | Description |
|---|---|
List[Any]
|
Returns a view object that displays a list of all the key objects. When the dictionary is changed, the view object also reflect these changes. |
popitem
popitem() -> Any
Returns and removes an arbitrary element (key, value) pair from the dictionary.
Returns:
| Type | Description |
|---|---|
Any
|
Returns an arbitrary element (key, value) pair from the dictionary removes an arbitrary element(the same element which is returned) from the dictionary. Note: Arbitrary elements and random elements are not same.The popitem() doesn't return a random element. |
update
update(other: Any) -> None
Updates the dictionary with the elements from the another dictionary object or from an iterable of key/value pairs. The update() method adds element(s) to the dictionary if the key is not in the dictionary.If the key is in the dictionary, it updates the key with the new value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Any
|
Takes either a dictionary or an iterable object of key/value pairs (generally tuples). |
required |
values
values() -> List[Any]
Returns a view object that displays a list of all the values in the dictionary.
Returns:
| Type | Description |
|---|---|
List[Any]
|
Returns a view object that displays a list of all values in a given dictionary. |
__contains__
__contains__(
key: QuantConnect_ExtendedDictionary_TKey,
) -> bool
Checks if the dictionary contains the specified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
The key to locate in the dictionary |
required |
Returns:
| Type | Description |
|---|---|
bool
|
true if the dictionary contains an element with the specified key; otherwise, false. |
__len__
__len__() -> int
check_for_implicitly_created_symbol
check_for_implicitly_created_symbol(
symbol: Union[Symbol, str, BaseContract],
) -> None
Checks if the symbol is implicitly created from a string, in which case it is not in the symbol cache, and throws a KeyNotFoundException.
This codeEntityType is protected.
contains_key
contains_key(
key: QuantConnect_ExtendedDictionary_TKey,
) -> bool
Checks if the dictionary contains the specified key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
The key to locate in the dictionary |
required |
Returns:
| Type | Description |
|---|---|
bool
|
true if the dictionary contains an element with the specified key; otherwise, false. |
remove
remove(key: QuantConnect_ExtendedDictionary_TKey) -> bool
Removes the value with the specified key
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
QuantConnect_ExtendedDictionary_TKey
|
The key object of the element to remove. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
true if the element is successfully found and removed; otherwise, false. |