Skip to content

Symbol

QuantConnect.Symbol

Symbol(sid: SecurityIdentifier, value: str)

Bases: Object, IEquatable[QuantConnect_Symbol], IComparable

Represents a unique security identifier. This is made of two components, the unique SID and the Value. The value is the current ticker symbol while the SID is constant over the life of a security

Initializes a new instance of the Symbol class

Parameters:

Name Type Description Default
sid SecurityIdentifier

The security identifier for this symbol

required
value str

The current ticker symbol value

required

EMPTY

EMPTY: Symbol = ...

Represents an unassigned symbol. This is intended to be used as an uninitialized, default value

NONE

NONE: Symbol = ...

Represents no symbol. This is intended to be used when no symbol is explicitly intended

canonical

canonical: Symbol

Get's the canonical representation of this symbol

value

value: str

Gets the current symbol for this ticker

id

Gets the security identifier for this symbol

has_underlying

has_underlying: bool

Gets whether or not this Symbol is a derivative, that is, it has a valid underlying property

underlying

underlying: Symbol

Gets the security underlying symbol, if any

security_type

security_type: SecurityType

Gets the security type of the symbol

cusip

cusip: str

The Committee on Uniform Securities Identification Procedures (CUSIP) number corresponding to this Symbol

composite_figi

composite_figi: str

The composite Financial Instrument Global Identifier (FIGI) corresponding to this Symbol

sedol

sedol: str

The Stock Exchange Daily Official List (SEDOL) security identifier corresponding to this Symbol

isin

isin: str

The International Securities Identification Number (ISIN) corresponding to this Symbol

cik

cik: Optional[int]

The Central Index Key number (CIK) corresponding to this Symbol

__eq__

__eq__(right: Any) -> bool
__eq__(right: Union[Symbol, str, BaseContract]) -> bool
__eq__(right: Union[Symbol, str, BaseContract]) -> bool

Equals operator

Parameters:

Name Type Description Default
right Any | Union[Symbol, str, BaseContract]

The right operand

required

Returns:

Type Description
bool

True if both symbols are equal, otherwise false.

__ne__

__ne__(right: Any) -> bool
__ne__(right: Union[Symbol, str, BaseContract]) -> bool
__ne__(right: Union[Symbol, str, BaseContract]) -> bool

Not equals operator

Parameters:

Name Type Description Default
right Any | Union[Symbol, str, BaseContract]

The right operand

required

Returns:

Type Description
bool

True if both symbols are not equal, otherwise false.

create_base

create_base(
    base_type: Any,
    underlying: Union[Symbol, str, BaseContract],
    market: str = None,
) -> Symbol
create_base(
    base_type: Type,
    underlying: Union[Symbol, str, BaseContract],
    market: str = None,
) -> Symbol

Creates a new Symbol for custom data. This method allows for the creation of a new Base Symbol using the first ticker and the first traded date from the provided underlying Symbol. This avoids the issue for mappable types, where the ticker is remapped supposing the provided ticker value is from today. See SecurityIdentifier's private method GetFirstTickerAndDate. The provided symbol is also set to Symbol.underlying so that it can be accessed using the custom data Symbol. This is useful for associating custom data Symbols to other asset classes so that it is possible to filter using custom data and place trades on the underlying asset based on the filtered custom data.

Parameters:

Name Type Description Default
base_type Any | Type

Type of BaseData instance

required
underlying Union[Symbol, str, BaseContract]

Underlying symbol to set for the Base Symbol

required
market str

Market

None

Returns:

Type Description
Symbol

New non-mapped Base Symbol that contains an Underlying Symbol.

create_canonical_option

create_canonical_option(
    underlying_symbol: Union[Symbol, str, BaseContract],
    market: str = None,
    alias: str = None,
) -> Symbol
create_canonical_option(
    underlying_symbol: Union[Symbol, str, BaseContract],
    target_option: str,
    market: str = None,
    alias: str = None,
) -> Symbol

Simple method to create the canonical option symbol for any given underlying symbol

Parameters:

Name Type Description Default
underlying_symbol Union[Symbol, str, BaseContract]

Underlying of this option

required
market str

Market for this option

None
alias str

An alias to be used for the symbol cache. Required when

None
target_option Optional[str]

The target option ticker. This is useful when the option ticker does not match the underlying, e.g. SPX index and the SPXW weekly option. If null is provided will use underlying

None

Returns:

Type Description
Symbol

New Canonical Option.

create_option

create_option(
    underlying: str,
    market: str,
    style: OptionStyle,
    right: OptionRight,
    strike: float,
    expiry: Union[datetime, date],
    alias: str = None,
    map_symbol: bool = True,
) -> Symbol
create_option(
    underlying_symbol: Union[Symbol, str, BaseContract],
    market: str,
    style: OptionStyle,
    right: OptionRight,
    strike: float,
    expiry: Union[datetime, date],
    alias: str = None,
) -> Symbol
create_option(
    underlying_symbol: Union[Symbol, str, BaseContract],
    target_option: str,
    market: str,
    style: OptionStyle,
    right: OptionRight,
    strike: float,
    expiry: Union[datetime, date],
    alias: str = None,
) -> Symbol
create_option(
    sid: SecurityIdentifier,
    value: str,
    underlying: Union[Symbol, str, BaseContract] = None,
) -> Symbol

Signature descriptions:

  • Provides a convenience method for creating an option Symbol.

  • Provides a convenience method for creating an option Symbol using SecurityIdentifier.

  • Provides a convenience method for creating an option Symbol from its SecurityIdentifier and alias.

Parameters:

Name Type Description Default
underlying Optional[str | Union[Symbol, str, BaseContract]]

The underlying ticker

None
market Optional[str]

The market the underlying resides in

None
style Optional[OptionStyle]

The option style (American, European, ect..)

None
right Optional[OptionRight]

The option right (Put/Call)

None
strike Optional[float]

The option strike price

None
expiry Optional[Union[datetime, date]]

The option expiry date

None
alias Optional[str]

An alias to be used for the symbol cache. Required when

None
map_symbol Optional[bool]

Specifies if symbol should be mapped using map file provider

True
underlying_symbol Optional[Union[Symbol, str, BaseContract]]

The underlying security symbol

None
target_option Optional[str]

The target option ticker. This is useful when the option ticker does not match the underlying, e.g. SPX index and the SPXW weekly option. If null is provided will use underlying

None
sid Optional[SecurityIdentifier]

The option SID

None
value Optional[str]

The alias

None

Returns:

Type Description
Symbol

Depends on the signature used. Case 1: [A new Symbol object for the specified option contract.]; Case 2: [A new Symbol object for the specified option.]

equals

equals(obj: Any) -> bool
equals(other: Union[Symbol, str, BaseContract]) -> bool

Signature descriptions:

  • Determines whether the specified System.Object is equal to the current System.Object.

  • Indicates whether the current object is equal to another object of the same type.

Parameters:

Name Type Description Default
obj Optional[Any]

The object to compare with the current object.

None
other Optional[Union[Symbol, str, BaseContract]]

An object to compare with this object.

None

Returns:

Type Description
bool

Depends on the signature used. Case 1: [true if the specified object is equal to the current object; otherwise, false.]; Case 2: [true if the current object is equal to the other parameter; otherwise, false.]

get_option_type_from_underlying

get_option_type_from_underlying(
    underlying_symbol: Union[Symbol, str, BaseContract],
) -> SecurityType
get_option_type_from_underlying(
    security_type: SecurityType,
) -> SecurityType

Signature descriptions:

  • Determines the SecurityType based on the underlying Symbol's SecurityType

  • Determines the SecurityType based on the underlying Symbol's SecurityType get_underlying_from_option_type(SecurityType)

Parameters:

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

Underlying Symbol of an option

None
security_type Optional[SecurityType]

SecurityType of the underlying Symbol

None

Returns:

Type Description
SecurityType

SecurityType of the option.

__ge__

__ge__(other: Any) -> bool

__gt__

__gt__(other: Any) -> bool

__le__

__le__(other: Any) -> bool

__lt__

__lt__(other: Any) -> bool

compare_to

compare_to(obj: Any) -> int

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

Parameters:

Name Type Description Default
obj Any

An object to compare with this instance.

required

Returns:

Type Description
int

A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance precedes obj in the sort order. Zero This instance occurs in the same position in the sort order as obj. Greater than zero This instance follows obj in the sort order.

contains

contains(value: str) -> bool

Symbol.Contains is a pass-through for Symbol.Value.Contains

create

create(
    ticker: str,
    security_type: SecurityType,
    market: str,
    alias: str = None,
    base_data_type: Type = None,
) -> Symbol

Provides a convenience method for creating a Symbol for most security types. This method currently does not support Commodities

Parameters:

Name Type Description Default
ticker str

The string ticker symbol

required
security_type SecurityType

The security type of the ticker. If security_type == Option, then a canonical symbol is created

required
market str

The market the ticker resides in

required
alias str

An alias to be used for the symbol cache. Required when adding the same security from different markets

None
base_data_type Type

Optional for SecurityType.BASE and used for generating the base data SID

None

Returns:

Type Description
Symbol

A new Symbol object for the specified ticker.

create_future

create_future(
    ticker: str,
    market: str,
    expiry: Union[datetime, date],
    alias: str = None,
) -> Symbol

Provides a convenience method for creating a future Symbol.

Parameters:

Name Type Description Default
ticker str

The ticker

required
market str

The market the future resides in

required
expiry Union[datetime, date]

The future expiry date

required
alias str

An alias to be used for the symbol cache. Required when adding the same security from different markets

None

Returns:

Type Description
Symbol

A new Symbol object for the specified future contract.

ends_with

ends_with(value: str) -> bool

Symbol.EndsWith is a pass-through for Symbol.Value.EndsWith

get_alias

get_alias(
    security_identifier: SecurityIdentifier,
    underlying: Union[Symbol, str, BaseContract] = None,
) -> str

Centralized helper method to resolve alias for a symbol

get_hash_code

get_hash_code() -> int

Serves as a hash function for a particular type.

Returns:

Type Description
int

A hash code for the current System.Object.

get_underlying_from_option_type

get_underlying_from_option_type(
    security_type: SecurityType,
) -> SecurityType

Determines the underlying SecurityType based on the option Symbol's SecurityType get_option_type_from_underlying(SecurityType)

Parameters:

Name Type Description Default
security_type SecurityType

SecurityType of the option Symbol

required

Returns:

Type Description
SecurityType

SecurityType of the underlying.

has_canonical

has_canonical() -> bool

Determines whether the symbol has a canonical representation

has_underlying_symbol

has_underlying_symbol(
    symbol: Union[Symbol, str, BaseContract],
) -> bool

Determines if the specified symbol is an underlying of this symbol instance

Parameters:

Name Type Description Default
symbol Union[Symbol, str, BaseContract]

The underlying to check for

required

Returns:

Type Description
bool

True if the specified symbol is an underlying of this symbol instance.

is_canonical

is_canonical() -> bool

Method returns true, if symbol is a derivative canonical symbol

Returns:

Type Description
bool

true, if symbol is a derivative canonical symbol.

starts_with

starts_with(value: str) -> bool

Symbol.StartsWith is a pass-through for Symbol.Value.StartsWith

to_lower

to_lower() -> str

Symbol.ToLower is a pass-through for Symbol.Value.ToLower

to_string

to_string() -> str

Returns a string that represents the current object.

Returns:

Type Description
str

A string that represents the current object.

to_upper

to_upper() -> str

Symbol.ToUpper is a pass-through for Symbol.Value.ToUpper

update_mapped_symbol

update_mapped_symbol(
    mapped_symbol: str, contract_depth_offset: int = 0
) -> Symbol

Creates new symbol with updated mapped symbol. Symbol Mapping: When symbols change over time (e.g. CHASE-> JPM) need to update the symbol requested. Method returns newly created symbol