FuturesChain
QuantConnect.Data.Market.FuturesChain
FuturesChain(
canonical_future_symbol: Union[
Symbol, str, BaseContract, Security
],
time: Union[datetime, date],
flatten: bool = True,
)
FuturesChain(
canonical_future_symbol: Union[
Symbol, str, BaseContract, Security
],
time: Union[datetime, date],
contracts: List[FutureUniverse],
flatten: bool = True,
)
Bases: BaseChain[FuturesContract, FuturesContracts, QuantConnect_Data_Market_FuturesChain, FuturesChainFilterUniverse], IFutureContractFilters[QuantConnect_Data_Market_FuturesChain]
The futures chain filters, the same ones the futures universe selection offers, see IFutureContractFilters{TSelf}. The filters shared with the option chains live in BaseChain{T, TContractsCollection, TSelf, TUniverse}. Each filter returns a new chain, leaving this one untouched
Initializes a new instance of the FuturesChain class
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
canonical_future_symbol
|
Union[Symbol, str, BaseContract, Security]
|
The symbol for this chain. |
required |
time
|
Union[datetime, date]
|
The time of this chain |
required |
flatten
|
bool
|
Whether to flatten the data frame |
True
|
contracts
|
Optional[List[FutureUniverse]]
|
The list of contracts that form this chain |
None
|
underlying
underlying: BaseData
Gets the most recent trade information for the underlying. This may be a Tick or a TradeBar
trade_bars
trade_bars: TradeBars
Gets all trade bars for every option contract in this chain, keyed by option symbol
quote_bars
quote_bars: QuoteBars
Gets all quote bars for every option contract in this chain, keyed by option symbol
contracts
contracts: (
QuantConnect_Data_Market_BaseChain_TContractsCollection
)
Gets all contracts in the chain, keyed by option symbol
filtered_contracts
filtered_contracts: HashSet[Symbol]
Gets the set of symbols that passed the Option.ContractFilter
data_frame
data_frame: Any
The data frame representation of the option chain
count
count: int
The number of contracts in this chain
clone
clone() -> BaseData
Return a new instance clone of this object, used in fill forward
Returns:
| Type | Description |
|---|---|
BaseData
|
A clone of the current object. |
contract_months
contract_months(months: List[int]) -> FuturesChain
Selects the contracts whose contract month is any of the given months of the year, like expiration_cycle but by the contract month, the month the contract is named after, which for some products, e.g. crude oil, is the month after the expiration month. Same as BaseFutureFilterUniverse{TUniverse, TData}.ContractMonths
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
months
|
List[int]
|
Months of the year to select contracts from, see FutureExpirationCycles |
required |
Returns:
| Type | Description |
|---|---|
FuturesChain
|
A new chain with the filter applied. |
create_chain
create_chain(
contracts: List[FuturesContract],
) -> FuturesChain
Creates a copy of this chain with only the given contracts
This Class is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contracts
|
List[FuturesContract]
|
The contracts to keep |
required |
create_filter_universe
create_filter_universe() -> FuturesChainFilterUniverse
Creates the filter universe over the contracts of this chain
This Class is protected.
expiration_cycle
expiration_cycle(months: List[int]) -> FuturesChain
Selects the contracts expiring in any of the given months of the year. Same as BaseFutureFilterUniverse{TUniverse, TData}.ExpirationCycle
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
months
|
List[int]
|
Months to select contracts from, see FutureExpirationCycles |
required |
Returns:
| Type | Description |
|---|---|
FuturesChain
|
A new chain with the filter applied. |
expiration
expiration(
min_expiry: timedelta, max_expiry: timedelta
) -> QuantConnect_Data_Market_BaseChain_TSelf
expiration(
min_expiry_days: int, max_expiry_days: int
) -> QuantConnect_Data_Market_BaseChain_TSelf
expiration(
expiries: List[datetime],
) -> QuantConnect_Data_Market_BaseChain_TSelf
Signature descriptions:
-
Selects the contracts expiring in the given range relative to the chain date. Same as ContractSecurityFilterUniverse{T, TData}.Expiration(TimeSpan, TimeSpan)
-
Selects the contracts expiring in the given range of days relative to the chain date. Same as ContractSecurityFilterUniverse{T, TData}.Expiration(int, int)
-
Selects the contracts expiring on any of the given dates. Time of day is ignored. Same as ContractSecurityFilterUniverse{T, TData}.Expiration(IEnumerable{DateTime})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min_expiry
|
Optional[timedelta]
|
The minimum time until expiry to include, for example, TimeSpan.FromDays(10) |
None
|
max_expiry
|
Optional[timedelta]
|
The maximum time until expiry to include, for example, TimeSpan.FromDays(10) |
None
|
min_expiry_days
|
Optional[int]
|
The minimum time, expressed in days, until expiry to include, for example, 10 |
None
|
max_expiry_days
|
Optional[int]
|
The maximum time, expressed in days, until expiry to include, for example, 10 |
None
|
expiries
|
Optional[List[datetime]]
|
The expiration dates |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
back_month
back_month() -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts of the second nearest expiration. Same as ContractSecurityFilterUniverse{T, TData}.BackMonth
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
back_months
back_months() -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts of all expirations but the nearest one. Same as ContractSecurityFilterUniverse{T, TData}.BackMonths
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
expiring_after
expiring_after(
date: Union[datetime, date],
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts expiring after the given date, excluding it. Time of day is ignored. Same as ContractSecurityFilterUniverse{T, TData}.ExpiringAfter
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Union[datetime, date]
|
The date the expirations must be after |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
expiring_before
expiring_before(
date: Union[datetime, date],
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts expiring before the given date, excluding it. Time of day is ignored. Same as ContractSecurityFilterUniverse{T, TData}.ExpiringBefore
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date
|
Union[datetime, date]
|
The date the expirations must be before |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
farthest_expiration
farthest_expiration() -> (
QuantConnect_Data_Market_BaseChain_TSelf
)
Selects the contracts of the farthest expiration. Same as ContractSecurityFilterUniverse{T, TData}.FarthestExpiration
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
front_month
front_month() -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts of the nearest expiration. Same as ContractSecurityFilterUniverse{T, TData}.FrontMonth
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
oi
oi(
min: int, max: int
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts with open interest in the given range. Alias for open_interest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
int
|
The minimum open interest value |
required |
max
|
int
|
The maximum open interest value |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
open_interest
open_interest(
min: int, max: int
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts with open interest in the given range. Same as ContractSecurityFilterUniverse{T, TData}.OpenInterest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
int
|
The minimum open interest value |
required |
max
|
int
|
The maximum open interest value |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
standards_only
standards_only() -> (
QuantConnect_Data_Market_BaseChain_TSelf
)
Selects the standard contracts in the chain. Unlike ContractSecurityFilterUniverse{T, TData}.StandardsOnly, it applies to the contracts already selected, so it can be combined with the expiry filters in any order
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
volume
volume(
min: int, max: int
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts with volume in the given range. Same as ContractSecurityFilterUniverse{T, TData}.Volume
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
min
|
int
|
The minimum volume |
required |
max
|
int
|
The maximum volume |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
weeklys_only
weeklys_only() -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the non standard contracts in the chain. Unlike ContractSecurityFilterUniverse{T, TData}.WeeklysOnly, it applies to the contracts already selected, so it can be combined with the expiry filters in any order
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
zero_dte
zero_dte() -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts expiring today. Same as ContractSecurityFilterUniverse{T, TData}.ZeroDte
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
get_aux
get_aux(
symbol: Union[Symbol, str, BaseContract, Security],
) -> QuantConnect_Data_Market_BaseChain_GetAux_TAux
get_aux() -> (
DataDictionary[
QuantConnect_Data_Market_BaseChain_GetAux_TAux
]
)
Signature descriptions:
-
Gets the auxiliary data with the specified type and symbol
-
Gets all auxiliary data of the specified type as a dictionary keyed by symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Optional[Union[Symbol, str, BaseContract, Security]]
|
The symbol of the auxiliary data |
None
|
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_GetAux_TAux | DataDictionary[QuantConnect_Data_Market_BaseChain_GetAux_TAux]
|
Depends on the signature used. Case 1: [The last auxiliary data with the specified type and symbol.]; Case 2: [A dictionary containing all auxiliary data of the specified type.] |
get_aux_list
get_aux_list(
symbol: Union[Symbol, str, BaseContract, Security],
) -> List[
QuantConnect_Data_Market_BaseChain_GetAuxList_TAux
]
Signature descriptions:
-
Gets a list of auxiliary data with the specified type and symbol
-
Gets all auxiliary data of the specified type as a dictionary keyed by symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Optional[Union[Symbol, str, BaseContract, Security]]
|
The symbol of the auxiliary data |
None
|
Returns:
| Type | Description |
|---|---|
List[QuantConnect_Data_Market_BaseChain_GetAuxList_TAux] | Dictionary[Symbol, List[BaseData]]
|
Depends on the signature used. Case 1: [The list of auxiliary data with the specified type and symbol.]; Case 2: [A dictionary containing all auxiliary data of the specified type.] |
__contains__
__contains__(
key: Union[Symbol, str, BaseContract, Security],
) -> bool
Checks if the chain contains a contract with the specified symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[Symbol, str, BaseContract, Security]
|
The symbol of the contract to check for |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the chain contains a contract with the specified symbol; otherwise, false. |
__iter__
__iter__() -> (
Iterator[QuantConnect_Data_Market_BaseChain_T]
)
__len__
__len__() -> int
contains_key
contains_key(
key: Union[Symbol, str, BaseContract, Security],
) -> bool
Checks if the chain contains a contract with the specified symbol
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Union[Symbol, str, BaseContract, Security]
|
The symbol of the contract to check for |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the chain contains a contract with the specified symbol; otherwise, false. |
filter
filter(
filter: Callable[
[QuantConnect_Data_Market_BaseChain_TUniverse],
QuantConnect_Data_Market_BaseChain_TUniverse,
],
) -> QuantConnect_Data_Market_BaseChain_TSelf
Applies the given universe filter to the contracts of this chain and returns the result as a new chain
This Class is protected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter
|
Callable[[QuantConnect_Data_Market_BaseChain_TUniverse], QuantConnect_Data_Market_BaseChain_TUniverse]
|
The universe filter to apply |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |
get_enumerator
get_enumerator() -> (
IEnumerator[QuantConnect_Data_Market_BaseChain_T]
)
Returns an enumerator that iterates through the collection.
Returns:
| Type | Description |
|---|---|
IEnumerator[QuantConnect_Data_Market_BaseChain_T]
|
An enumerator that can be used to iterate through the collection. |
where
where(
predicate: Any,
) -> QuantConnect_Data_Market_BaseChain_TSelf
Selects the contracts matching the given predicate, e.g. chain.where(lambda contract: contract.open_interest > 100). From C# use Linq's Where, which keeps this chain's type untouched
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicate
|
Any
|
Function determining which contracts are kept |
required |
Returns:
| Type | Description |
|---|---|
QuantConnect_Data_Market_BaseChain_TSelf
|
A new chain with the filter applied. |