Learn slippage from real executions and say discoveries in plain words

The monthly regression raises an estimate by itself and lowers one only on
real money and with the confirmation of the user in the Laboratorio. The
table of what news does to prices and the fixed list of questions on the
clues are informative only.

refs #65

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 12:15:20 +01:00
1 parent df21962da3
commit 14e8a872dc
15 files changed
+1060 -22

No files matched your search

@@ -5,7 +5,9 @@
@inject IClock Clock
@using Anubis.Backtest
@using Anubis.Data
@using Anubis.Learning
@using Anubis.Strategies
@using Anubis.Trading
<PageTitle>Laboratorio · Anubis</PageTitle>
@@ -173,10 +175,47 @@
<section class="panel" aria-labelledby="stime">
<h2 id="stime">Stime di costo da confermare</h2>
<div class="empty">
<p class="empty-title">Nessuna stima da confermare.</p>
<p>Quando le esecuzioni con soldi veri diranno che lo scostamento è più basso di quello previsto, la nuova stima aspetterà qui la tua conferma. Arrivano con la Fase 8.</p>
</div>
<p class="hint">Scostamento contato da simulatore e backtest: @string.Join("; ", SlippageTiers.All.Select(t => SlippageTiers.Label(t) + " " + Bp(_table.Of(t)))). Ogni mese si confronta con le esecuzioni ottenute dai broker, mai con quelle del simulatore. Una stima sale da sola; scende solo se viene da soldi veri e la confermi tu.</p>
@if (_costs.Where(c => c.Status == CostStatuses.Pending).ToList() is { Count: > 0 } pending)
{
@foreach (var c in pending)
{
<div class="row">
<p>@Capital(SlippageTiers.Label(c.Tier)): da @Bp(c.PreviousBp) a @Bp(c.Bp). <span class="note">Misurati @Bp(c.MeasuredBp) su @c.Cases esecuzioni con soldi veri (tra @Bp(c.LowBp) e @Bp(c.HighBp) al 95%).</span></p>
<form method="post" action="/azioni/stime-di-costo/@c.Id/conferma" class="form-inline"><AntiforgeryToken /><button class="btn btn-small" type="submit" data-confirm="Simulatore e backtest conteranno costi più bassi. Confermi?">Conferma</button></form>
<form method="post" action="/azioni/stime-di-costo/@c.Id/rifiuta" class="form-inline"><AntiforgeryToken /><button class="btn btn-small" type="submit">Rifiuta</button></form>
</div>
}
}
else
{
<div class="empty">
<p class="empty-title">Nessuna stima da confermare.</p>
<p>Quando le esecuzioni con soldi veri diranno che lo scostamento è più basso di quello previsto, la nuova stima aspetterà qui la tua conferma.</p>
</div>
}
@if (_costs.Where(c => c.Status != CostStatuses.Pending).Reverse().Take(10).ToList() is { Count: > 0 } past)
{
<div class="table-wrap">
<table class="table">
<caption class="sr-only">Stime di scostamento già decise</caption>
<thead><tr><th scope="col">Quando</th><th scope="col">Strumenti</th><th scope="col" class="num">Prima</th><th scope="col" class="num">Stima</th><th scope="col" class="num">Esecuzioni</th><th scope="col">Esito</th></tr></thead>
<tbody>
@foreach (var c in past)
{
<tr>
<td class="nowrap">@Format.ShortDate(c.DecidedAt ?? c.CreatedAt, Shell.Now, Shell.Zone)</td>
<td>@Capital(SlippageTiers.Label(c.Tier))</td>
<td class="num">@Bp(c.PreviousBp)</td>
<td class="num">@Bp(c.Bp)</td>
<td class="num">@c.Cases</td>
<td>@Outcome(c.Status)</td>
</tr>
}
</tbody>
</table>
</div>
}
</section>
@code {
@@ -188,6 +227,8 @@
private DateOnly _from;
private DateOnly _to;
private IReadOnlyList<string> _research = [];
private IReadOnlyList<CostEstimate> _costs = [];
private SlippageTable _table = SlippageTable.Standard;
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
@@ -204,6 +245,9 @@
var services = Host.Services!;
_lab = services.Lab;
_trials = await new TrialStore(services.Db, Clock).ListAsync(100, ct);
var costs = new CostBook(services.Db, Clock);
_costs = await costs.ListAsync(ct);
_table = await costs.TableAsync(ct);
_running = _trials.Any(t => !t.IsFinished);
_family = StrategyCatalog.Find(Strategia ?? "") ?? StrategyCatalog.All[0];
var today = DateOnly.FromDateTime(Clock.UtcNow.UtcDateTime);
@@ -217,6 +261,7 @@
_message = Errore switch
{
null => null,
"stima" => "Quella stima non aspetta più una conferma.",
"motore" => "Il laboratorio non è attivo in questo momento: riprova tra poco.",
TrialRequestErrors.Strategy => "Strategia sconosciuta: scegline una dall'elenco.",
TrialRequestErrors.Source => "Scegli da dove prendere i dati e, per le barre raccolte, il mercato.",
@@ -229,6 +274,18 @@
};
}
private static string Bp(decimal bp) => Format.Quantity(Math.Round(bp, 1)) + " punti base";
private static string Capital(string text) => char.ToUpper(text[0], System.Globalization.CultureInfo.GetCultureInfo("it-IT")) + text[1..];
private static string Outcome(string status) => status switch
{
CostStatuses.Applied => "Salita da sola",
CostStatuses.Confirmed => "Confermata da te",
CostStatuses.Refused => "Rifiutata da te",
_ => "Superata dal mese dopo",
};
private string Research() => _research.Count == 0
? "Lo storico di ricerca è vuoto: lo riempie la raccolta dei dati."
: "Nello storico di ricerca: " + LabText.Symbols(_research) + ".";
+19
View File
@@ -41,6 +41,7 @@ internal static partial class Forms
signed.MapPost("/segnale-di-vita/togli", RemoveHeartbeatAsync);
signed.MapPost("/assenza/{id:guid}/vista", AbsenceSeenAsync);
signed.MapPost("/laboratorio", PlanTrialAsync);
signed.MapPost("/stime-di-costo/{id:guid}/{choice}", DecideCostAsync);
signed.MapPost("/strategie/{strategy}/{choice}", StrategyStageAsync);
signed.MapPost("/rischio/limiti", SetLimitsAsync);
signed.MapPost("/rischio/{key}", SetRiskSettingAsync);
@@ -764,6 +765,24 @@ internal static partial class Forms
}
}
/// <summary>A lower slippage estimate waits for the user (SPEC 11.6).</summary>
private static async Task<IResult> DecideCostAsync(Guid id, string choice, AnubisHost host, HttpContext context, CancellationToken ct)
{
if (host.IsDemo || host.Services is not { } services || choice is not ("conferma" or "rifiuta"))
{
return Results.Redirect("/laboratorio?errore=motore#stime");
}
var book = new Anubis.Learning.CostBook(services.Db, host.Clock);
var done = await book.DecideAsync(id, choice == "conferma", context.User.Identity?.Name ?? "utente", ct).ConfigureAwait(false);
if (done && services.Trading is { } trading)
{
await trading.RefreshCostsAsync(ct).ConfigureAwait(false);
}
return Results.Redirect(done ? "/laboratorio#stime" : "/laboratorio?errore=stima#stime");
}
private static DateOnly? ParseDay(string text) =>
DateOnly.TryParseExact(text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out var day) ? day : null;