The quarterly review judged the best variant of the grid instead of the one that trades: the plan now fixes the variant in use and the protocol measures that one, while the tries are still those of the grid. A failure while the history is prepared is a reason in the report and no longer stops the review, and a strategy whose protocol does not exist says so when its data are there. The volatility improvement compared books of different days and stages: the book keeps its stage and its previous day, and a case without a book valid on its day is left out. Fewer than six months give no interval, the others use the clustered error with the Student t. The restriction balance counts a case in the period in which its outcome became known, so no case is lost or counted twice between two reviews. The contact given to the SEC travels only on the client that never follows a redirect, so it cannot reach another site. refs #75 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
106 lines
5.0 KiB
C#
106 lines
5.0 KiB
C#
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",
|
|
_ => line.NoProtocol ? "Non riprovata" : "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.";
|
|
}
|