BasePairsTradingAlphaModel
QuantConnect.Algorithm.Framework.Alphas.BasePairsTradingAlphaModel
BasePairsTradingAlphaModel(
lookback: int = 1,
resolution: Resolution = ...,
threshold: float = 1,
)
Bases: AlphaModel
This alpha model is designed to accept every possible pair combination from securities selected by the universe selection model This model generates alternating long ratio/short ratio insights emitted as a group
Initializes a new instance of the BasePairsTradingAlphaModel class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lookback
|
int
|
Lookback period of the analysis |
1
|
resolution
|
Resolution
|
Analysis resolution |
...
|
threshold
|
float
|
The percent <0, 100> deviation of the ratio from the mean before emitting an insight |
1
|
name
name: str
Defines a name for a framework model
instance
instance: Any
Gets the underlying python instance
This codeEntityType is protected.
PythonRuntimeChecker
Bases: Object
Set of helper methods to invoke Python methods with runtime checks for return values and out parameter's conversions.
has_passed_test
has_passed_test(
algorithm: QCAlgorithm,
asset_1: Union[Symbol, str, BaseContract],
asset_2: Union[Symbol, str, BaseContract],
) -> bool
Check whether the assets pass a pairs trading test
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
QCAlgorithm
|
The algorithm instance that experienced the change in securities |
required |
asset_1
|
Union[Symbol, str, BaseContract]
|
The first asset's symbol in the pair |
required |
asset_2
|
Union[Symbol, str, BaseContract]
|
The second asset's symbol in the pair |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the statistical test for the pair is successful. |
on_securities_changed
on_securities_changed(
algorithm: QCAlgorithm, changes: SecurityChanges
) -> None
Event fired each time the we add/remove securities from the data feed
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
QCAlgorithm
|
The algorithm instance that experienced the change in securities |
required |
changes
|
SecurityChanges
|
The security additions and removals from the algorithm |
required |
update
update(
algorithm: QCAlgorithm, data: Slice
) -> Iterable[Insight]
Updates this alpha model with the latest data from the algorithm. This is called each time the algorithm receives data for subscribed securities
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
algorithm
|
QCAlgorithm
|
The algorithm instance |
required |
data
|
Slice
|
The new data available |
required |
Returns:
| Type | Description |
|---|---|
Iterable[Insight]
|
The new insights generated. |
equals
equals(obj: Any) -> bool
equals(
other: BasePythonWrapper[
QuantConnect_Python_BasePythonWrapper_TInterface
],
) -> bool
Signature descriptions:
-
Determines whether the specified object is an instance of BasePythonWrapper{TInterface} and wraps the same Python object reference as this instance, which would indicate that they are equal.
-
Determines whether the specified instance wraps the same Python object reference as this instance, which would indicate that they are equal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Optional[Any]
|
The other object to compare this with |
None
|
other
|
Optional[BasePythonWrapper[QuantConnect_Python_BasePythonWrapper_TInterface]]
|
The other object to compare this with |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if both instances are equal, that is if both wrap the same Python object reference. |
set_python_instance
set_python_instance(instance: Any) -> None
set_python_instance(
instance: Any, validate_interface: bool
) -> None
Signature descriptions:
-
Sets the python instance
-
Sets the python instance and sets the validate interface flag
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
Any
|
The underlying python instance |
required |
validate_interface
|
Optional[bool]
|
Whether to perform validations for interface implementation |
None
|
dispose
dispose() -> None
Dispose of this instance
get_event
get_event(name: str) -> Any
Gets the Python instance event with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the event |
required |
get_hash_code
get_hash_code() -> int
Gets the hash code for the current instance
Returns:
| Type | Description |
|---|---|
int
|
The hash code of the current instance. |
get_method
get_method(
method_name: str, python_only: bool = False
) -> Any
Gets the Python instances method with the specified name and caches it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
python_only
|
bool
|
Whether to only return python methods |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
The matched method. |
get_property
get_property(property_name: str) -> Any
Gets the Python instance property with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
The name of the property |
required |
has_attr
has_attr(name: str) -> bool
Determines whether the Python instance has the specified attribute
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The attribute name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Whether the Python instance has the specified attribute. |
invoke_method
invoke_method(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> Any
Invokes the specified method with the specified arguments
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
invoke_void_method
invoke_void_method(
method_name: str, *args: Union[Object, Iterable[Object]]
) -> None
Invokes the specified method with the specified arguments without returning a value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
The name of the method |
required |
args
|
Union[Object, Iterable[Object]]
|
The arguments to call the method with |
()
|
set_property
set_property(property_name: str, value: Any) -> None
Sets the Python instance property with the specified name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
property_name
|
str
|
The name of the property |
required |
value
|
Any
|
The property value |
required |