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>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 20:59:20 +01:00
1 parent 79bb194de0
commit 2257c3e16c
34 files changed
+2308 -87

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
using Anubis.Backtest;
using Anubis.Core;
using Anubis.Learning;
using Anubis.Trading;
namespace Anubis.Server;
/// <summary>A row of the balance of the restrictions: this period and since the start.</summary>
internal sealed record ReviewRestriction(string Name, RestrictionLine? Period, RestrictionLine? Ever);
/// <summary>A base rate before and after a review.</summary>
internal sealed record ReviewRate(string Name, string Before, string After);
/// <summary>How the quarterly review (SPEC 12.2) is written for the user.</summary>
internal static class ReviewView
{
public static string Verdict(ReviewLine line) => line.Verdict switch
{
ReviewVerdicts.Passed => "Superata",
ReviewVerdicts.Rejected => "Non superata",
ReviewVerdicts.Error => "Non riuscita",
_ => "In attesa dei dati",
};
public static string? VerdictClass(ReviewLine line) => line.Verdict switch
{
ReviewVerdicts.Passed => "gain",
ReviewVerdicts.Rejected or ReviewVerdicts.Error => "loss",
_ => null,
};
/// <summary>What changed for the strategy, as a sentence.</summary>
public static string Action(ReviewLine line)
{
var text = QuarterlyReview.ActionText(line);
return char.ToUpperInvariant(text[0]) + text[1..];
}
/// <summary>How the strategy did live, in the words of its stage.</summary>
public static IReadOnlyList<string> Live(ReviewLine line, IReadOnlyDictionary<string, double> rates)
{
var lines = new List<string>();
if (line.Stage == StrategyStages.Observation)
{
lines.Add(line.Signals == 0 ? "Nessun segnale chiuso dal vivo."
: $"{Signals(line.Signals)}, in guadagno {LabText.Percent((double)line.Won / line.Signals, 0)}" + (rates.TryGetValue(line.Strategy, out var rate) ? $" (di solito {LabText.Percent(rate, 0)})." : "."));
return lines;
}
if (line.Live is not { } f)
{
return ["Niente da confrontare."];
}
lines.Add($"Risultato {Fraction(f.Result, sign: true)}" + (line.BacktestOverSameDays is { } b ? $"; il backtest negli stessi giorni circa {LabText.Percent(b, 1, withSign: true)}." : "."));
lines.Add($"Calo massimo {Fraction(f.Fall)}" + (line.ExpectedFall is { } e ? $", atteso {Fraction(e)}." : "."));
lines.Add($"Scostamento dei prezzi {Bp(f.SlippageBp)}" + (line.ExpectedSlippageBp is { } s ? $", atteso {Bp(s)}." : "."));
lines.Add($"Operazioni chiuse {f.Trades}" + (f.OneStep is { } step ? $"; decisioni identiche al backtest del giorno dopo {Fraction(1m - step)}." : "."));
return lines;
}
private static string Signals(int count) => count == 1 ? "1 segnale chiuso" : $"{count} segnali chiusi";
private static string Fraction(decimal? value, bool sign = false) => value is { } v ? LabText.Percent((double)v, 1, sign) : LabText.Missing;
private static string Bp(decimal? value) => value is { } v ? Format.Quantity(Math.Round(v, 1)) + " punti base" : LabText.Missing;
public static IReadOnlyList<ReviewRate> Rates(ReviewReport report) =>
[.. report.RatesBefore.Keys.Union(report.RatesAfter?.Keys ?? []).Order(StringComparer.Ordinal).Select(s => new ReviewRate(StrategyNames.Label(s, withMarket: true),
report.RatesBefore.TryGetValue(s, out var before) ? LabText.Percent(before) : LabText.Missing,
(report.RatesAfter ?? report.RatesBefore).TryGetValue(s, out var after) ? LabText.Percent(after) : LabText.Missing))];
public static IReadOnlyList<ReviewRestriction> Restrictions(ReviewReport report) =>
[.. RestrictionBalance.Codes
.Select(c => new ReviewRestriction(RestrictionBalance.Label(c), report.Restrictions.Lines.FirstOrDefault(l => l.Code == c), report.RestrictionsEver.Lines.FirstOrDefault(l => l.Code == c)))
.Where(r => r.Period is not null || r.Ever is not null)];
/// <summary>The cases of a row that gave no amount, in words.</summary>
public static string Rest(RestrictionLine? line)
{
if (line is null)
{
return LabText.Missing;
}
var parts = new List<string>();
void Add(int count, string one, string many)
{
if (count > 0)
{
parts.Add(count == 1 ? "1 " + one : $"{count} {many}");
}
}
Add(line.Open, "ancora aperta", "ancora aperte");
Add(line.Delayed, "solo rimandata", "solo rimandate");
Add(line.NeverStarted, "mai partita", "mai partite");
Add(line.Increases, "aumento senza esito", "aumenti senza esito");
return parts.Count == 0 ? LabText.Missing : string.Join(", ", parts);
}
public static string Running(Review review) => review.Status == ReviewStatuses.Preparing
? $"La revisione del {review.Title} aspetta gli archivi dei prezzi fino al {LabText.Day(review.Through)}: ci riprovo ogni notte, fino al {QuarterlyReview.LastDay} del mese."
: $"La revisione del {review.Title} è in corso: i test sono nell'elenco qui sotto.";
}