filter_option_chain
For a given stock symbol, returns the option chain filtered by expiration date and strike price.
Syntax
Fields
Description
symbol(str)
Symbol of stock
type(str)
Type of option, either "call" or "put"
lower_exp(str | datetime.datetime)
Minimum expiration date of the option, inclusive. This can be a string in the format "YYYY-MM-DD" or a datetime object
upper_exp(str | datetime.datetime)
Maximum expiration date of the option, inclusive. This can be a string in the format "YYYY-MM-DD" or a datetime object
lower_strike(float)
The minimum strike price of the option, inclusive
upper_strike(float)
The maximum strike price of the option, inclusive
def filter_option_chain(
self: Self@Algorithm,
symbol: str,
type: str,
lower_exp: Union[str, datetime.datetime],
upper_exp: Union[str, datetime.datetime],
lower_strike: float,
upper_strike: float
)
The datetime.datetime
object used to specify the expiration date should be timezone-aware. If a timezone-naive object is passed, it will be assumed to be in the timezone of the computer running the algorithm.
In practice, you should ideally use timezone-aware objects set to the timezone of the exchange where the options are traded. For details on Python datetime objects, see the offcial Python documentation.
Returns
Returns a DataFrame containing the filtered option chain. The DataFrame has the following format:
symbol
type
strike
str
str
str
float
The index is a string representing the OCC symbol of the option. The columns are as follows:
symbol
: The symbol of the stock the option is based on.type
: The type of the option, either “call” or “put”.strike
: The strike price of the option.