Module normal
Expand description
2D grid-search trade optimizer for normal-distribution markets.
Maximises net expected value (EV − collateral) under the trader’s
belief, subject to collateral ≤ budget. Both EV and cost are
reported in chain units — i.e. λ-scaled with λ = k / ‖p‖₂,
matching helpers.cairo:50-176 (scaled_verify_minimum_with_lambda).
§λ-scaling (v0.1.3)
Pre-v0.1.3 the inner grid loop mixed units: the EV was λ-scaled
(Gaussian-product integral × λ_g) but the cost from
normal_collateral was the unscaled −d_min. Two bugs surfaced
by Reviewer B’s audit (docs/REVIEW_ITEM3_DRIVER_B.md §6):
- Budget filter mismatch:
coll > input.budgetcompared an unscaled cost against the user’s real-XP budget. With λ ≈ 200×–266× at typical(k, σ), the filter let trades pass that were 200× over budget at the chain charge. - Mixed-units candidate selection:
best_net = ev − collranked candidates on incompatible units, so the “best” pick was wrong.
v0.1.3 routes the inner cost through the same λ-scaling
optimize_quote_offline applies (crates/deadeye-sdk/src/normal.rs):
chain_cost = max(0, λ_f · f(x*) − λ_g · g(x*)) evaluated at the
audited stationary point from normal_collateral. Both the budget
filter and the candidate selector run on chain_cost, restoring
unit consistency with expected_value.
Structs§
- Normal
Optimization Input - Inputs to
optimize_normal_trade. - Normal
Optimization Result - Output of
optimize_normal_trade. - Optimizer
Constraints - Tunable bounds on the optimizer’s policy region.
Functions§
- optimize_
normal_ trade - Picks the highest-net-EV trade in the policy region.