pal.stochastic_scalar module

Stochastic scalar variables for Monte Carlo simulation.

Provides the StochasticScalar class for representing and manipulating scalar-valued stochastic variables in actuarial and risk modeling applications. Supports arithmetic operations, statistical functions, and numpy integration.

class pal.stochastic_scalar.StochasticScalar(values)[source]

Bases: ProteusStochasticVariable

A class to represent a single scalar variable in a simulation.

coupled_variable_group: CouplingGroup
__init__(values)[source]

Initialize a stochastic scalar.

Parameters:

values (TypeAliasType) – An array of values that describe the distribution for the scalar variable.

values: ndarray[tuple[Any, ...], dtype[number[Any]]]
n_sims: int = None

The number of simulations in the variable.

property ranks: StochasticScalar

Return the ranks of the variable.

tolist()[source]

Convert the values to a Python list.

Return type:

list[Union[float, int, number]]

mean()[source]

Return the mean of the variable across the simulation dimension.

Return type:

float

sum()[source]

Return the sum of the variable across the simulation dimension.

Return type:

float

all()

Check if all values in the variable are True (non-zero).

Return type:

bool

Returns:

True if all values are non-zero, False otherwise.

any()

Check if any value in the variable is True (non-zero).

Return type:

bool

Returns:

True if any value is non-zero, False otherwise.

astype(dtype)

Convert the underlying values to a specified dtype.

Parameters:

dtype (dtype[Any] | type[Any]) – The data type to convert to.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

Returns:

A new numpy array with the specified dtype.

std()[source]

Return the standard deviation across the simulation dimension.

Return type:

float

percentile(p)[source]

Return the percentile of the variable across the simulation dimension.

Parameters:

p (Union[float, int, number, list[Union[float, int, number]]]) – The percentile level (between 0 and 100).

Return type:

Union[float, int, number, list[Union[float, int, number]]]

Returns:

The percentile value.

tvar(p)[source]

Calculate the Tail Value at Risk (TVaR) at a given percentile.

Parameters:

p (Union[float, int, number, list[Union[float, int, number]]]) – The percentile level (between 0 and 100) to calculate TVaR.

Return type:

Union[float, int, number, list[Union[float, int, number]]]

Returns:

The TVaR value as a float.

upsample(n_sims)[source]

Increase the number of simulations in the variable.

Return type:

Self

show_histogram(title=None)[source]

Show a histogram of the variable.

Parameters:

title (str | None) – Title of the histogram plot. Defaults to None.

Return type:

None

show_cdf(title=None)[source]

Show a plot of the cumulative distribution function (cdf) of the variable.

Parameters:

title (str | None) – Title of the cdf plot. Defaults to None.

Return type:

None