Fix the review findings of the basket engine, command and report
The independent review of Phase 14 found rules the engine applied differently from the decisions, numbers the report labelled wrongly and a command that left a trial "running" when interrupted. Engine: - The pause after the 9% account stop is read at the decision moment (the bar's close), like every other gate: on daily bars it no longer blocks one day past the server date change. - In a one-pair basket, a level closed by the venue's mandatory stop closes the other levels at the next execution with their own reason, closed_with_stop (counted and labelled in the report); the basket's exit stays mandatory_stop, and a two-leg basket keeps orphan_leg. - The cap of two entries per currency applies to new baskets only, never to the averagings of an open basket, and every leg is valued at the current mid: a Prudente long basket "come dal vivo" now makes its three averagings and Fedele writes no note on them. - The surrogate of the control chains on the mid when the source has an ask, so each mid change keeps its size and the spread stays around the mid instead of moving the mid by a spread at each change of sign. - The financing already charged on positions still open at the end is part of the run's fees (BacktestRun.AccruedFees, zero for the daily engine, kept in stored unit outcomes). Report: the fee row says what it holds (commission and financing, the spread is in the prices) and the cost-stress text matches what the multiplier scales; baskets still open at the end are labelled as such and left out of the share closed at the target; refusal labels say what the engine checks; the ECB-price and cost limitations are no longer printed twice; every count has the Italian thousands separator. Command: Ctrl+C or SIGTERM cancels the run; the trial is recorded as failed with "Prova interrotta prima della fine: rilancia «anubis backtest baskets»." and the command exits 1; a trial that cannot start is failed instead of thrown, and an unexpected error ends with an Italian line, never a stack trace. The laboratory fails a leftover basket trial with an accurate message instead of "Strategia non più disponibile". The Table 6.5 test comment no longer claims each price is the only one that fits the row. The real report is regenerated on the same data and database as the first run, which now counts as a prior trial. refs #127 #129 #131 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3bee136c74
commit
a8defde572
15 files changed
+488
-143
No files matched your search
@@ -127,29 +127,54 @@ public sealed class BasketReportTests
|
||||
new("EURUSD-USDCHF", opened.AddDays(3), opened.AddDays(4), 1_000m, 2, ["EURUSD", "USDCHF"], "orphan_leg", -12m),
|
||||
new("AUDNZD", opened.AddDays(5), opened.AddDays(9), 1_000m, 1, ["AUDNZD"], "target", 9m),
|
||||
new("AUDNZD", opened.AddDays(10), opened.AddDays(12), 1_000m, 1, ["AUDNZD"], "target", 8m),
|
||||
new("GBPUSD", opened.AddDays(20), null, 1_000m, 1, ["GBPUSD"], null, -3m),
|
||||
new("GBPUSD", opened.AddDays(20), null, 1_000m, 1, ["GBPUSD"], BasketReasons.End, -3m),
|
||||
];
|
||||
var notes = new Dictionary<string, int>(StringComparer.Ordinal)
|
||||
{
|
||||
["orphan_leg"] = 2,
|
||||
["closed_with_stop"] = 3,
|
||||
["gate_open_loss"] = 5,
|
||||
["weird_code"] = 1,
|
||||
};
|
||||
var two = Section(BasketReport.Markdown(Input(trial with { Report = trial.Report with { Notes = notes, Baskets = baskets } })), "## Prova del motore a panieri");
|
||||
StringAssert.Contains(two, "Gambe rimaste sole: 2");
|
||||
StringAssert.Contains(two, "Posizioni chiuse insieme a un livello fermato dallo stop obbligatorio: 3 (");
|
||||
StringAssert.Contains(two, "| stop obbligatorio della piattaforma | 1 |");
|
||||
StringAssert.Contains(two, "| gamba rimasta sola dopo uno stop obbligatorio | 1 |");
|
||||
StringAssert.Contains(two, "| obiettivo raggiunto | 2 |");
|
||||
StringAssert.Contains(two, "| ancora aperto alla fine | 1 |");
|
||||
StringAssert.Contains(two, "| ancora aperto alla fine (valutato agli ultimi prezzi) | 1 |");
|
||||
StringAssert.Contains(two, "Panieri della variante giudicata: 5.");
|
||||
StringAssert.Contains(two, "perdita aperta oltre il 2%");
|
||||
StringAssert.Contains(two, "| perdita aperta pari o oltre il 2%: nessun paniere nuovo | 5 |");
|
||||
StringAssert.Contains(two, "| `weird_code` | 1 |");
|
||||
StringAssert.Contains(two, "Chiusi all'obiettivo: 50,0%");
|
||||
Assert.IsFalse(two.Contains("`closed_with_stop`", StringComparison.Ordinal), "closes, not refusals");
|
||||
Assert.IsFalse(two.Contains("fine del periodo", StringComparison.Ordinal), "a basket open at the end was not closed");
|
||||
|
||||
// Two at the target out of the four closed: the one still open at the end is not counted among the closed.
|
||||
StringAssert.Contains(two, "Chiusi all'obiettivo: 50,0% dei panieri chiusi");
|
||||
|
||||
var none = Section(BasketReport.Markdown(Input(trial with { Report = trial.Report with { Notes = new Dictionary<string, int>(), Baskets = [] } })), "## Prova del motore a panieri");
|
||||
StringAssert.Contains(none, "Gambe rimaste sole: 0");
|
||||
StringAssert.Contains(none, "Chiusure d'ufficio per margine insufficiente: 0");
|
||||
StringAssert.Contains(none, "Stop sul valore del conto: 0");
|
||||
StringAssert.Contains(none, "Posizioni chiuse insieme a un livello fermato dallo stop obbligatorio: 0 (");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void TheLimitsAreWrittenOnce()
|
||||
{
|
||||
// With a trial, the engine's own limitations already speak of the ECB prices and of the costs: the report does not
|
||||
// repeat its own version of them. Without one, it writes them.
|
||||
const string Prices = "- I prezzi sono i cambi di riferimento della BCE, uno al giorno";
|
||||
const string Costs = "- I costi sono quelli di eToro letti il 02/12/2026";
|
||||
var withTrial = Section(BasketReport.Markdown(Input(_trial.Value)), "## Cosa il backtest non rappresenta");
|
||||
var without = Section(BasketReport.Markdown(Input(null, "Nessuna prova.")), "## Cosa il backtest non rappresenta");
|
||||
|
||||
StringAssert.Contains(withTrial, "- Motore finto della prova.");
|
||||
Assert.AreEqual(0, Count(withTrial, Prices), withTrial);
|
||||
Assert.AreEqual(0, Count(withTrial, Costs), withTrial);
|
||||
Assert.AreEqual(1, Count(without, Prices), without);
|
||||
Assert.AreEqual(1, Count(without, Costs), without);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -174,14 +199,33 @@ public sealed class BasketReportTests
|
||||
[BasketReasons.RvolFilter] = 1,
|
||||
[BasketReasons.CorrelationLow] = 1,
|
||||
[BasketReasons.SwitchTripped] = 1,
|
||||
[BasketReasons.MaxOpenBaskets] = 1,
|
||||
[BasketReasons.MaxOpenBaskets] = 1_569,
|
||||
};
|
||||
var text = Section(BasketReport.Markdown(Input(trial with { Report = trial.Report with { Notes = notes } })), "## Prova del motore a panieri");
|
||||
StringAssert.Contains(text, "| troppe posizioni aperte per la piattaforma | 3 |");
|
||||
var report = trial.Report with
|
||||
{
|
||||
Notes = notes,
|
||||
LookAhead = trial.Report.LookAhead with { Decisions = 4_817 },
|
||||
Overfitting = new ReportOverfitting(16, 12_870, 4, 0.25),
|
||||
};
|
||||
var text = Section(BasketReport.Markdown(Input(trial with { Report = report })), "## Prova del motore a panieri");
|
||||
|
||||
// Each label says what the engine does (BasketSimulation, ReasonCatalog).
|
||||
StringAssert.Contains(text, "| si supererebbero 9 posizioni aperte (conto Demo condiviso) | 3 |");
|
||||
StringAssert.Contains(text, "| fuori dalla finestra oraria | 4 |");
|
||||
StringAssert.Contains(text, "| perdita aperta pari o oltre il 2%: nessun paniere nuovo | 1 |");
|
||||
StringAssert.Contains(text, "| volatilità recente oltre il doppio del normale, o non ancora nota | 1 |");
|
||||
StringAssert.Contains(text, "| perdita del giorno pari o oltre il 2%: niente ingressi né mediazioni per 24 ore | 1 |");
|
||||
StringAssert.Contains(text, "| correlazione tra le gambe sotto 0,6 sul segno atteso, o non ancora nota | 1 |");
|
||||
StringAssert.Contains(text, "| esposizione netta su una valuta oltre due ingressi (solo panieri nuovi) | 1 |");
|
||||
StringAssert.Contains(text, "| dimensione ridotta a metà o a un quarto (perdita della settimana o calo dal massimo) | 1 |");
|
||||
StringAssert.Contains(text, "Posizioni chiuse dallo stop obbligatorio della piattaforma: 6.");
|
||||
var refusals = text[text.IndexOf("**Ingressi e mediazioni fermati o annotati**", StringComparison.Ordinal)..];
|
||||
Assert.IsFalse(refusals.Contains('`', StringComparison.Ordinal), "a code without a label: " + refusals);
|
||||
|
||||
// Counts are grouped the Italian way, like every other number of the report.
|
||||
StringAssert.Contains(text, "| già aperto il numero massimo di panieri | 1.569 |");
|
||||
StringAssert.Contains(text, "4.817 decisioni");
|
||||
StringAssert.Contains(text, "su 12.870 combinazioni");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@@ -193,7 +237,9 @@ public sealed class BasketReportTests
|
||||
StringAssert.Contains(text, "zero (nessuna operazione)");
|
||||
Assert.IsFalse(text.Contains("comprare e tenere", StringComparison.OrdinalIgnoreCase));
|
||||
Assert.IsFalse(text.Contains("buy and hold", StringComparison.OrdinalIgnoreCase));
|
||||
StringAssert.Contains(text, "**Sensibilità ai costi** (commissione, differenziale e finanziamento pagato moltiplicati insieme)");
|
||||
StringAssert.Contains(text, "**Sensibilità ai costi** (differenziale, commissioni e finanziamento a carico moltiplicati insieme; gli accrediti di finanziamento restano uguali)");
|
||||
StringAssert.Contains(text, "| Commissioni e finanziamento pagati (il differenziale è già nei prezzi) | ");
|
||||
Assert.IsFalse(text.Contains("| Costi pagati |", StringComparison.Ordinal));
|
||||
StringAssert.Contains(text, "| ×2 |");
|
||||
StringAssert.Contains(text, "| ×3 |");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user