Put the candidate strategies in observation without capital

Relative momentum among coins and all-time highs on stocks are now in the
code as candidates: they collect signals, have no share, no capital and no
order path, and every way forward refuses them. The crypto one ran the
protocol once and failed it (DSR 0.744, worst fall 35.3%), so it is archived
and decides nothing; the stock one waits for the Alpaca history.

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 19:52:24 +01:00
1 parent 9d1a4f2f69
commit fb0ab223a5
33 files changed
+1747 -82

No files matched your search

+50 -5
View File
@@ -34,11 +34,45 @@ internal sealed record StrategyCard(
}
/// <summary>
/// The Strategie screen (SPEC 12.3, 13.6, mockup 04): the path to real money in four stages, a card for each base
/// strategy with its requirements, and the ones in observation with the reason.
/// A candidate of SPEC 8.4 on the same screen: only the signals collected so far, or why it was discarded. It has no
/// capital, no card and no button.
/// </summary>
internal sealed record StrategiesView(IReadOnlyList<StrategyCard> Cards, bool LiveAllowed, IReadOnlyList<(Guid Id, string Name, string Broker)> LiveAccounts)
internal sealed record CandidateLine(StrategyStage Stage, string Name, int Signals, int Days)
{
public bool Archived => StageBook.IsArchived(Stage);
public bool Waiting => StrategiesView.IsWaiting(Stage);
public string Text
{
get
{
if (Archived)
{
return Stage.Qualification!.Verdict;
}
var signals = $"Raccoglie segnali senza fare ordini: {Signals} in {Days} {(Days == 1 ? "giorno" : "giorni")}.";
return signals + " " + (Waiting ? Stage.Qualification!.Verdict
: Days < StageBook.ObservationDays ? $"Servono almeno {StageBook.ObservationDays} giorni per giudicarla."
: $"I {StageBook.ObservationDays} giorni di segnali sono raccolti; resta senza capitale.");
}
}
}
/// <summary>
/// The Strategie screen (SPEC 12.3, 13.6, mockup 04): the path to real money in four stages, a card for each base
/// strategy with its requirements, and the ones in observation with the reason, the candidates of 8.4 among them.
/// </summary>
internal sealed record StrategiesView(IReadOnlyList<StrategyCard> Cards, IReadOnlyList<CandidateLine> Candidates, bool LiveAllowed, IReadOnlyList<(Guid Id, string Name, string Broker)> LiveAccounts)
{
/// <summary>Whether a strategy's backtest could not be run yet for lack of data: not the same as having failed it.</summary>
public static bool IsWaiting(StrategyStage stage)
{
ArgumentNullException.ThrowIfNull(stage);
return stage.Qualification is { Passed: false, PlanHash: null };
}
/// <summary>What each base strategy does, in four lines (SPEC 8).</summary>
public static readonly IReadOnlyDictionary<string, IReadOnlyList<string>> Rules = new Dictionary<string, IReadOnlyList<string>>(StringComparer.Ordinal)
{
@@ -82,9 +116,19 @@ internal sealed record StrategiesView(IReadOnlyList<StrategyCard> Cards, bool Li
await services.Db.ReadAsync(s => s.FirstOrDefaultAsync("SELECT symbol FROM instruments WHERE id = @id", r => r.Text("symbol"), ("id", instrument)), cancellationToken)
.ConfigureAwait(false) ?? "?";
var cards = new List<StrategyCard>();
var candidates = new List<CandidateLine>();
foreach (var stage in await stages.AllAsync(cancellationToken).ConfigureAwait(false))
{
if (!StrategyNames.Base.Any(b => b.Name == stage.Strategy))
if (StrategyNames.IsCandidate(stage.Strategy))
{
var observedFrom = stage.StageSince ?? clock.UtcNow;
var signals = await services.Db.ReadAsync(s => s.CountAsync("SELECT COUNT(*) FROM ml_features WHERE source = @l AND strategy = @s AND decided_at >= @f",
("l", Anubis.Learning.CaseSources.Live), ("s", stage.Strategy), ("f", observedFrom)), cancellationToken).ConfigureAwait(false);
candidates.Add(new CandidateLine(stage, StrategyNames.Label(stage.Strategy), (int)signals, Math.Max(0, (int)(clock.UtcNow - observedFrom).TotalDays)));
continue;
}
if (!StrategyNames.IsBase(stage.Strategy))
{
continue;
}
@@ -174,7 +218,8 @@ internal sealed record StrategiesView(IReadOnlyList<StrategyCard> Cards, bool Li
}
var live = accounts.Where(a => a.Environment == TradingEnvironments.Live).Select(a => (a.Id, a.Name, a.Broker)).ToList();
return new StrategiesView([.. cards.OrderBy(c => StrategyNames.Base.ToList().FindIndex(b => b.Name == c.Stage.Strategy))], liveAllowed, live);
return new StrategiesView([.. cards.OrderBy(c => StrategyNames.Base.ToList().FindIndex(b => b.Name == c.Stage.Strategy))],
[.. candidates.OrderBy(c => c.Archived).ThenBy(c => c.Name, StringComparer.Ordinal)], liveAllowed, live);
}
/// <summary>A requirement not met yet only because time has to pass or nothing could be measured so far.</summary>