This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

vp.finance.crr_price

The CRR value with N steps: u = exp(sigma sqrt(dt)), d = 1/u, the risk-neutral up probability p = (exp((r - q) dt) - d) / (u - d), values rolled back from maturity; an American option takes the larger of continuing and exercising at every node.

Part of the distribution vipyr; it runs from a checkout of the repository. Planned on PyPI as pip install vipyr.

Signature

vp.finance.crr_price(S, K, T, r, q, sigma, N, is_call, american)

Parameters

S : float, required
K : float, required
T : float, required
r : float, required
q : float, required
sigma : float, required
N : int, required
is_call : bool, required
american : bool, required

Returns

A frozen CrrPriceResult. Iterating it gives the fields below in order; it also has params, tests, log and check().

price : float
The option's value on an N-step Cox-Ross-Rubinstein tree.

Raises

TypeError
An argument of the wrong type, or an unknown keyword.
vipyr.VivBuildError
An ImportError: no C compiler, or the program's C does not build.

Examples

import vipyr as vp
r = vp.finance.crr_price(S=50.0, K=50.0, T=5 / 12, r=0.1, q=0.0, sigma=0.4, N=5,
                            is_call=False, american=True)
print(r.price)                            # Hull: 4.49
assert r.check()
4.488458534725913

Each example ran as written when these pages were generated, and the output shown is what it printed.

Checked against

Reference
Hull's printed American put values 4.49, 4.263, 4.272, 4.278 and 4.283 (N = 5 to 500), within half a unit of the last printed digit; the European value at N = 4000 within 2 × 10−3 of Black-Scholes.

Source