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:
1 parent
9d1a4f2f69
commit
fb0ab223a5
33 files changed
+1747
-82
No files matched your search
@@ -14,18 +14,19 @@ namespace Anubis.Server;
|
||||
/// Binance daily archives (each checked against its SHA-256) and the ECB rates into the research history, converts
|
||||
/// them to euro, runs the protocol of <c>crypto_trend</c> on both universes and writes reports and outcome files.
|
||||
/// The stock strategies need the Alpaca history: without it their files say they wait, and they stay in observation.
|
||||
/// "anubis backtest candidates" does the same for the candidates of SPEC 8.4 and leaves the other files alone.
|
||||
/// </summary>
|
||||
internal static class BacktestCommand
|
||||
{
|
||||
private const string Usage =
|
||||
"Uso: anubis backtest base [--to AAAA-MM-GG] [--out docs/backtests] [--offline]\n" +
|
||||
"Uso: anubis backtest base|candidates [--to AAAA-MM-GG] [--out docs/backtests] [--offline]\n" +
|
||||
" --offline usa solo gli archivi già scaricati (i cambi BCE li scarica solo se mancano). Opzioni comuni: [--platform docker|desktop] [--data-dir <cartella>]";
|
||||
|
||||
public static async Task<int> RunAsync(string[] args, TextWriter? output = null, IReadOnlyDictionary<string, string?>? environment = null,
|
||||
HttpMessageHandler? handler = null)
|
||||
{
|
||||
output ??= Console.Out;
|
||||
if (args.Length < 1 || args[0] != "base")
|
||||
if (args.Length < 1 || args[0] is not ("base" or "candidates"))
|
||||
{
|
||||
await output.WriteLineAsync(Usage).ConfigureAwait(false);
|
||||
return 2;
|
||||
@@ -66,23 +67,30 @@ internal static class BacktestCommand
|
||||
var converted = await EuroHistory.ConvertAllAsync(store, rates, CancellationToken.None).ConfigureAwait(false);
|
||||
await output.WriteLineAsync($"Convertite in euro {converted.Count} coppie.").ConfigureAwait(false);
|
||||
|
||||
var outcome = await CryptoTrendProtocol.RunAsync(config.Data.Research, to, now, text => output.WriteLine(text), CancellationToken.None).ConfigureAwait(false);
|
||||
var candidates = args[0] == "candidates";
|
||||
var name = candidates ? StrategyNames.CryptoRelativeMomentum : StrategyNames.CryptoTrend;
|
||||
var outcome = candidates
|
||||
? await CandidateProtocol.RunCryptoAsync(config.Data.Research, to, now, text => output.WriteLine(text), CancellationToken.None).ConfigureAwait(false)
|
||||
: await CryptoTrendProtocol.RunAsync(config.Data.Research, to, now, text => output.WriteLine(text), CancellationToken.None).ConfigureAwait(false);
|
||||
var notes = DataNotes(outcome, rates);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, "crypto_trend.md"),
|
||||
ProtocolReport.Markdown(outcome, "crypto_trend", notes, "anubis backtest base --to " + to.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture))).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, "crypto_trend.outcome.json"), BacktestOutcomes.ToJson(outcome.Qualification)).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, name + ".md"),
|
||||
ProtocolReport.Markdown(outcome, name, notes, $"anubis backtest {args[0]} --to " + to.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture))).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, name + ".outcome.json"), BacktestOutcomes.ToJson(outcome.Qualification)).ConfigureAwait(false);
|
||||
foreach (var run in outcome.Runs)
|
||||
{
|
||||
// The full reports (curve, trades) stay with the data: the repository keeps the summary and the outcome.
|
||||
await File.WriteAllTextAsync(Path.Combine(config.Data.Research, "crypto_trend-" + run.Report.PlanHash[..12] + ".report.json"), run.Report.ToJson())
|
||||
await File.WriteAllTextAsync(Path.Combine(config.Data.Research, name + "-" + run.Report.PlanHash[..12] + ".report.json"), run.Report.ToJson())
|
||||
.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
foreach (var (strategy, name) in new[] { (StrategyNames.EquityMomentum, "Momentum azioni"), (StrategyNames.EquityMeanrev, "Ritorno alla media azioni") })
|
||||
(string Strategy, string Name, Qualification Waiting, IReadOnlyList<string> Lines)[] waiting = candidates
|
||||
? [(StrategyNames.StockAthBreakout, StrategyNames.Label(StrategyNames.StockAthBreakout), CandidateProtocol.StockWaiting(), CandidateProtocol.StockExplanation)]
|
||||
: [(StrategyNames.EquityMomentum, "Momentum azioni", EquityProtocol.Waiting(StrategyNames.EquityMomentum), EquityProtocol.Explanation),
|
||||
(StrategyNames.EquityMeanrev, "Ritorno alla media azioni", EquityProtocol.Waiting(StrategyNames.EquityMeanrev), EquityProtocol.Explanation)];
|
||||
foreach (var w in waiting)
|
||||
{
|
||||
var waiting = EquityProtocol.Waiting(strategy);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, strategy + ".md"), ProtocolReport.Waiting(strategy, name, waiting, EquityProtocol.Explanation)).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, strategy + ".outcome.json"), BacktestOutcomes.ToJson(waiting)).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, w.Strategy + ".md"), ProtocolReport.Waiting(w.Strategy, w.Name, w.Waiting, w.Lines)).ConfigureAwait(false);
|
||||
await File.WriteAllTextAsync(Path.Combine(outDir, w.Strategy + ".outcome.json"), BacktestOutcomes.ToJson(w.Waiting)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await output.WriteLineAsync((outcome.Qualification.Passed ? "Superato: " : "Non superato: ") + outcome.Qualification.Verdict).ConfigureAwait(false);
|
||||
|
||||
Reference in new issue
Block a user