Payoffs¶
dummypy.payoffs
¶
Payoff functions for vanilla European option contracts.
call_payoff(spot, strike)
¶
Return the expiry payoff of a European call option.
The return type follows :func:numpy.maximum, which this delegates to: a
scalar spot yields a :class:numpy.float64, an array-like yields an
array. The two are deliberately not normalised to an array — doing so
would make call_payoff(120.0, 100.0) return array([20.]) and
surprise every caller who passed a single number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spot
|
ArrayLike
|
Underlying spot price(s) at expiry. Scalars and array-likes are both accepted. |
required |
strike
|
float
|
Strike price of the option. Must be a finite, non-negative real number. |
required |
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
Element-wise payoff |
float64 | NDArray[float64]
|
for scalar |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
A scalar spot gives a scalar payoff:
Out of the money the payoff floors at zero rather than going negative:
An array-like spot is evaluated element-wise:
An unusable strike fails fast:
>>> call_payoff(120.0, strike=-1.0)
Traceback (most recent call last):
...
ValueError: strike must be non-negative, got -1.0
Source code in src/dummypy/payoffs.py
put_payoff(spot, strike)
¶
Return the expiry payoff of a European put option.
Mirrors :func:call_payoff, including its return-type convention: scalar in,
scalar out; array-like in, array out.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spot
|
ArrayLike
|
Underlying spot price(s) at expiry. Scalars and array-likes are both accepted. |
required |
strike
|
float
|
Strike price of the option. Must be a finite, non-negative real number. |
required |
Returns:
| Type | Description |
|---|---|
float64 | NDArray[float64]
|
Element-wise payoff |
float64 | NDArray[float64]
|
for scalar |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
A scalar spot gives a scalar payoff:
Out of the money the payoff floors at zero:
An array-like spot is evaluated element-wise:
A non-finite strike is rejected alongside a negative one:
>>> put_payoff(80.0, strike=float("nan"))
Traceback (most recent call last):
...
ValueError: strike must be a finite real number, got nan