Risk and policy
Three modules collaborate to keep betting strategies within acceptable
bounds: Whale.Risk quantifies danger, Whale.Policy declares rules, and
Whale.Guards enforces hard limits at the execution boundary.
Whale.Risk
Section titled “Whale.Risk”Risk assessment functions that operate on typed inputs from Whale.Types.
import Whale.Risk exposing (expected_loss, variance_of_return, ruin_probability)
let el = expected_loss fraction odds win_problet var = variance_of_return fraction odds win_problet ruin = ruin_probability fraction odds win_prob bankroll target_ruin_levelexpected_loss: the mean loss per unit staked given the sizing and edge.variance_of_return: second moment of per-bet returns, useful for comparing strategies at equal expected value.ruin_probability: the probability that the bankroll reaches a specified floor before doubling, given fixed Kelly-fraction betting.
Whale.Policy
Section titled “Whale.Policy”Declarative rules that constrain which bets a strategy may place. Policies compose: a bet must satisfy every active policy to proceed.
import Whale.Policy exposing (Policy, require)
let rules = [ Policy.min_edge 0.02, Policy.max_odds (Odds.decimal 20.0), Policy.max_concurrent 5, Policy.cooldown_seconds 60,]
let verdict = Policy.evaluate rules candidate_bet-- verdict : Result () PolicyViolationevaluate returns Ok () when all rules pass, or an Err describing the
first violated policy. The caller decides whether to reject or log.
Whale.Guards
Section titled “Whale.Guards”Guards are hard limits that act as a final gate before execution. Unlike policies (which advise), guards halt execution unconditionally when breached.
import Whale.Guards exposing (Guard, enforce)
let guards = [ Guard.max_stake (Money.usd 500.00), Guard.max_daily_loss (Money.usd 1_000.00), Guard.max_drawdown_pct 0.25,]
let check = Guard.enforce guards roll candidate_stake-- check : Result () GuardTrippedWhen a guard trips, the bet does not execute. The GuardTripped value
carries the guard name and the value that breached it, for diagnostics.
Composition
Section titled “Composition”A typical execution path:
- Compute
StakeFractionviaWhale.Sizing. - Convert to
MoneyviaWhale.BankRoll.stake. - Evaluate
Whale.Policyrules against the candidate. - Enforce
Whale.Guardson the final stake and bankroll state. - If all pass, record the bet. Otherwise, skip or reduce.