@inherits LoadedComponent
@page "/laboratorio/confronto"
@inject AnubisHost Host
@inject ShellData Shell
@inject IClock Clock
@using Anubis.Backtest
@using Anubis.Strategies
Confronto tra test · Anubis
← Laboratorio
@if (_a is null || _b is null)
{
Scegli due test conclusi dall'elenco del Laboratorio.
return;
}
@{
var a = _a.Value;
var b = _b.Value;
var ra = a.Report;
var rb = b.Report;
}
Confronto tra due test
@if (ra.DataFingerprint != rb.DataFingerprint)
{
I due test hanno letto dati diversi (strumenti, periodo o valuta): il confronto è indicativo.
}
else
{
Stessi dati per entrambi: le differenze vengono dalla strategia, dalla griglia o dalle soglie.
}
|
@Name(a) |
@Name(b) |
@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))
@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 =>
{
| @label | @value(_a!.Value) | @value(_b!.Value) |
};
}