Fix what a second independent reading of the Phase 8 fixes found
ci / test (postgres) (push) Failing after 6m9s
ci / test (sqlite) (push) Successful in 7m6s
ci / image (push) Skipped
ci / test (postgres) (pull_request) Successful in 5m51s
ci / test (sqlite) (pull_request) Successful in 7m3s
ci / image (pull_request) Successful in 1m51s
ci / test (postgres) (push) Failing after 6m9s
ci / test (sqlite) (push) Successful in 7m6s
ci / image (push) Skipped
ci / test (postgres) (pull_request) Successful in 5m51s
ci / test (sqlite) (pull_request) Successful in 7m3s
ci / image (pull_request) Successful in 1m51s
One funded signal was enough to start the model for good, because the interval of a few cases had no width: it now takes a hundred, weighed among themselves. A computer always off at 03:00 never made the night of the model: a job to make up for counts from the first start that knows it, and the night waits for the bars of the absence. Stories are seen as they were when the decision was due, a report already out does not close a label, an undone promotion starts the trial again, and the trade card finds the estimate of an example born earlier. ADR 0018 point 18 has the list; each defect has its test. refs #67 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0b0f4a5e75
commit
c7e462b6f4
18 files changed
+371
-26
No files matched your search
@@ -377,6 +377,11 @@ internal sealed partial class AnubisHost(
|
||||
lastDues[name] = due;
|
||||
}
|
||||
|
||||
if (!options.Demo)
|
||||
{
|
||||
await StartCountingAsync([.. SchedulerJobs(backups)], lastDues, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (_sampler is not null)
|
||||
{
|
||||
await _sampler.TakeAsync(SampleKinds.Start, cancellationToken).ConfigureAwait(false);
|
||||
@@ -506,13 +511,31 @@ internal sealed partial class AnubisHost(
|
||||
!options.Demo && (overrides is null ? true : overrides.Trading == true) &&
|
||||
environment.GetValueOrDefault("ANUBIS_TRADING") is not ("0" or "off" or "false");
|
||||
|
||||
private void StartScheduler(Scheduler scheduler, Backups backups, Dictionary<string, DateTimeOffset> lastDues)
|
||||
private IEnumerable<ScheduledJob> SchedulerJobs(Backups backups)
|
||||
{
|
||||
// A backup missed while the bot was off is taken once at the restart, whenever it comes (SPEC 5.6).
|
||||
var backup = new ScheduledJob("backup", "Salvataggio del database", Schedule.Daily(new TimeOnly(3, 30), Config.TimeZone),
|
||||
async ct => await backups.TakeAsync(_db!, "notturno", ct).ConfigureAwait(false))
|
||||
{ MaxLateness = TimeSpan.FromHours(2), CatchUpWithin = TimeSpan.FromDays(3650) };
|
||||
foreach (var job in new[] { backup }.Concat(_sampler is { } sampler ? new[] { sampler.Job() } : []).Concat(_market?.Jobs() ?? []).Concat(_trading?.Jobs() ?? []).Concat(_telegram?.Jobs() ?? []))
|
||||
return new[] { backup }.Concat(_sampler is { } sampler ? new[] { sampler.Job() } : []).Concat(_market?.Jobs() ?? []).Concat(_trading?.Jobs() ?? []).Concat(_telegram?.Jobs() ?? []);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A job to make up for after an absence counts from the first start that knows it. Otherwise a computer always off at
|
||||
/// its hour would never make it: without a first run there would be no run to find missed (SPEC 5.6).
|
||||
/// </summary>
|
||||
private Task StartCountingAsync(IReadOnlyList<ScheduledJob> jobs, Dictionary<string, DateTimeOffset> lastDues, CancellationToken cancellationToken) => _db!.WriteAsync(async s =>
|
||||
{
|
||||
foreach (var job in jobs.Where(j => j.CatchUpWithin is not null && !lastDues.ContainsKey(j.Name)))
|
||||
{
|
||||
await s.ExecuteAsync("INSERT INTO jobs (id, name, description, last_due_at, created_at, updated_at) VALUES (@id, @n, @d, @now, @now, @now) ON CONFLICT (name) DO NOTHING", cancellationToken,
|
||||
("id", Ids.NewId(clock)), ("n", job.Name), ("d", job.Description), ("now", clock.UtcNow)).ConfigureAwait(false);
|
||||
}
|
||||
}, cancellationToken);
|
||||
|
||||
private void StartScheduler(Scheduler scheduler, Backups backups, Dictionary<string, DateTimeOffset> lastDues)
|
||||
{
|
||||
foreach (var job in SchedulerJobs(backups))
|
||||
{
|
||||
scheduler.Add(job, lastDues.TryGetValue(job.Name, out var due) ? due : null);
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ internal sealed record LearningView
|
||||
Missing = state.ActivatedAt is null && activation.Enough ? Missings(activation) : [],
|
||||
LastTraining = last is null ? "mai" : $"{LongDay(DayOf(last.TrainedAt), now)}, versione {last.Version}",
|
||||
Bands = bands,
|
||||
BandsText = bands.Count == 0 ? "Nessuna stima ha ancora un esito." : BandsWords(bands),
|
||||
BandsText = bands.Count == 0 ? "Nessuna stima ha ancora un esito." : BandsWords(bands, history ? null : activation.CalibrationError),
|
||||
BandsFromHistory = history && bands.Count > 0,
|
||||
Champion = Column(champion, now),
|
||||
Challenger = Column(challenger, now),
|
||||
@@ -341,7 +341,11 @@ internal sealed record LearningView
|
||||
: $"Nessuna fascia di probabilità ha ancora {Judge.BandMin} casi.");
|
||||
}
|
||||
|
||||
if (!check.Improves)
|
||||
if (check.Funded < ActivationCheck.FundedNeeded)
|
||||
{
|
||||
missing.Add($"Servono almeno {ActivationCheck.FundedNeeded} segnali di strategie con un capitale, anche in simulazione: per ora {(check.Funded == 1 ? "è uno" : $"sono {Format.Number(check.Funded)}")}.");
|
||||
}
|
||||
else if (!check.Improves)
|
||||
{
|
||||
missing.Add("Non è ancora provato che, filtrando lui, si guadagni di più per operazione proposta: la differenza può essere caso.");
|
||||
}
|
||||
@@ -353,8 +357,11 @@ internal sealed record LearningView
|
||||
|
||||
private static LearningBand Band(CalibrationBand b) => new((int)Math.Round(b.From * 100), (int)Math.Round(b.To * 100), b.Cases, Round(b.Estimated * 100, 1), Round(b.Observed * 100, 1));
|
||||
|
||||
/// <summary>The sentence under the chart: the highest band that counts, whether it is well calibrated, the bands that do not count.</summary>
|
||||
public static string BandsWords(IReadOnlyList<LearningBand> bands)
|
||||
/// <summary>
|
||||
/// The sentence under the chart: the highest band that counts, whether it is well calibrated, the bands that do not
|
||||
/// count. <paramref name="measured"/> is the error of the criterion to start counting (11.5), when it is the judge.
|
||||
/// </summary>
|
||||
public static string BandsWords(IReadOnlyList<LearningBand> bands, double? measured = null)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(bands);
|
||||
var solid = bands.Where(b => b.Solid).ToList();
|
||||
@@ -363,10 +370,10 @@ internal sealed record LearningView
|
||||
return $"Nessuna fascia ha ancora {Judge.BandMin} casi: troppo pochi per contarci.";
|
||||
}
|
||||
|
||||
var error = solid.Sum(b => b.Cases * Math.Abs(b.Estimated - b.Observed)) / solid.Sum(b => b.Cases);
|
||||
var error = measured is { } known ? Round(known * 100, 1) : solid.Sum(b => b.Cases * Math.Abs(b.Estimated - b.Observed)) / solid.Sum(b => b.Cases);
|
||||
var best = solid[^1];
|
||||
var text = $"Quando stima tra il {best.From} e il {best.To}%, è andata bene il {Format.Number(best.Observed)}% delle volte: " +
|
||||
(error < (decimal)ActivationCheck.MaxCalibrationError * 100 ? "è ben tarato." : $"non è ancora ben tarato, in media sbaglia di {Format.Number(error, 1)} punti.");
|
||||
((measured is { } exact ? exact < ActivationCheck.MaxCalibrationError : error < (decimal)ActivationCheck.MaxCalibrationError * 100) ? "è ben tarato." : $"non è ancora ben tarato, in media sbaglia di {Format.Number(error, 1)} punti.");
|
||||
var above = bands.Where(b => !b.Solid && b.From >= best.To).ToList();
|
||||
var below = bands.Where(b => !b.Solid && b.To <= solid[0].From).ToList();
|
||||
var between = bands.Where(b => !b.Solid).Except(above).Except(below).Sum(b => b.Cases);
|
||||
|
||||
@@ -77,7 +77,7 @@ internal static class ReasonTexts
|
||||
var applied = Number("applied") ?? 1;
|
||||
if (applied < 1)
|
||||
{
|
||||
return applied > 0 ? string.Create(it, $"{said}: acquisto ridotto al {applied * 100:0}%") : said + ": acquisto non fatto";
|
||||
return applied > 0 ? string.Create(it, $"{said}: acquisto ridotto al {Math.Clamp(Math.Round(applied * 100), 1, 99):0}%") : said + ": acquisto non fatto";
|
||||
}
|
||||
|
||||
bool Is(string name) => json.RootElement.TryGetProperty(name, out var value) && value.ValueKind == JsonValueKind.True;
|
||||
|
||||
@@ -180,9 +180,9 @@ internal sealed record TradesView(
|
||||
("s", t.Strategy), ("sym", t.Symbol), ("f", t.OpenedAt.AddDays(-1)), ("t", t.ClosedAt.AddMinutes(5))).ConfigureAwait(false);
|
||||
|
||||
// The example may be older than the purchase: proposed, held back, and bought days later. Same example, same estimate.
|
||||
var m = d.Any(x => x.Stage == DecisionStages.Model) ? [] : await s.QueryAsync(
|
||||
var m = await s.QueryAsync(
|
||||
"SELECT d.outcome, d.data FROM decisions d JOIN ml_features f ON f.decision_id = d.decision_id AND f.symbol = d.symbol LEFT JOIN ml_labels l ON l.feature_id = f.id " +
|
||||
"WHERE d.stage = @st AND d.strategy = @s AND d.symbol = @sym AND d.created_at <= @t AND (l.closed_day IS NULL OR l.closed_day > @o) ORDER BY d.created_at DESC LIMIT 1",
|
||||
"WHERE d.stage = @st AND d.strategy = @s AND d.symbol = @sym AND d.created_at <= @t AND (l.closed_day IS NULL OR l.closed_day >= @o) ORDER BY d.created_at DESC LIMIT 1",
|
||||
r => (Outcome: r.Text("outcome"), Data: r.TextOrNull("data")), ("st", DecisionStages.Model), ("s", t.Strategy), ("sym", t.Symbol), ("t", t.OpenedAt.AddMinutes(5)),
|
||||
("o", DateOnly.FromDateTime(t.OpenedAt.UtcDateTime).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture))).ConfigureAwait(false);
|
||||
return (e, d, m);
|
||||
@@ -200,7 +200,10 @@ internal sealed record TradesView(
|
||||
: sell.Purpose is "stop" or "protective" ? "stop" : null;
|
||||
decimal? entrySlip = buy.Reference is > 0m && t.BoughtQuantity > 0m ? Math.Round(((t.BoughtValue / t.BoughtQuantity) / buy.Reference.Value - 1m) * 10_000m, 1) : null;
|
||||
decimal? exitSlip = sell.Reference is > 0m && t.SoldQuantity > 0m ? Math.Round((1m - (t.SoldValue / t.SoldQuantity) / sell.Reference.Value) * 10_000m, 1) : null;
|
||||
List<WhyLine> bought = [.. Lines(buy.Key), .. earlier.SelectMany(m => ReasonTexts.Stage(DecisionStages.Model, m.Outcome, [], m.Data))];
|
||||
|
||||
// The decision of the purchase has its own line when the example was born with it.
|
||||
var own = buy.Key is not null && byKey.TryGetValue(buy.Key, out var entryRows) && entryRows.Any(r => r.Stage == DecisionStages.Model);
|
||||
List<WhyLine> bought = [.. Lines(buy.Key), .. (own ? [] : earlier).SelectMany(m => ReasonTexts.Stage(DecisionStages.Model, m.Outcome, [], m.Data))];
|
||||
return (bought, sold, entrySlip, exitSlip, code);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user