Add the Laboratorio screen: new test, report, comparison (refs #36)
The laboratory starts with the host (off in demo mode) and runs its queue next to market data and trading. The page lists every trial with status, verdict and headline figures, refreshing itself while one is queued or running, and offers the form for a new test: strategy, data origin and market, instruments, period, initial capital and the grid, with the thresholds stated before the run. The form posts with the antiforgery token; errors come back as a short code. The report page shows the protocol checks, the chosen variant against buy and hold (table and chart), results per year, cost sensitivity, the Deflated Sharpe Ratio, PBO, walk-forward windows, purged CV paths, the look-ahead result, every variant with its zone score, what the backtest does not model, the data used and the trades. A comparison page puts two finished tests side by side and says whether they read the same data. The improvements of 8.7 and the cost estimates of 11.6 have their sections, empty until Phases 9 and 8. The equity chart takes amounts in their own currency and its labels as parameters. The profit factor has no value without a losing trade. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5efb149fd6
commit
953ffe5e9b
11 files changed
+1083
-26
No files matched your search
@@ -34,6 +34,7 @@ internal static partial class Forms
|
||||
signed.MapPost("/chiavi/{broker}", SaveKeysAsync);
|
||||
signed.MapPost("/chiavi/{broker}/togli", RemoveKeysAsync);
|
||||
signed.MapPost("/capitale/{broker}", SetCapitalAsync);
|
||||
signed.MapPost("/laboratorio", PlanTrialAsync);
|
||||
}
|
||||
|
||||
private static string Back(IFormCollection form, string fallback)
|
||||
@@ -324,6 +325,93 @@ internal static partial class Forms
|
||||
return Results.Redirect(back + "?ok=capitale#conti");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A new backtest trial (SPEC 12.2): the plan is written and queued at once, then the page of the trial follows it.
|
||||
/// A field that cannot be read goes back as a code; the chosen strategy is kept, nothing typed travels in the address.
|
||||
/// </summary>
|
||||
private static async Task<IResult> PlanTrialAsync(IFormCollection form, AnubisHost host, CancellationToken ct)
|
||||
{
|
||||
var family = Anubis.Strategies.StrategyCatalog.Find(form["strategia"].ToString());
|
||||
string Back(string code) => "/laboratorio?errore=" + code + (family is null ? "" : "&strategia=" + Uri.EscapeDataString(family.Id)) + "#nuovo";
|
||||
if (host.IsDemo || host.Services?.Lab is not { } lab)
|
||||
{
|
||||
return Results.Redirect(Back("motore"));
|
||||
}
|
||||
|
||||
if (family is null)
|
||||
{
|
||||
return Results.Redirect(Back(Anubis.Backtest.TrialRequestErrors.Strategy));
|
||||
}
|
||||
|
||||
var source = form["origine"].ToString();
|
||||
var venue = source == Anubis.Backtest.TrialSources.Research ? Anubis.Data.Venues.Binance : form["mercato"].ToString();
|
||||
if (source == Anubis.Backtest.TrialSources.Database && venue is not (Anubis.Data.Venues.Okx or Anubis.Data.Venues.Alpaca))
|
||||
{
|
||||
return Results.Redirect(Back(Anubis.Backtest.TrialRequestErrors.Source));
|
||||
}
|
||||
|
||||
if (ParseDay(form["dal"].ToString()) is not { } from || ParseDay(form["al"].ToString()) is not { } to)
|
||||
{
|
||||
return Results.Redirect(Back(Anubis.Backtest.TrialRequestErrors.Dates));
|
||||
}
|
||||
|
||||
if (ParseEuro(form["capitale"].ToString()) is not { } capital)
|
||||
{
|
||||
return Results.Redirect(Back(Anubis.Backtest.TrialRequestErrors.Capital));
|
||||
}
|
||||
|
||||
var grid = new Dictionary<string, IReadOnlyList<decimal>>(StringComparer.Ordinal);
|
||||
foreach (var p in family.Parameters)
|
||||
{
|
||||
var text = form["griglia_" + p.Name].ToString();
|
||||
if (string.IsNullOrWhiteSpace(text))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ParseList(text) is not { } values)
|
||||
{
|
||||
return Results.Redirect(Back(Anubis.Backtest.TrialRequestErrors.Grid));
|
||||
}
|
||||
|
||||
grid[p.Name] = values;
|
||||
}
|
||||
|
||||
var symbols = form["strumenti"].ToString()
|
||||
.Split([',', ';', ' ', '\n', '\r', '\t'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
||||
.Select(x => x.ToUpperInvariant())
|
||||
.ToList();
|
||||
try
|
||||
{
|
||||
var trial = await lab.PlanAsync(new Anubis.Backtest.TrialRequest(family.Id, source, venue, symbols, from, to, capital, grid), ct).ConfigureAwait(false);
|
||||
return Results.Redirect("/laboratorio/" + trial.Id.ToString("D"));
|
||||
}
|
||||
catch (Anubis.Backtest.TrialRequestException ex)
|
||||
{
|
||||
return Results.Redirect(Back(ex.Code));
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
/// <summary>Values of a grid as people type them: "10, 20, 30" or "10 20 30"; decimals with a point.</summary>
|
||||
internal static IReadOnlyList<decimal>? ParseList(string text)
|
||||
{
|
||||
var result = new List<decimal>();
|
||||
foreach (var item in (text ?? "").Split([',', ';', ' '], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
if (!decimal.TryParse(item, System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.InvariantCulture, out var value))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
result.Add(value);
|
||||
}
|
||||
|
||||
return result.Count is > 0 and <= 20 ? result : null;
|
||||
}
|
||||
|
||||
/// <summary>An amount as people type it: "1500", "1.500", "1500,50", "1.500,50", "1500.50".</summary>
|
||||
internal static decimal? ParseEuro(string text)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user