Files
Anubis/src/Anubis.Server/Components/Pages/LaboratorioConfronto.razor
T
Alby96andClaude Opus 5.5 f278ff4f67
ci / test (postgres) (push) Successful in 2m41s
ci / test (sqlite) (push) Successful in 1m56s
ci / test (postgres) (pull_request) Successful in 3m45s
ci / test (sqlite) (pull_request) Successful in 2m22s
ci / image (push) Successful in 1m10s
ci / image (pull_request) Successful in 13s
Fix the defects of the Phase 4 review (refs #34 #35 #36)
- An error of the database (PostgreSQL restarting) no longer stops the
  laboratory until the next start: the queue logs it, waits 30 seconds
  on the injectable clock and tries the same trial again.
- Buy and hold, the comparison of every report, buys an instrument
  whose history starts later at its first close, with the share kept
  free for it; before, it was never bought and the others took its
  weight. Its version goes to 2.
- The comparison page reads a and b as text: a malformed id shows
  "two finished tests needed" instead of an error page.
- A trial re-checks the hash of its plan before running and refuses a
  plan that no longer matches it.
- Parameters that count days take whole numbers only (10.5 would run
  as 10 and count twice in the DSR); the capital starts from 1, as the
  message says.

ADR 0010 says so, and corrects the estimated minimum of the research
history: 5 does refuse smaller orders, like the exchanges' minimums.

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

107 lines
5.0 KiB
Plaintext

@inherits LoadedComponent
@page "/laboratorio/confronto"
@inject AnubisHost Host
@inject ShellData Shell
@inject IClock Clock
@using Anubis.Backtest
@using Anubis.Strategies
<PageTitle>Confronto tra test · Anubis</PageTitle>
<p><a href="/laboratorio">← Laboratorio</a></p>
@if (_a is null || _b is null)
{
<Pending Title="Servono due test completati.">Scegli due test conclusi dall'elenco del <a href="/laboratorio">Laboratorio</a>.</Pending>
return;
}
@{
var a = _a.Value;
var b = _b.Value;
var ra = a.Report;
var rb = b.Report;
}
<section class="panel" aria-labelledby="confronto">
<h2 id="confronto">Confronto tra due test</h2>
@if (ra.DataFingerprint != rb.DataFingerprint)
{
<p class="notice notice-attention" role="note"><Icon Name="info" Size="16" />I due test hanno letto dati diversi (strumenti, periodo o valuta): il confronto è indicativo.</p>
}
else
{
<p class="notice notice-gain" role="note"><Icon Name="check" Size="16" />Stessi dati per entrambi: le differenze vengono dalla strategia, dalla griglia o dalle soglie.</p>
}
<div class="table-wrap">
<table class="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col"><a href="/laboratorio/@a.Trial.Id">@Name(a)</a></th>
<th scope="col"><a href="/laboratorio/@b.Trial.Id">@Name(b)</a></th>
</tr>
</thead>
<tbody>
@Row("Esito", x => LabText.Verdict(x.Trial.Verdict))
@Row("Dati", x => LabText.Symbols(x.Trial.Plan.Data.Symbols) + ", " + LabText.Period(x.Trial.Plan.Data.From, x.Trial.Plan.Data.To))
@Row("Variante scelta", x => LabText.Parameters(x.Report.Chosen) + $" (di {x.Trial.Variants})")
@Row("Risultato netto", x => LabText.Money(x.Report.Metrics.NetResult, x.Report.Currency, withSign: true))
@Row("Con costi doppi", x => x.Report.Costs.FirstOrDefault(k => k.Multiplier == 2m) is { } k ? LabText.Money(k.NetResult, x.Report.Currency, withSign: true) : LabText.Missing)
@Row("Rendimento annuo", x => LabText.Percent(x.Report.Metrics.AnnualReturn, 1, true))
@Row("Comprare e tenere, annuo", x => LabText.Percent(x.Report.Benchmark.AnnualReturn, 1, true))
@Row("Volatilità annua", x => LabText.Percent(x.Report.Metrics.Volatility))
@Row("Sharpe annuo", x => LabText.Number(x.Report.Metrics.Sharpe))
@Row("Calo massimo", x => LabText.Percent(x.Report.Metrics.MaxDrawdown))
@Row("Operazioni chiuse", x => x.Report.Metrics.Trades.ToString(CultureInfo.InvariantCulture))
@Row("Operazioni in guadagno", x => x.Report.Metrics.Trades == 0 ? LabText.Missing : LabText.Percent(x.Report.Metrics.WinRate, 0))
@Row("Rapporto guadagni/perdite", x => LabText.Number(x.Report.Metrics.ProfitFactor))
@Row("Deflated Sharpe Ratio", x => LabText.Number(x.Report.DeflatedSharpe.Value))
@Row("Probabilità di sovra-adattamento", x => x.Report.Overfitting is { } p ? LabText.Number(p.Probability) : "non si applica")
@Row("Finestre che avanzano, rendimento", x => x.Report.WalkForward is { } w ? LabText.Percent(w.Return, 1, true) : LabText.Missing)
@Row("Decisioni cambiate dai dati futuri", x => x.Report.LookAhead.Changed.ToString(CultureInfo.InvariantCulture))
</tbody>
</table>
</div>
</section>
@code {
private (Trial Trial, BacktestReport Report)? _a;
private (Trial Trial, BacktestReport Report)? _b;
[CascadingParameter]
public HttpContext? HttpContext { get; set; }
// Text, not Guid: a malformed value must give "servono due test", not an error page.
[SupplyParameterFromQuery(Name = "a")]
public string? A { get; set; }
[SupplyParameterFromQuery(Name = "b")]
public string? B { get; set; }
protected override async Task LoadAsync()
{
var ct = HttpContext?.RequestAborted ?? CancellationToken.None;
var store = new TrialStore(Host.Services!.Db, Clock);
_a = await ReadAsync(store, A, ct);
_b = await ReadAsync(store, B, ct);
}
private static async Task<(Trial, BacktestReport)?> ReadAsync(TrialStore store, string? id, CancellationToken ct)
{
if (!Guid.TryParse(id, out var key) || await store.GetAsync(key, ct) is not { } trial || await store.ReportJsonAsync(key, ct) is not { } json)
{
return null;
}
return (trial, BacktestReport.FromJson(json));
}
private string Name((Trial Trial, BacktestReport Report) x) =>
$"{StrategyCatalog.Find(x.Trial.Strategy)?.Name ?? x.Trial.Strategy}, {Format.ShortDate(x.Trial.CreatedAt, Shell.Now, Shell.Zone)}";
private RenderFragment Row(string label, Func<(Trial Trial, BacktestReport Report), string> value) => __builder =>
{
<tr><th scope="row">@label</th><td>@value(_a!.Value)</td><td>@value(_b!.Value)</td></tr>
};
}