Skip to content

BaseChain

QuantConnect.Data.Market.BaseChain

BaseChain(
    canonical_symbol: Union[
        Symbol, str, BaseContract, Security
    ],
    time: Union[datetime, date],
    data_type: MarketDataType,
    flatten: bool = True,
)
BaseChain(
    canonical_option_symbol: Union[
        Symbol, str, BaseContract, Security
    ],
    time: Union[datetime, date],
    data_type: MarketDataType,
    flatten: bool = True,
)
BaseChain(
    other: BaseChain[
        QuantConnect_Data_Market_BaseChain_T,
        QuantConnect_Data_Market_BaseChain_TContractsCollection,
    ],
)
BaseChain(
    other: BaseChain[
        QuantConnect_Data_Market_BaseChain_T,
        QuantConnect_Data_Market_BaseChain_TContractsCollection,
    ],
    contracts: List[QuantConnect_Data_Market_BaseChain_T],
)
BaseChain(data_type: MarketDataType, flatten: bool)

Bases: Generic[QuantConnect_Data_Market_BaseChain_T, QuantConnect_Data_Market_BaseChain_TContractsCollection, QuantConnect_Data_Market_BaseChain_TSelf, QuantConnect_Data_Market_BaseChain_TUniverse], QuantConnect_Data_Market_BaseChain, IContractFilters[QuantConnect_Data_Market_BaseChain_TSelf], Iterable[QuantConnect_Data_Market_BaseChain_T]

A chain of contracts with the filters of its universe selection, see IContractFilters{TSelf}. Each filter returns a new chain, leaving this one untouched

Signature descriptions:

  • Initializes a new instance of the BaseChain{T, TContractsCollection, TSelf, TUniverse} class

  • Initializes a new instance of the BaseChain{T, TContractsCollection} class

  • Initializes a new instance of the BaseChain{T, TContractsCollection, TSelf, TUniverse} class as a copy of the specified chain

  • Initializes a new instance of the BaseChain{T, TContractsCollection, TSelf, TUniverse} class as a copy of the specified chain containing only the given subset of its contracts

  • Initializes a new default instance of the BaseChain{T, TContractsCollection} class

Parameters:

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

The symbol for this chain

None
time Optional[Union[datetime, date]]

The time of this chain

None
data_type Optional[MarketDataType]

The type of data this chain represents

None
flatten Optional[bool]

Whether to flatten the data frame

True
canonical_option_symbol Optional[Union[Symbol, str, BaseContract, Security]]

The symbol for this chain.

None
other Optional[BaseChain[QuantConnect_Data_Market_BaseChain_T, QuantConnect_Data_Market_BaseChain_TContractsCollection]]

The chain to copy

None
contracts Optional[List[QuantConnect_Data_Market_BaseChain_T]]

The contracts to keep

None

underlying

underlying: BaseData

Gets the most recent trade information for the underlying. This may be a Tick or a TradeBar

ticks

ticks: Ticks

Gets all ticks for every option contract in this chain, keyed by option symbol

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

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.

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
]
get_aux_list() -> Dictionary[Symbol, List[BaseData]]

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

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.

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.

create_chain

create_chain(
    contracts: List[QuantConnect_Data_Market_BaseChain_T],
) -> QuantConnect_Data_Market_BaseChain_TSelf

Creates a copy of this chain with only the given contracts

This Class is protected.

Parameters:

Name Type Description Default
contracts List[QuantConnect_Data_Market_BaseChain_T]

The contracts to keep

required

create_filter_universe

create_filter_universe() -> (
    QuantConnect_Data_Market_BaseChain_TUniverse
)

Creates the filter universe over the contracts of this chain

This Class is protected.

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.

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.

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.

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.

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.

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.

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.