Commit Graph
2 Commits
Author SHA1 Message Date
Alby96andClaude Opus 5.5 a8defde572 Fix the review findings of the basket engine, command and report
The independent review of Phase 14 found rules the engine applied
differently from the decisions, numbers the report labelled wrongly and
a command that left a trial "running" when interrupted.

Engine:
- The pause after the 9% account stop is read at the decision moment
  (the bar's close), like every other gate: on daily bars it no longer
  blocks one day past the server date change.
- In a one-pair basket, a level closed by the venue's mandatory stop
  closes the other levels at the next execution with their own reason,
  closed_with_stop (counted and labelled in the report); the basket's
  exit stays mandatory_stop, and a two-leg basket keeps orphan_leg.
- The cap of two entries per currency applies to new baskets only,
  never to the averagings of an open basket, and every leg is valued
  at the current mid: a Prudente long basket "come dal vivo" now makes
  its three averagings and Fedele writes no note on them.
- The surrogate of the control chains on the mid when the source has
  an ask, so each mid change keeps its size and the spread stays
  around the mid instead of moving the mid by a spread at each change
  of sign.
- The financing already charged on positions still open at the end is
  part of the run's fees (BacktestRun.AccruedFees, zero for the daily
  engine, kept in stored unit outcomes).

Report: the fee row says what it holds (commission and financing, the
spread is in the prices) and the cost-stress text matches what the
multiplier scales; baskets still open at the end are labelled as such
and left out of the share closed at the target; refusal labels say
what the engine checks; the ECB-price and cost limitations are no
longer printed twice; every count has the Italian thousands separator.

Command: Ctrl+C or SIGTERM cancels the run; the trial is recorded as
failed with "Prova interrotta prima della fine: rilancia «anubis
backtest baskets»." and the command exits 1; a trial that cannot start
is failed instead of thrown, and an unexpected error ends with an
Italian line, never a stack trace. The laboratory fails a leftover
basket trial with an accurate message instead of "Strategia non più
disponibile".

The Table 6.5 test comment no longer claims each price is the only one
that fits the row. The real report is regenerated on the same data and
database as the first run, which now counts as a prior trial.

refs #127 #129 #131

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 19:26:24 +01:00
Alby96andClaude Opus 5.5 44639e3f49 Add the basket engine: a margin account that trades the document's baskets
Phase 14 needs an engine that simulates the research document's baskets
with the frictions of the venue, so the trial judge can say whether they
earn anything once those frictions are paid.

BasketEngine walks a BasketMarket (the bars of a BarDataset without the
moments no symbol trades) bar by bar: decisions on the closed bar,
execution at the next open, buys at the ask and sells at the bid (bid and
ask rebuilt from the venue spread when the source gives one price, as the
ECB fixings do). Every leg of every level is its own position with the
venue's mandatory stop; a stop that leaves one leg of a two-leg basket
alone closes the rest at the next execution as an orphan leg. Commission
on both sides, financing at every rollover crossed (Wednesday triple, from
the VenueCosts calendar), liquidation below half the initial margin.

On top, the document's account rules (9% stop on the open loss over the
balance, on mid prices in the daily pause, entries back at the next server
day; 2% gate on new baskets only; open baskets, Rvol, correlation, three
costs) and, «come dal vivo», SPEC 9.2 through RiskMonitor (day, week, fall
from the high, trip with the seven-day restart), the 40% margin limit,
nine positions, no opposite positions, net exposure per currency and the
Prudente basket stops. One equity point a day for every variant.

Signals come from the replica's RollingZ and RollingSigma on each unit's
compressed series; a rolling Rvol joins them, equal to BasketIndex.Rvol.
The comparison configuration (same close, no cost, no protection) makes
the replica's baskets on 200 seeded series and its total to 1e-9; on the
ECB fixture it gives the replica's 535.54 targets over 1,259 baskets.
TrialPlan gains optional Mode and Costs, left out when null, so the plans
of the daily families keep their hashes.

refs #127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 18:17:13 +01:00