option_util package

Submodules

option_util.expirations module

option_util.expirations.future_expirations(from_date: datetime | None = None) Dict[str, datetime][source]

Get a list of future options expiration dates.

option_util.expirations.next_business_day(from_date: datetime | None = None) date[source]

Get the next trading day from the given date.

option_util.expirations.next_expiration(expiration_type: Literal['friday', 'third_friday', 'quarter_end', 'next_bus_day', 'wednesday', 'quarter_third_friday'], from_date: datetime | None = None) date[source]

Get the next expiration date based on the expiration type.

Parameters:
  • expiration_type – When the option will expire. options: ‘friday’, ‘third_friday’, ‘quarterly’, ‘next_bus_day’, ‘wednesday’

  • from_date – The date to make the calculation from.

Returns:

datetime.date

Example:

>>> # Return the next expiration by type.
>>> next_exp_by_type = expirations.next_expiration(
...    expiration_type='friday', from_date=datetime(2024,10,27)
...    )
>>> print(f'Next Expiration by Type: {next_exp_by_type}')
Next Expiration by Type: 2024-11-01
Raises:

NotImplementedError: If the expiration type is not yet implemented. ValueError: If an invalid expiration type is provided.

option_util.expirations.next_friday(from_date: datetime | None = None) date[source]

Get the date of the next Friday from the given date.

option_util.expirations.next_monthly_expiration(from_date: datetime | None = None) date[source]

Get the date of the next monthly options expiration (third Friday of the month).

option_util.expirations.next_quarter_end(from_date: datetime | None = None) date[source]

Get the last Friday of the last month in the current quarter.

option_util.expirations.next_quarter_third_friday(from_date: datetime | None = None) date[source]

Get the third Friday of the last month of the current quarter.

option_util.expirations.parse_contract_symbol(symbol: str) float[source]

Parse the contract symbol to extract the strike price.

Parameters:

symbol (str) – The contract symbol string.

Returns:

The strike price extracted from the symbol.

Return type:

float

option_util.expirations.previous_business_day(date: datetime) date[source]

Uses pandas calendars to get the previous business day.

date can be any day of the week including weekends. US Federal holidays are excluded from the results.

Parameters:

date – The day to start from. YYYY-MM-DD format.

Returns:

datetime

Example:

>>> # Get the previous business day from date
>>> prev_bus_day = expirations.previous_business_day(
>>> date=datetime(2024, 10, 27)) # Sunday
>>> print(prev_bus_day) # Previous bus day is Friday

Next business day: 2024-10-25

Module contents