trader.ranking.comparables module

Two deterministic figures per candidate, derived from stored bars.

The ranker is shown each candidate’s own prose reason from its per-symbol decision. A model comparing several pieces of its own fluent prose will tend to pick the most fluent, not the best — so the prompt also carries numbers that are commensurable across candidates and can contradict a well-written reason.

Both figures come from bars this app already fetched. Nothing here does I/O, so decisions.inputs_json stays reproducible and a later provider comparison stays a script rather than a project.

class trader.ranking.comparables.Comparables(bars_considered, window_change_pct, range_position_pct)[source]

Bases: object

Where a candidate sits in its own recent range, and which way it moved.

Parameters:
  • bars_considered (int)

  • window_change_pct (Decimal)

  • range_position_pct (Decimal | None)

bars_considered: int
window_change_pct: Decimal

Percent change from the window’s first close to its last.

range_position_pct: Decimal | None

Where the last close sits between the window low and high, 0-100.

None when the window is flat (high == low). NOT 0 and NOT 50: a flat window is real for an illiquid or halted name, and both numbers would be false claims about where price sits — one saying “at the low”, the other “mid-range” — which the ranker would believe.

as_dict()[source]

JSON-safe, for decisions.inputs_json and for the prompt.

Prices and percentages are strings rather than floats for the same reason build_bar_summary does it: a float both loses precision and misrepresents what the ranker was shown.

Return type:

dict[str, object]

trader.ranking.comparables.build_comparables(bars, lookback)[source]

The two figures, over the last lookback bars.

lookback is the candidate’s own strategy’s warmup_bars(). For LlmStrategy that is its _lookback_bars, so these figures describe exactly the window the model was shown per symbol. The pool being ranked is always single-strategy, so the window is uniform across candidates — which is the only property that matters for comparing them.

Parameters:
  • bars (Sequence[Bar])

  • lookback (int)

Return type:

Comparables