quantdata.dysanos.grid.rndysanos.conditional_tail#

Conditional extreme-quantile and lower-CVaR estimation.

For a signed instrument return Y and lower-tail probability alpha, the model estimates

Q_alpha(Y | z) = inf {q: P[Y <= q | z] >= alpha}.

Both Y=dC (long) and Y=-dC (short) are fitted explicitly. The associated lower-CVaR functional is represented by the Rockafellar–Uryasev score

q - relu(q - Y) / alpha.

At the population optimum its conditional expectation is the lower expected shortfall. A finite empirical distribution has no resolution below one observation. Requested levels below 1 / training_paths are consequently reported but tied to the effective empirical level 1 / training_paths.

class quantdata.dysanos.grid.rndysanos.conditional_tail.ConditionalTailConfig(*, label, state_features, instruments, training_paths, group='', user_version='1.0', seed=83771, tail_path_counts=(0.1, 1.0, 2.0, 10.0), network_config=FeedForwardConfig(activation='LeakyReLU', num_depth=2, num_width=200, use_bias=True))[source]#

Bases: object

Logical geometry and tail levels for the conditional quantile model.

tail_path_counts specifies tail masses in units of independent paths. For example, with 50,000 training paths, 10 means a lower-tail probability of 10 / 50_000. Values below one path are retained as requested metadata but use one path as their effective empirical level.

group: str = ''#
user_version: str = '1.0'#
seed: int = 83771#
tail_path_counts: tuple[float, ...] = (0.1, 1.0, 2.0, 10.0)#
network_config: FeedForwardConfig = FeedForwardConfig(activation='LeakyReLU', num_depth=2, num_width=200, use_bias=True)#
property filename: str#
property requested_tail_probabilities: tuple[float, ...]#
property effective_tail_path_counts: tuple[float, ...]#
property effective_tail_probabilities: tuple[float, ...]#
property unique_effective_tail_probabilities: tuple[float, ...]#
property requested_to_unique_level: tuple[int, ...]#
level_metadata()[source]#

Return requested and effective probability conventions.

class quantdata.dysanos.grid.rndysanos.conditional_tail.ConditionalTailQuantileModel(env, *, config, state_mean, state_scale)[source]#

Bases: BaseModel

State-only monotone lower quantiles for long and short returns.

unique_quantiles(z)[source]#

Return monotone quantiles at empirically distinct tail levels.

forward(z)[source]#

Return requested levels, tying levels below one empirical path.

loss(z, returns)[source]#

Return joint normalized pinball loss at unique effective levels.

training_loss(z, returns)[source]#

Compiled training kernel after data preparation established invariants.

cvar_scores(z, returns)[source]#

Return requested lower-CVaR scores using effective finite-sample levels.

quantdata.dysanos.grid.rndysanos.conditional_tail.empirical_lower_cvar(values, *, tail_probability, dim=0)[source]#

Return exact lower expected shortfall of an empirical distribution.

Fractional probability mass at the boundary order statistic is included. Therefore every level at or below 1 / observations is exactly the sample minimum; a fractional observation cannot reveal a lower value.

quantdata.dysanos.grid.rndysanos.conditional_tail.lower_cvar_score(*, quantiles, returns, tail_probabilities)[source]#

Return the lower-CVaR variational score per observation and output.

Conditional expectation of this score is maximized by a lower quantile; at that optimum it equals lower expected shortfall.

quantdata.dysanos.grid.rndysanos.conditional_tail.lower_quantile_pinball(*, quantiles, returns, tail_probabilities, normalize_levels=True)[source]#

Return normalized pinball loss and its direction/level/instrument means.

Parameters:
  • quantiles (Tensor) – Shape (..., 2, L, J) with long/short as the direction axis.

  • returns (Tensor) – Shape (..., J). Long and short targets are constructed internally.

  • tail_probabilities (Tensor) – One-dimensional tensor of the L effective lower-tail levels.

  • normalize_levels (bool) – Divide each level by its tail probability. This does not change any population minimizer, but prevents the least-extreme level from mechanically dominating all rarer levels in a joint model.

quantdata.dysanos.grid.rndysanos.conditional_tail.moment_signal_statistics(drift, second_moment, *, g=3.0)[source]#

Measure sampled states satisfying abs(mu) > g * sigma.

The variance is the population conditional variance max(E[Y**2|z] - E[Y|z]**2, 0). Zero predicted variance is reported separately because an infinite signal ratio can indicate inconsistent moment-network outputs rather than an economic opportunity.

quantdata.dysanos.grid.rndysanos.conditional_tail.signed_returns(returns)[source]#

Return explicit long dC and short -dC outcomes.