Quotes Module

Quotes

SimpleQuote

class pyquantlib.SimpleQuote

Bases: Quote

Simple quote for market data.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Constructs an invalid SimpleQuote.

  1. __init__(value: SupportsFloat | SupportsIndex) -> None

Constructs a SimpleQuote with the given value.

isValid() bool

Returns true if the quote holds a valid value.

reset() None

Resets the quote to an invalid state.

setValue(value: SupportsFloat | SupportsIndex) float

Sets the quote value and notifies observers.

value() float

Returns the current value.

spot = ql.SimpleQuote(100.0)
spot.setValue(105.0)
print(spot.value())  # 105.0

DerivedQuote

class pyquantlib.DerivedQuote

Bases: Quote

Quote derived from another quote using a unary function.

__init__(quote: QuoteHandle, function: collections.abc.Callable) None

Creates a derived quote from another quote and a Python function.

CompositeQuote

class pyquantlib.CompositeQuote

Bases: Quote

Quote composed from two quotes using a binary function.

__init__(quote1: QuoteHandle, quote2: QuoteHandle, function: collections.abc.Callable) None

Creates a composite quote from two quotes and a Python function.

QuoteHandle

class pyquantlib.QuoteHandle

Bases: pybind11_object

Handle to Quote objects

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Creates an empty handle.

  1. __init__(ptr: object, registerAsObserver: bool = True) -> None

Creates a handle linked to the given object.

asObservable() Observable

Converts to Observable for observer registration.

Returns the shared_ptr to the current object link.

empty() bool

Returns true if the handle is empty.

get() base.Quote

Returns the underlying shared_ptr. Raises error if empty.

RelinkableQuoteHandle

class pyquantlib.RelinkableQuoteHandle

Bases: QuoteHandle

Relinkable handle to Quote objects

__init__(*args, **kwargs)

Overloaded function.

  1. __init__() -> None

Creates an empty relinkable handle.

  1. __init__(ptr: object, registerAsObserver: bool = True) -> None

Creates a relinkable handle linked to the given object.

linkTo(ptr: object = None, registerAsObserver: bool = True) None

Links the handle to a new object instance. Notifies observers.

spot = ql.SimpleQuote(100.0)
handle = ql.QuoteHandle(spot)

# Relinkable handles can be redirected
relinkable = ql.RelinkableQuoteHandle(spot)
new_spot = ql.SimpleQuote(105.0)
relinkable.linkTo(new_spot)

Observer Pattern

Quotes participate in QuantLib’s observer pattern. When a quote’s value changes, all dependent calculations are automatically invalidated:

spot = ql.SimpleQuote(100.0)
# ... create option using spot handle ...

npv1 = option.NPV()  # computed with spot = 100
spot.setValue(105.0)
npv2 = option.NPV()  # automatically recomputed with spot = 105