Write the diary from fixed templates and add the "senza bot" comparison (refs #50)

The diary needs sentences in the tone of appendix B, built only from what
happened. DiaryText holds the templates the live engine will use: fills
with the result of the trade they close, raised stops, the daily crypto
close, the stock signals, observation signals, recovery and absence. The
reason-code sentences move from the server into the library
(ReasonCatalog) so the engine and the screens share them; a test checks
that every reason constant has its sentence. The diary gets the kinds of
the Diario screen: Ordini, Decisioni, Sistema, Notizie, Apprendimento.

The comparison of SPEC 7.5 invests each capital flow on its day, 40% in
BTC/EUR and 60% in SPY adjusted and converted at the ECB rate, and never
touches it; a withdrawal sells both in the proportion they reached. Prices
are the closes of the day before, so a deposit is never a gain. Without
the SPY history (no Alpaca keys) the photograph leaves it empty rather
than show half a comparison. The Panoramica now takes the flows out of
the "Senza bot" result, as it already did for the bot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 17:46:28 +01:00
1 parent e3c9eae65b
commit 98ee504dab
9 files changed
+636 -72

No files matched your search

+6 -2
View File
@@ -95,9 +95,13 @@ internal sealed record Overview(
};
var series = daily.Where(p => p.Day >= start.Day).ToList();
var cells = new List<PeriodResult> { Between("Oggi", Since(1)), Between("Ultimi 7 giorni", Since(7)), Between("Ultimi 30 giorni", Since(30)) };
if (daily[0].Benchmark is { } firstBenchmark && latest.Benchmark is { } lastBenchmark && firstBenchmark != 0)
// "Senza bot" since the first day it is known, with the same flows taken out as for the bot (SPEC 7.5).
if (daily.FirstOrDefault(p => p.Benchmark is not null) is { Benchmark: { } firstBenchmark } first && latest.Benchmark is { } lastBenchmark)
{
cells.Add(new PeriodResult("Senza bot", lastBenchmark - firstBenchmark, (lastBenchmark - firstBenchmark) / firstBenchmark * 100m));
var flows = latest.Flows - first.Flows;
var amount = lastBenchmark - firstBenchmark - flows;
var basis = firstBenchmark + flows;
cells.Add(new PeriodResult("Senza bot", amount, basis == 0m ? 0m : amount / basis * 100m));
}
return new Overview(daily, series, Between("", start), start.Day, start.Equity, cells, (int)positions, (int)withoutStop, (int)orders, next, last, capitalSet);
+1 -58
View File
@@ -12,63 +12,6 @@ namespace Anubis.Server;
/// </summary>
internal static class ReasonTexts
{
private static readonly Dictionary<string, string> Texts = new(StringComparer.Ordinal)
{
// Strategies.
["trend_entry"] = "La chiusura ha superato i massimi recenti su almeno un orizzonte: è iniziata una tendenza al rialzo.",
["trend_increase"] = "Più orizzonti erano d'accordo sulla tendenza: il peso è salito.",
["trend_reduce"] = "La tendenza si è indebolita, o la moneta è diventata più agitata: il peso è sceso.",
["trend_exit"] = "La tendenza si è interrotta: il prezzo è finito sotto lo stop mobile.",
["trend_stop"] = "Lo stop mobile è salito con il prezzo.",
["momentum_entry"] = "Era tra i titoli più forti degli ultimi mesi, con il mercato in salita.",
["momentum_increase"] = "Il peso obiettivo è salito alla revisione settimanale.",
["momentum_reduce"] = "Il peso obiettivo è sceso alla revisione settimanale.",
["momentum_exit_rank"] = "Non era più tra i 30 titoli più forti.",
["momentum_exit_trend"] = "Il mercato nel suo insieme è girato al ribasso: niente più azioni.",
["momentum_stop"] = "Lo stop di protezione è stato aggiornato.",
["meanrev_entry"] = "Era sceso per qualche seduta di fila ma restava sopra la sua media a 200 giorni: un ribasso breve di un titolo che nel lungo periodo sale.",
["meanrev_exit_average"] = "Il prezzo è tornato sopra la media a 5 giorni: il rimbalzo cercato è arrivato.",
["meanrev_exit_rsi"] = "L'indicatore di forza è tornato alto: il rimbalzo è avvenuto.",
["meanrev_exit_earnings"] = "Uscita prima della trimestrale.",
["meanrev_exit_time"] = "Tempo scaduto: nessun rimbalzo in 5 sedute.",
// Exits recorded on the trade.
["stop"] = "Stop di protezione raggiunto.",
["exit"] = "Uscita decisa dalla strategia.",
["signal"] = "Uscita sul segnale della strategia.",
["residue"] = "Resto troppo piccolo per essere venduto, tolto dal registro.",
["adjustment"] = "Rettifica dopo l'allineamento con il conto.",
// Correctives.
["crypto_regime_below_average"] = "Il mercato crypto era sotto la sua media: acquisti ridotti.",
["crypto_regime_high_volatility"] = "Il mercato crypto era molto agitato: acquisti ridotti.",
["calendar_event"] = "Un dato economico importante era vicino: niente nuove posizioni in quell'ora.",
// Risk.
["risk_reduction"] = "Ordine rimpicciolito dai limiti di rischio.",
["daily_loss_block"] = "Perdita del giorno oltre il limite: niente nuovi ingressi per 24 ore.",
["switch_tripped"] = "Interruttore scattato: il bot aspetta la tua conferma.",
["bot_paused"] = "Bot in pausa: niente nuovi ingressi.",
["bot_stopped"] = "Bot fermato con \"Ferma tutto\".",
["invested_limit"] = "Capitale investito al limite: niente soldi presi in prestito.",
["position_limit"] = "Ridotto al peso massimo di una posizione.",
["crypto_limit"] = "Quota delle crypto sul totale al limite.",
["trade_risk_limit"] = "Ridotto perché il rischio dell'operazione restasse entro il limite.",
["stop_above_price"] = "Stop sopra il prezzo: ordine rifiutato.",
["stale_price"] = "Prezzo troppo vecchio: niente acquisti finché i dati non tornano freschi.",
["price_gap"] = "Prezzo dell'ordine troppo lontano dall'ultimo prezzo.",
["clock_skew"] = "Orologio non allineato con quello del broker.",
["owned_by_other_strategy"] = "La posizione appartiene a un'altra strategia.",
["no_short_selling"] = "Niente vendite allo scoperto: venduto solo quanto posseduto.",
["no_leverage"] = "Niente leva: l'ordine sta nella liquidità disponibile.",
["not_owned_by_bot"] = "La posizione non è del bot: non la tocca.",
["live_not_confirmed"] = "Soldi veri non confermati per questa strategia.",
["exit_only"] = "Strategia in sola uscita: niente nuovi acquisti.",
["live_not_allowed"] = "Soldi veri non permessi dalla configurazione d'avvio.",
["observation"] = "Strategia in osservazione: produce segnali, nessun ordine.",
["orders_per_minute"] = "Troppi ordini in un minuto: il bot si è fermato.",
["pdt_guard"] = "Guardia sulle operazioni in giornata: niente posizioni in più oggi.",
["no_fx_rate"] = "Manca il cambio euro-dollaro: niente acquisti in dollari.",
["unknown_instrument"] = "Strumento sconosciuto.",
};
// The exits in the few words of a table column; the full sentence stays for the "why" card.
private static readonly Dictionary<string, string> ShortExits = new(StringComparer.Ordinal)
{
@@ -85,7 +28,7 @@ internal static class ReasonTexts
/// <summary>Why a trade was closed, in a short sentence.</summary>
public static string Exit(string? code) => code is null ? "Chiusa" : ShortExits.TryGetValue(code, out var text) ? text : Text(code).TrimEnd('.');
public static string Text(string code) => Texts.TryGetValue(code, out var text) ? text : code;
public static string Text(string code) => ReasonCatalog.Text(code);
/// <summary>The lines of one stage of a decision. <paramref name="data"/> is the JSON of the numbers the stage used.</summary>
public static IEnumerable<WhyLine> Stage(string stage, string outcome, IReadOnlyList<string> reasons, string? data)