Files
Anubis/src/Anubis.Server/LabText.cs
T
Alby96andClaude Opus 5.5 2257c3e16c Review the base strategies every three months
Every quarter the base strategies are tried again on the longer history with
the slippage in force, compared with how they did live, and the report is
published in the laboratory with the base rates measured again and the balance
of the restrictions of 10.5. In observation the outcome replaces the old one and
a strategy that passed goes to simulation after its 90 days; with capital
nothing moves but the demotion condition of 12.3. A restart halfway goes on and
the review concludes once; the outcome of a review survives a restart with an
older build.

refs #74

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 20:59:20 +01:00

92 lines
4.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Anubis.Backtest;
using Anubis.Core;
namespace Anubis.Server;
/// <summary>How the laboratory pages write the numbers of a backtest, in plain Italian (SPEC 13.3).</summary>
internal static class LabText
{
public const string Missing = "—";
/// <summary>A fraction as a percentage: 0,1234 is "12,3%".</summary>
public static string Percent(double? fraction, int decimals = 1, bool withSign = false) =>
fraction is { } x && double.IsFinite(x) ? Format.Percent((decimal)(x * 100), decimals, withSign) : Missing;
public static string Number(double? value, int decimals = 2) =>
value is { } x && double.IsFinite(x) ? Format.Number((decimal)x, decimals) : Missing;
public static string Money(decimal value, string currency, bool withSign = false) => Format.Money(value, currency, withSign);
public static string Day(DateOnly? day) => day is { } d ? d.ToString("dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) : Missing;
public static string Period(DateOnly from, DateOnly to) => $"{Day(from)} – {Day(to)}";
/// <summary>Parameters as the user reads them: "fast=20;slow=100" becomes "fast 20, slow 100".</summary>
public static string Parameters(string text) =>
string.IsNullOrEmpty(text) ? "nessun parametro" : string.Join(", ", text.Split(';').Select(p => p.Replace('=', ' ').Replace('.', ',')));
public static string Status(Trial trial, string? progress) => trial.Status switch
{
TrialStatuses.Planned => "In coda",
TrialStatuses.Running => progress is null ? "In corso" : "In corso: " + progress,
TrialStatuses.Failed => "Non riuscito",
_ => "Completato",
};
public static string Verdict(string? verdict) => verdict switch
{
TrialVerdicts.Passed => "Superato",
TrialVerdicts.Rejected => "Non superato",
_ => Missing,
};
public static string Source(TrialData data) => data.Source == TrialSources.Research
? "storico di ricerca " + Venue(data.Venue)
: "barre raccolte di " + Venue(data.Venue);
public static string Venue(string venue) => venue switch
{
"okx" => "OKX",
"alpaca" => "Alpaca",
"binance" => "Binance",
EuroHistory.Venue => "Binance convertito in euro",
_ => venue,
};
public static string Symbols(IReadOnlyList<string> symbols) =>
symbols.Count <= 4 ? string.Join(", ", symbols) : string.Join(", ", symbols.Take(3)) + $" e altri {symbols.Count - 3}";
/// <summary>The value of a check, written in its unit.</summary>
public static string CheckValue(ReportCheck check, string currency) => check.Value is not { } v
? "non si applica"
: check.Unit switch
{
"money" => Format.Money((decimal)v, currency, withSign: true),
"percent" => Percent(v),
"count" => Format.Number((decimal)v),
_ => Number(v),
};
public static string CheckThreshold(ReportCheck check, string currency) => check.Comparison + " " + check.Unit switch
{
"money" => Format.Money((decimal)check.Threshold, currency),
"percent" => Percent(check.Threshold, 0),
"count" => Format.Number((decimal)check.Threshold),
_ => Number(check.Threshold),
};
/// <summary>What the engine did not do as asked, in words.</summary>
public static string Note(string reason) => reason switch
{
BacktestReasons.NoCash => "Acquisti ridotti per mancanza di liquidità",
BacktestReasons.NoPrice => "Ordini senza prezzo di apertura",
BacktestReasons.UnknownSymbol => "Strumenti chiesti dalla strategia ma assenti dai dati",
BacktestReasons.NoShortSelling => "Vendite allo scoperto rifiutate",
BacktestReasons.WrittenOff => "Residui sotto il minimo lasciati dopo un'uscita",
BacktestReasons.Dividend => "Dividendi incassati",
_ when reason.StartsWith(BacktestReasons.AdjustedPrefix, StringComparison.Ordinal) =>
"Decisioni cambiate da correttivi e rischio (" + ReasonTexts.Text(reason[BacktestReasons.AdjustedPrefix.Length..]).TrimEnd('.') + ")",
_ => "Ordini sotto il minimo dello strumento, non inviati",
};
}