API

This page summarizes the public API exposed by the package.

Top-level functions

The package exports the following functions at the top level:

quantplus.crr_price(S0, K, r, sigma, T, N, q=0.0, is_call=True, american=False, S_upper=None, S_lower=None, every_step=False)

Price a European or American option with the CRR binomial tree.

Thin, statically-typed wrapper around the C++ core – the actual tree construction and backward induction happen entirely in C++.

S_lower and S_upper are inclusive stock-price thresholds. By default, they filter terminal nodes only; with every_step=True, nodes outside the band are also pruned at intermediate steps. At a node with only one surviving child, that child receives the remaining probability. Raises ValueError when no terminal node is reachable from the root.

quantplus.black_scholes_price(S0, K, r, sigma, T, q=0.0, is_call=True)

Closed-form Black-Scholes-Merton price (the CRR tree’s N -> infinity limit).

quantplus.crr_tree(S0, K, r, sigma, T, N, q=0.0, is_call=True, american=False)

Like crr_price, but also returns the terminal stock prices and option payoffs as Python lists, e.g. for plotting or inspection.

Returns:
(root_price, terminal_stock_prices, terminal_option_values)
quantplus.plot_crr_tree(S0, K, r, sigma, T, N, q=0.0, is_call=True, american=True, S_upper=None, S_lower=None, every_step=False, show=True)[source]

Show an interactive CRR tree with draggable stock-price thresholds.

Nodes that cannot reach a terminal stock price inside [S_lower, S_upper] are greyed out. Drag either horizontal threshold to update the bounded option price. matplotlib is needed only when this function is called.

Returns the (figure, axes) pair. Set show=False to build the plot without entering Matplotlib’s GUI event loop.

CRR threshold parameters

crr_price accepts two optional inclusive stock-price bounds:

  • S_lower: lowest stock price to retain; None leaves the lower side unbounded.

  • S_upper: highest stock price to retain; None leaves the upper side unbounded.

  • every_step: when false (default), bounds apply to terminal nodes and earlier

    nodes are retained if they can reach a terminal node in range. When true, a node must also be inside the band at every step.

At a surviving node with only one surviving child, that child receives all of the remaining transition probability. Reversed bounds and bands with no surviving terminal path raise ValueError.

The interactive plot is opened with plot_crr_tree. It provides draggable threshold lines and a checkbox for switching every_step while displaying the bounded price and the corresponding unbounded price. matplotlib is imported only when the plotting function is called.

Module overview

The public package is intentionally lightweight and exposes only the functions that users are expected to call directly. The numerical implementation itself is kept in the compiled extension and C++ source files.

You can inspect the runtime package directly in Python:

import quantplus as qp

print(qp.__all__)
print(qp.__version__)

This helps developers confirm which functions are part of the supported public surface.

Other useful considerations

  • crr_price is the main pricing function for binomial-tree valuation.

  • black_scholes_price is the analytic benchmark for comparison.

  • crr_tree is useful when you want the tree terminal nodes or payoffs.

  • plot_crr_tree displays an interactive tree and recalculates a bounded price

    as its thresholds move.

The package may evolve over time, but the public interface remains intentionally stable and easy to inspect.