quantdata.dysanos.grid.rndysanos.direct_arbitrage#

State-conditional direct-arbitrage policies and certification.

The policy sees only the current state z. A softmax chooses a long/short direction while a separate sigmoid gate chooses gross exposure. Thus long and short positions are represented separately and

sum(long + short) <= 1.

For realized return dH and effective one-way cost c, net return is

(long - short) @ dH - (long + short) @ c.

Population almost-sure nonnegativity cannot be proved from Monte Carlo data. The certification helpers therefore report every validation loss and use paths, rather than path-time observations, as independent clusters.

class quantdata.dysanos.grid.rndysanos.direct_arbitrage.DirectArbitrageConfig(*, label, state_features, instruments, group='', user_version='0.1', epsilon=0.01, delta=0.01, numerical_tolerance=0.0001, smooth_temperature=0.0025, tail_fraction=0.01, downside_weight=10.0, tail_weight=100.0, overlap_weight=1.0, mean_reward_weight=0.1, discovery_fraction=0.05, constraint_ramp_fraction=0.45, initial_trade_fraction=0.01, mask_arbitrage_candidates=False, objective='simplex-soft-hit', cap_weight=1.0, seed=70771, network_config=FeedForwardConfig(activation='LeakyReLU', num_depth=2, num_width=100, use_bias=True))[source]#

Bases: object

Logical policy, economic threshold, and constrained-loss configuration.

group: str = ''#
user_version: str = '0.1'#
epsilon: float = 0.01#
delta: float = 0.01#
numerical_tolerance: float = 0.0001#
smooth_temperature: float = 0.0025#
tail_fraction: float = 0.01#
downside_weight: float = 10.0#
tail_weight: float = 100.0#
overlap_weight: float = 1.0#
mean_reward_weight: float = 0.1#
discovery_fraction: float = 0.05#
constraint_ramp_fraction: float = 0.45#
initial_trade_fraction: float = 0.01#
mask_arbitrage_candidates: bool = False#
objective: str = 'simplex-soft-hit'#
cap_weight: float = 1.0#
seed: int = 70771#
network_config: FeedForwardConfig = FeedForwardConfig(activation='LeakyReLU', num_depth=2, num_width=100, use_bias=True)#
property filename: str#
class quantdata.dysanos.grid.rndysanos.direct_arbitrage.DirectArbitrageTrainConfig(*, batch_size=1024, valuation_batch_size=4096, lr=0.001, final_lr=1e-06, weight_decay=0.0001, compile=True, value_update=10000, checkpoint_update=10000, checkpoint_root='~/.cache/rndysanos/direct-arbitrage')[source]#

Bases: object

Operational configuration for direct-policy optimization.

batch_size: int = 1024#
valuation_batch_size: int = 4096#
lr: float = 0.001#
final_lr: float = 1e-06#
weight_decay: float = 0.0001#
compile: bool = True#
value_update: int = 10000#
checkpoint_update: int = 10000#
checkpoint_root: str = '~/.cache/rndysanos/direct-arbitrage'#
class quantdata.dysanos.grid.rndysanos.direct_arbitrage.DirectArbitrageTrainingResult(policy, training, validation, tracker, checkpoint_path, restarted)[source]#

Bases: object

Trained policy, complete valuations, and restart metadata.

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

Bases: BaseModel

State-only long/short direction and independent scalar exposure gate.

forward(z, excluded_directions=None)[source]#

Forward method.

Parameters:
  • data (dict) – Input data dictionary containing tensors for the model. The expected keys and tensor shapes depend on the specific model implementation.

  • training (bool, default False) – Whether the model is in training mode.

  • return_what (BaseModel.ReturnWhat, default ReturnWhat.LOSS_WEIGHT) – Specifies what the model should return. Options are: - ReturnWhat.LOSS_WEIGHT: return float loss (with gradient) and float weight (without gradient) for training. - ReturnWhat.VALUATION: return loss, weight and a dictionary of additional float metrics. - ReturnWhat.PATHWISE: return pathwise metrics as dictionary.

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

Bases: BaseModel

V2.0 policy with one unbounded signed output and radial L1 clipping.

forward(z, excluded_directions=None)[source]#

Return the feasible signed action and feasible raw L1 norm.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.direct_arbitrage_loss(*, long, short, dH, cost, config, penalty_scale=1.0)[source]#

Reward threshold hits while heavily penalizing mean and tail downside.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.effective_cost(data, *, bar_c, cost_prop, conditional_variance_model, n_cost, batch_size)[source]#

Materialize max(c_cond, bar_c, c_prop) without retaining gradients.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.net_return(*, long, short, dH, cost)[source]#

Return net P&L for separate long and short allocations.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.state_normalization(data, *, batch_size)[source]#

Return training-only state mean and population standard deviation.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.train_direct_policy(training, validation, *, config, train_config, epochs, env, restart=False)[source]#

Train a direct policy and atomically checkpoint resumable optimizer state.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.unconditional_cost(data, *, cost_uncond, batch_size)[source]#

Return the full-training population standard error per instrument.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.v2_arbitrage_loss(*, action, raw_l1, dH, cost, config, penalty_scale=1.0)[source]#

V2.0 mean/downside/CVaR loss with radial-output conditioning penalty.

quantdata.dysanos.grid.rndysanos.direct_arbitrage.valuate_policy(policy, data, *, batch_size, split)[source]#

Value a policy and conservatively certify it using independent paths.