Pricing
stochPathSim.pricing
Pricing: payoffs, Monte Carlo, least-squares Monte Carlo and binomial trees.
MCResult
dataclass
Monte Carlo price estimate.
Attributes:
| Name | Type | Description |
|---|---|---|
price |
float
|
Estimated present value. |
stderr |
float
|
Standard error of the estimate. |
n_paths |
int
|
Number of simulated paths. |
samples |
(ndarray, optional)
|
The independent discounted samples the estimate averages (pair averages under antithetic sampling, control-variate adjusted if one was used). |
conf_int
conf_int(level=0.95)
Two-sided normal confidence interval for the price.
AsianArithmetic
Bases: _Asian
Fixed-strike Asian option on the arithmetic average of the fixings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
float
|
Strike. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
fixing_times
|
array_like
|
Averaging times (must be grid times). By default every grid time from
|
None
|
AsianGeometric
Bases: _Asian
Fixed-strike Asian option on the geometric average of the fixings (see :class:AsianArithmetic).
Barrier
Bases: Payoff
Single-barrier knock-in or knock-out option, monitored at every grid time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
float
|
Strike. |
required |
barrier
|
float
|
Barrier level. |
required |
kind
|
('up-and-out', 'up-and-in', 'down-and-out', 'down-and-in')
|
|
"up-and-out"
|
option_type
|
('call', 'put')
|
|
"call"
|
rebate
|
float
|
Paid at maturity if the option is knocked out, or never knocked in. |
0.0
|
sigma
|
float
|
Volatility for the Broadie-Glasserman-Kou continuity correction. When
given, the barrier is moved towards the spot by the factor
|
None
|
effective_barrier
effective_barrier(times)
Barrier used on the grid, after the optional continuity correction.
knocked
knocked(paths, times)
Boolean per path: whether the barrier was touched on the grid.
Basket
Bases: Payoff
Option on a weighted sum of terminal values of several state variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array_like
|
One weight per state. |
required |
K
|
float
|
Strike. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
states
|
sequence of str
|
State names, in the order of |
None
|
Digital
European
EuropeanCall
EuropeanPut
LookbackFixed
Bases: Payoff
Fixed-strike lookback: max(max S - K, 0) (call) or max(K - min S, 0) (put), over the grid.
LookbackFloating
Payoff
Base class for path-dependent payoffs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
Name of the state variable to read; defaults to the primary state. |
None
|
__call__
__call__(result, times=None)
Undiscounted payoff per path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
SimulationResult or ndarray
|
Simulated paths. A raw array must have shape |
required |
times
|
array_like
|
Grid times for a raw array (needed by time-aware payoffs). |
None
|
evaluate
evaluate(paths, times)
Payoff per path from a (n_paths, n_times) array.
Spread
longstaff_schwartz
longstaff_schwartz(process, payoff_fn, T, *, r, n_steps=50, n_paths=100000, basis='laguerre', degree=3, seed=None, antithetic=False, state=None, grid=None)
Price an American (Bermudan) option with the Longstaff-Schwartz algorithm.
Exercise is allowed at every grid time after t = 0; the continuation value
is regressed on in-the-money paths only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
StochasticProcess
|
Risk-neutral process for the underlying. |
required |
payoff_fn
|
callable
|
Intrinsic value as a function of the underlying, e.g.
|
required |
T
|
float
|
Maturity in years. |
required |
r
|
float
|
Continuously compounded discount rate. |
required |
n_steps
|
int
|
Number of exercise dates (equal steps). |
50
|
n_paths
|
int
|
Number of paths. |
100000
|
basis
|
('laguerre', 'poly')
|
Regression basis, evaluated on the spot scaled by its initial value. |
"laguerre"
|
degree
|
int
|
Degree of the regression basis. |
3
|
seed
|
As in :meth: |
None
|
|
antithetic
|
As in :meth: |
None
|
|
grid
|
As in :meth: |
None
|
|
state
|
str
|
State variable to exercise on (default: primary state). |
None
|
discount_factors
discount_factors(result, discount, T)
Discount factor(s) to maturity T.
discount may be a continuously compounded rate, a :class:ZeroCurve, or
None; with None the pathwise "discount" state of the result is used
when the process provides one, otherwise payoffs are left undiscounted.
price_mc
price_mc(process, payoff, T, *, discount=None, n_steps=252, n_paths=100000, seed=None, antithetic=False, control_variate=None, grid=None, keep_samples=False)
Price a payoff by Monte Carlo simulation of a process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
StochasticProcess
|
Process to simulate (e.g. a risk-neutral :class: |
required |
payoff
|
callable
|
Maps a :class: |
required |
T
|
float
|
Maturity in years. |
required |
discount
|
(float, ZeroCurve or None)
|
Discounting: a continuously compounded rate, a curve, or |
None
|
n_steps
|
int
|
Time steps and paths. |
252
|
n_paths
|
int
|
Time steps and paths. |
252
|
seed
|
int
|
Seed for reproducible results. |
None
|
antithetic
|
bool
|
Antithetic variates; the standard error is computed on pair averages. |
False
|
control_variate
|
tuple(payoff, exact_value)
|
A second payoff with known present value. Its discounted samples are used as a linear control with the variance-minimising coefficient. |
None
|
grid
|
TimeGrid
|
Custom simulation grid (overrides |
None
|
keep_samples
|
bool
|
Store the samples in the result. |
False
|
crr_price
crr_price(S, K, T, r, sigma, option_type='call', *, american=False, q=0.0, n_steps=500)
Cox-Ross-Rubinstein binomial price of a vanilla option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
K
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
T
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
r
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
sigma
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
american
|
bool
|
Allow early exercise at every node. |
False
|
q
|
float
|
Continuous dividend yield. |
0.0
|
n_steps
|
int
|
Number of tree steps. |
500
|
american
American and Bermudan options by least-squares Monte Carlo.
longstaff_schwartz
longstaff_schwartz(process, payoff_fn, T, *, r, n_steps=50, n_paths=100000, basis='laguerre', degree=3, seed=None, antithetic=False, state=None, grid=None)
Price an American (Bermudan) option with the Longstaff-Schwartz algorithm.
Exercise is allowed at every grid time after t = 0; the continuation value
is regressed on in-the-money paths only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
StochasticProcess
|
Risk-neutral process for the underlying. |
required |
payoff_fn
|
callable
|
Intrinsic value as a function of the underlying, e.g.
|
required |
T
|
float
|
Maturity in years. |
required |
r
|
float
|
Continuously compounded discount rate. |
required |
n_steps
|
int
|
Number of exercise dates (equal steps). |
50
|
n_paths
|
int
|
Number of paths. |
100000
|
basis
|
('laguerre', 'poly')
|
Regression basis, evaluated on the spot scaled by its initial value. |
"laguerre"
|
degree
|
int
|
Degree of the regression basis. |
3
|
seed
|
As in :meth: |
None
|
|
antithetic
|
As in :meth: |
None
|
|
grid
|
As in :meth: |
None
|
|
state
|
str
|
State variable to exercise on (default: primary state). |
None
|
montecarlo
Monte Carlo pricing of path-dependent payoffs.
MCResult
dataclass
Monte Carlo price estimate.
Attributes:
| Name | Type | Description |
|---|---|---|
price |
float
|
Estimated present value. |
stderr |
float
|
Standard error of the estimate. |
n_paths |
int
|
Number of simulated paths. |
samples |
(ndarray, optional)
|
The independent discounted samples the estimate averages (pair averages under antithetic sampling, control-variate adjusted if one was used). |
conf_int
conf_int(level=0.95)
Two-sided normal confidence interval for the price.
discount_factors
discount_factors(result, discount, T)
Discount factor(s) to maturity T.
discount may be a continuously compounded rate, a :class:ZeroCurve, or
None; with None the pathwise "discount" state of the result is used
when the process provides one, otherwise payoffs are left undiscounted.
price_mc
price_mc(process, payoff, T, *, discount=None, n_steps=252, n_paths=100000, seed=None, antithetic=False, control_variate=None, grid=None, keep_samples=False)
Price a payoff by Monte Carlo simulation of a process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process
|
StochasticProcess
|
Process to simulate (e.g. a risk-neutral :class: |
required |
payoff
|
callable
|
Maps a :class: |
required |
T
|
float
|
Maturity in years. |
required |
discount
|
(float, ZeroCurve or None)
|
Discounting: a continuously compounded rate, a curve, or |
None
|
n_steps
|
int
|
Time steps and paths. |
252
|
n_paths
|
int
|
Time steps and paths. |
252
|
seed
|
int
|
Seed for reproducible results. |
None
|
antithetic
|
bool
|
Antithetic variates; the standard error is computed on pair averages. |
False
|
control_variate
|
tuple(payoff, exact_value)
|
A second payoff with known present value. Its discounted samples are used as a linear control with the variance-minimising coefficient. |
None
|
grid
|
TimeGrid
|
Custom simulation grid (overrides |
None
|
keep_samples
|
bool
|
Store the samples in the result. |
False
|
payoffs
Payoffs evaluated on simulated paths.
Every payoff maps simulated paths to one undiscounted payoff per path at
maturity. Call a payoff with a :class:~stochPathSim.core.SimulationResult,
or with a raw (n_paths, n_times) array plus the matching times.
Payoff
Base class for path-dependent payoffs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
str
|
Name of the state variable to read; defaults to the primary state. |
None
|
__call__
__call__(result, times=None)
Undiscounted payoff per path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
SimulationResult or ndarray
|
Simulated paths. A raw array must have shape |
required |
times
|
array_like
|
Grid times for a raw array (needed by time-aware payoffs). |
None
|
evaluate
evaluate(paths, times)
Payoff per path from a (n_paths, n_times) array.
European
EuropeanCall
EuropeanPut
Digital
AsianArithmetic
Bases: _Asian
Fixed-strike Asian option on the arithmetic average of the fixings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
float
|
Strike. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
fixing_times
|
array_like
|
Averaging times (must be grid times). By default every grid time from
|
None
|
AsianGeometric
Bases: _Asian
Fixed-strike Asian option on the geometric average of the fixings (see :class:AsianArithmetic).
Barrier
Bases: Payoff
Single-barrier knock-in or knock-out option, monitored at every grid time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
K
|
float
|
Strike. |
required |
barrier
|
float
|
Barrier level. |
required |
kind
|
('up-and-out', 'up-and-in', 'down-and-out', 'down-and-in')
|
|
"up-and-out"
|
option_type
|
('call', 'put')
|
|
"call"
|
rebate
|
float
|
Paid at maturity if the option is knocked out, or never knocked in. |
0.0
|
sigma
|
float
|
Volatility for the Broadie-Glasserman-Kou continuity correction. When
given, the barrier is moved towards the spot by the factor
|
None
|
effective_barrier
effective_barrier(times)
Barrier used on the grid, after the optional continuity correction.
knocked
knocked(paths, times)
Boolean per path: whether the barrier was touched on the grid.
LookbackFixed
Bases: Payoff
Fixed-strike lookback: max(max S - K, 0) (call) or max(K - min S, 0) (put), over the grid.
LookbackFloating
Basket
Bases: Payoff
Option on a weighted sum of terminal values of several state variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
array_like
|
One weight per state. |
required |
K
|
float
|
Strike. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
states
|
sequence of str
|
State names, in the order of |
None
|
Spread
trees
Binomial trees for European and American options.
crr_price
crr_price(S, K, T, r, sigma, option_type='call', *, american=False, q=0.0, n_steps=500)
Cox-Ross-Rubinstein binomial price of a vanilla option.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
S
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
K
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
T
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
r
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
sigma
|
float
|
Spot, strike, maturity (years), continuously compounded rate and volatility. |
required |
option_type
|
('call', 'put')
|
|
"call"
|
american
|
bool
|
Allow early exercise at every node. |
False
|
q
|
float
|
Continuous dividend yield. |
0.0
|
n_steps
|
int
|
Number of tree steps. |
500
|