Skip to content

Atoms

The atoms package provides the fundamental data structures used throughout the optpricing library, representing core financial concepts like options, stocks, and interest rates.

ExerciseStyle

Bases: Enum

Enumeration for the exercise style of an option.

Option dataclass

Option(
    strike: float,
    maturity: float,
    option_type: OptionType,
    exercise_style: ExerciseStyle = ExerciseStyle.EUROPEAN,
)

Immutable container representing a single vanilla option contract.

Parameters:

Name Type Description Default
strike float

The strike price of the option.

required
maturity float

The time to maturity of the option, expressed in years.

required
option_type OptionType

The type of the option, either CALL or PUT.

required
exercise_style ExerciseStyle

The exercise style of the option, by default ExerciseStyle.EUROPEAN.

EUROPEAN

parity_counterpart

parity_counterpart() -> Option

Create the put-call parity equivalent of this option.

A call is converted to a put, and a put is converted to a call, while keeping all other parameters the same.

Returns:

Type Description
Option

A new Option instance with the opposite type.

Source code in src/optpricing/atoms/option.py
def parity_counterpart(self) -> Option:
    """
    Create the put-call parity equivalent of this option.

    A call is converted to a put, and a put is converted to a call,
    while keeping all other parameters the same.

    Returns
    -------
    Option
        A new Option instance with the opposite type.
    """
    if self.option_type is OptionType.PUT:
        other_type = OptionType.CALL
    else:
        other_type = OptionType.PUT
    return replace(self, option_type=other_type)

OptionType

Bases: Enum

Enumeration for the type of an option (Call or Put).

Rate dataclass

Rate(rate: float | Callable[[float], float])

Represents the risk-free interest rate structure.

This can be a single constant rate or a full term structure.

Parameters:

Name Type Description Default
rate float | Callable[[float], float]
  • If a float, represents a constant risk-free rate for all maturities.
  • If a callable, it should be a function that takes a maturity (t) and returns the continuously compounded zero rate for that maturity. Example: lambda t: 0.02 + 0.01 * t
required

get_rate

get_rate(t: float = 0) -> float

Get the interest rate for a specific maturity.

Parameters:

Name Type Description Default
t float

The time (maturity) for which to get the rate. This is only used if the rate is a term structure (callable). Default is 0.

0

Returns:

Type Description
float

The continuously compounded risk-free rate.

Source code in src/optpricing/atoms/rate.py
def get_rate(self, t: float = 0) -> float:
    """
    Get the interest rate for a specific maturity.

    Parameters
    ----------
    t : float, optional
        The time (maturity) for which to get the rate. This is only
        used if the rate is a term structure (callable). Default is 0.

    Returns
    -------
    float
        The continuously compounded risk-free rate.
    """
    if callable(self.rate):
        return self.rate(t)
    return self.rate

Stock dataclass

Stock(
    spot: float,
    volatility: float | None = None,
    dividend: float = 0.0,
    discrete_dividends: list[float] | None = None,
    ex_div_times: list[float] | None = None,
)

Immutable container representing the underlying asset's properties.

Parameters:

Name Type Description Default
spot float

The current price of the underlying asset.

required
volatility float | None

The constant (implied or historical) volatility of the asset's returns. Default is None.

None
dividend float

The continuously compounded dividend yield, by default 0.0.

0.0
discrete_dividends list[float] | None

A list of discrete dividend amounts. Default is None.

None
ex_div_times list[float] | None

A list of times (in years) for the discrete dividend payments. Must correspond to discrete_dividends. Default is None.

None

ZeroCouponBond dataclass

ZeroCouponBond(maturity: float, face_value: float = 1.0)

Represents a zero-coupon bond contract.

Parameters:

Name Type Description Default
maturity float

The time to maturity of the bond, in years.

required
face_value float

The face value of the bond, paid at maturity. Defaults to 1.0.

1.0