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.cn_american_put

The American put by Crank-Nicolson on M space intervals over [0, Smax] and Nt time steps, of which the first implicit are fully implicit (two half-size steps each).

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

Signature

vp.finance.cn_american_put(S0, K, T, r, q, sigma, Smax, M, Nt, implicit)

Parameters

S0 : float, required
K : float, required
T : float, required
r : float, required
q : float, required
sigma : float, required
Smax : float, required
M : int, required
Nt : int, required
implicit : int, required

Returns

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

price : float
The American put's value at S0.

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.cn_american_put(S0=50.0, K=50.0, T=5 / 12, r=0.1, q=0.0, sigma=0.4,
                                  Smax=200.0, M=400, Nt=200, implicit=4)
print(r.price)                            # the tree gives 4.48669
assert r.check()
4.2827742739876875

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

Checked against

Reference
The CRR tree, the mean of N = 10000 and 10001 (4.48669): error 8.8 × 10−5, tolerance 2e-4.

Source