Fase 5 — Strategie, portafoglio e rischio #91

Merged
Alby96 merged 8 commits from fase-5 into main 2026-11-11 17:30:11 +01:00
8 Commits
Author SHA1 Message Date
Alby96andClaude Opus 5.5 fc5df0146e Prepare strategies before the host is ready; stop demo servers first (refs #44 #45)
ci / test (postgres) (push) Successful in 4m39s
ci / test (sqlite) (push) Successful in 2m57s
ci / image (push) Successful in 56s
ci / test (postgres) (pull_request) Successful in 5m27s
ci / test (sqlite) (pull_request) Successful in 3m14s
ci / image (pull_request) Successful in 10s
Loading the outcomes before "ready" was not enough: on a fresh database the
strategy rows did not exist yet, so the load did nothing and CI run 220
failed the same way on PostgreSQL. The new TradingService.PrepareAsync
creates accounts and strategies, then loads the outcomes; the host runs it
before it is ready and logs a failure without blocking the interface.
StartAsync repeats it, which changes nothing.

The demo tests deleted the demo folder while the server still held its
SQLite file, which Windows refuses at random. They now stop the server
first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 17:19:15 +01:00
Alby96andClaude Opus 5.5 dc1ba4e701 Load the backtest outcomes before the host is ready (refs #44 #45)
ci / test (postgres) (push) Failing after 4m53s
ci / test (sqlite) (push) Successful in 3m4s
ci / image (push) Skipped
The trading service loaded the outcomes in the background after the host
reported "ready", so for a moment Strategie showed every strategy as
without a backtest. CI run 219 caught it on SQLite. The host now loads
them before it is ready; the call is idempotent, so the one at trading
start changes nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 17:01:25 +01:00
Alby96andClaude Opus 5.5 9ac159a7db Fix the defects of the Phase 5 review (refs #41 #42 #43 #44 #45 #46)
ci / test (postgres) (push) Successful in 3m52s
ci / test (sqlite) (push) Failing after 2m41s
ci / image (push) Skipped
An independent review found these, now fixed and tested:

- Risk limits could be raised through PUT /api/settings without the
  phrase and the password. The API now refuses risk keys.
- The reference equity counted results twice after reduced to real and
  after a demotion. Each ledger now keeps a baseline, and carried results
  stay in the ledger's currency until the reference is computed.
- An instrument could be bought by a second strategy in the same account
  (SPEC 8.6), and purchases under way did not hold their cash, so several
  purchases sent together could exceed it. Both are refused or shrunk now.
- After an automatic trip of the switch there was no way to restart from
  the interface. Rischio now shows the trip of both worlds and the restart.
- The fresh password of SPEC 12.4 could be tried without limit. Five wrong
  attempts in 15 minutes now lock it.
- Observation to simulation skipped the 90 days of live signals.
- A new build changed the qualification of a strategy with real money,
  "Ferma tutto" counted as a critical incident, raising risk ignored
  demotion conditions in progress, and weekends counted as stock sessions.
- The 12.4 confirmation now summarises capital, first purchases and limits,
  and live strategies show the gap with their simulated twin.

The backtest converts each bar with the rate fixed before it opens, the
day before, and the report now counts how often correctives and risk
changed a decision. crypto_trend is still not passed: the broad universe
now falls 32.8%. The outcome file also keeps the qualified parameters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:48:41 +01:00
Alby96andClaude Opus 5.5 17d6b8db38 Record the Phase 5 choices and close the roadmap items (refs #46)
ADR 0011 collects what the specification leaves open or refines in this
phase: strategies shared by backtest and live, correctives and risk inside
the backtests, the risk engine that only refuses or shrinks, the stages as
the only way to real money, the euro history and the protocol of the base
backtests, and the honest "not passed" of crypto_trend.

ROADMAP ticks the Phase 5 items and criteria with the tests that prove
them; STATE moves to Phase 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:19:35 +01:00
Alby96andClaude Opus 5.5 13f9c42f61 Add the Operazioni, Strategie and Rischio screens (refs #45)
The three screens follow mockups 03, 04 and 07.

Operazioni shows the balance of the closed trades, filters, a CSV export,
and for each trade why it was bought and sold. The reasons come from the
decision codes through fixed Italian templates.

Strategie shows the four stages towards real money, a card per strategy
with its requirements, the procedure of SPEC 12.4, and why each strategy in
observation waits. A strategy that failed its backtest cannot be moved into
the simulation.

Rischio shows the emergency switch, the automatic blocks, the use of each
limit, the fall from the peak, the scenarios and the risk events. Stop,
close and restart now go through the risk engine. A restart is refused
while the STOP file exists.

Impostazioni gains the limits, the day-trade guard and the scenarios.
Lowering a limit is always allowed. Raising a limit or the entrusted capital
while a strategy uses real money needs the phrase and the password.

The demo now holds the decisions behind its trades, the 58 days of
simulation and the indices of its curves, so it matches the mockups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:14:44 +01:00
Alby96andClaude Opus 5.5 7041533ce2 Add the honest backtests of the base strategies (refs #44)
crypto_trend now has a backtest report and an outcome file, computed by
"anubis backtest base" on the Binance daily archives from 2019 to October
2026. Prices are converted from USDT to euro with the ECB rate of the day,
and delisted coins stay in the universe, so survivors do not flatter the
result. The protocol runs the broad universe and BTC, ETH and SOL, with
costs doubled and tripled and buy and hold beside. Both universes must pass.

The outcome is "not passed": the broad universe falls 29.1% (limit 25%) and
the narrow one has a probability of overfitting of 0.84 (limit 0.40). The
strategy therefore stays in observation. The stock strategies wait for the
Alpaca keys and stay in observation too. The bot reads the outcome files at
every start.

Trials now read 450 days of history before their start, only so the
indicators and the 400-day listing age are ready on the first day. Before
this, 2019 was spent warming up and BTC and ETH could not be chosen until
2020. A daily series also stops at a hole longer than a week, so the LUNA
relaunched in 2022 is not mistaken for the coin that collapsed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 16:13:23 +01:00
Alby96andClaude Opus 5.5 8def84e122 Add the risk engine, correctives and strategy stages (refs #41 #42 #43)
Every intent of a strategy now crosses a risk engine that only refuses or
shrinks: loss limits per world with the 24-hour block, the weekly halving,
the halving and the switch on the fall from the high, the size limits on
invested capital, single position, crypto share and trade risk, the
technical checks, no short sales and no leverage, the day-trade guard
(off by default). The switch, "Ferma tutto", "Ferma e chiudi", the STOP
file and the orders-per-minute anomaly stop the bot until the user
confirms a restart, and a restart after a trip measures the high from
then on.

The correctives of SPEC 8.5 (crypto regime, economic calendar) and the
risk rules also run inside the backtests of the base strategies, so the
reports show what would happen live. Each stage of a decision is written
to a new decisions table with reason codes.

The stage book is the only way to real money: an order on a real account
needs the startup consent, every requirement of SPEC 12.3 met, the typed
phrase and a fresh password and second factor. Order managers on real
accounts fail closed and ask again before each order leaves. A demoted or
revoked strategy keeps its real positions in exit only, with stops, until
they are at zero. The simulated twin stays out of totals and of the
reference equity.

Tests cover each rule of 9.1 and 9.2, with property tests for "never
larger than asked" and "never larger after a loss", and both proofs on a
fake real account: nothing reaches it without the procedure, and a
demoted strategy manages exits and stops down to zero.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:22:35 +01:00
Alby96andClaude Opus 5.5 2409e74b26 Add the three base strategies and their indicators (refs #38 #39 #40)
crypto_trend follows nine breakout periods with Donchian-middle stops,
volatility-targeted weights under the 35%/20% caps and a monthly top-10
universe. equity_momentum reviews on the last close of each week with the
SPY filter, inverse-volatility weights and an ATR trailing stop.
equity_meanrev buys RSI(2) dips above the 200-session average, sized for
a fixed risk, and exits at the close.

The engine gains what the rules need: exits at the same close, a stop set
at a distance from the price obtained, data-only instruments such as SPY,
the trading calendar, the reference equity of the strategy's share and the
equity history. Every strategy passes the look-ahead check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 14:43:19 +01:00