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
@@ -341,6 +341,95 @@ public sealed class BasketEngineTests
|
||||
Assert.AreEqual(VenueCosts.Etoro.Financing("EURUSD", Direction.Buy, 1_098.5m, 5), result.Financing);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void OnDailyBarsTheAccountStopPausesOnlyUntilTheServerDateChanges()
|
||||
{
|
||||
// Daily fixings at 00:00 UTC from Monday 5 January 2026, no spread and no cost. 100,000 EURUSD bought at 1.0000 on
|
||||
// Tuesday 20 (bar 11); Wednesday's bar (12) closes at 0.9910, on Thursday 22 at 00:00 UTC: open loss 900 / 10,000 = 9%,
|
||||
// the account stop fires. That moment is Wednesday 19:00 in New York, already server day Thursday, so the pause lasts
|
||||
// until Thursday 17:00 New York, 22:00 UTC. Thursday's bar (13) is decided at its close, Friday 00:00 UTC, after the
|
||||
// change: its signal (0.9800, z = −2.57) opens.
|
||||
double[] e = [.. BasketSynthetic.Alternate(1.0000, 1.0001, 10), 0.9990, 1.0000, 0.9910, 0.9800, 0.9800];
|
||||
var data = BasketSynthetic.Daily(new Dictionary<string, double[]> { ["EURUSD"] = e });
|
||||
|
||||
var result = Run(data, SingleRules(EurUsd, BasketMode.AsDocument) with { LotPer10k = 1m }, VenueCosts.None);
|
||||
|
||||
var stop = result.Events.Single(x => x.Reason == BasketReasons.AccountStop);
|
||||
Assert.AreEqual(BasketSynthetic.Midnight(new DateOnly(2026, 1, 22)), stop.At, "at the close of Wednesday's bar");
|
||||
Assert.AreEqual(new DateTimeOffset(2026, 1, 22, 22, 0, 0, TimeSpan.Zero), ServerClock.NextDayStart(stop.At));
|
||||
Assert.IsFalse(result.Events.Any(x => x.Reason == BasketReasons.PausedUntilNextDay), "Thursday's decision comes after the change");
|
||||
var reopened = result.Events.Single(x => x.Kind == BasketEventKinds.Open && x.At > stop.At);
|
||||
Assert.AreEqual(BasketSynthetic.Midnight(new DateOnly(2026, 1, 23)), reopened.At, "Thursday's signal opens at its close");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void AMandatoryStopOnOneLevelOfASinglePairBasketClosesTheOtherLevelsWithTheirOwnReason()
|
||||
{
|
||||
// EURUSD (spread 0.1 pip) signals on Monday 19 January 2026 and is bought on Tuesday at the ask 0.998505; Wednesday
|
||||
// closes at 0.9900, 86 pips under it with z = −2.78: an averaging, bought on Thursday at 0.989005. The venue's stops
|
||||
// at leverage 5 sit 10% under each entry: 0.8986545 and 0.8901045. Friday fixes at 0.8950, bid 0.894995: level 0's
|
||||
// stop is gone through at the open, level 1's is not. The basket's exit is the mandatory stop; level 1 closes at the
|
||||
// next execution as closed with it, not as a stop of its own, and nothing is an orphan leg (one pair).
|
||||
double[] e = [.. BasketSynthetic.Alternate(1.0000, 1.0002, 10), 0.9985, 0.9985, 0.9900, 0.9890, 0.8950, 0.8950, 0.8950];
|
||||
var data = BasketSynthetic.Daily(new Dictionary<string, double[]> { ["EURUSD"] = e });
|
||||
|
||||
var result = Run(data, SingleRules(EurUsd, BasketMode.AsDocument) with { Distance = 50m }, VenueCosts.Etoro);
|
||||
|
||||
var trace = result.Traces.Single();
|
||||
Assert.AreEqual(2, trace.Levels);
|
||||
Assert.AreEqual(BasketReasons.MandatoryStop, trace.ExitReason);
|
||||
Assert.AreEqual(BasketReasons.MandatoryStop, result.Run.Baskets.Single().ExitReason);
|
||||
CollectionAssert.AreEqual(new[] { BasketReasons.MandatoryStop, BasketReasons.ClosedWithStop }, trace.Positions.Select(p => p.ExitReason).ToArray());
|
||||
CollectionAssert.AreEqual(new int?[] { 14, 15 }, trace.Positions.Select(p => p.ExitBar).ToArray());
|
||||
Assert.AreEqual(0.894995m, trace.Positions[0].ExitPrice, "the bid of Friday's open");
|
||||
Assert.AreEqual(1, result.Run.Fills.Count(f => f.Reason == BasketReasons.ClosedWithStop));
|
||||
Assert.AreEqual(1, result.Run.Notes.Count(n => n.Reason == BasketReasons.MandatoryStop));
|
||||
Assert.AreEqual(1, result.Run.Notes.Count(n => n.Reason == BasketReasons.ClosedWithStop));
|
||||
Assert.AreEqual(0, result.Run.Notes.Count(n => n.Reason == BasketReasons.OrphanLeg));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void TheFeesOfARunIncludeTheFinancingOfPositionsStillOpen()
|
||||
{
|
||||
// EURUSD bought on Tuesday 20 January 2026 at 1.098505 and never sold: still open at the end. Its financing has left the
|
||||
// cash at every rollover, so it is in the fees of the run although no closing fill carries it.
|
||||
double[] e = [.. BasketSynthetic.Alternate(1.1000, 1.1002, 10), .. Enumerable.Repeat(1.0985, 10)];
|
||||
var data = BasketSynthetic.Daily(new Dictionary<string, double[]> { ["EURUSD"] = e });
|
||||
|
||||
var result = Run(data, SingleRules(EurUsd, BasketMode.AsDocument), VenueCosts.Etoro);
|
||||
|
||||
Assert.AreEqual(BasketReasons.End, result.Run.Baskets.Single().ExitReason);
|
||||
Assert.IsTrue(result.Financing > 0m, $"financing {result.Financing}");
|
||||
Assert.AreEqual(result.Commission + result.Financing, result.Run.Fees);
|
||||
Assert.AreEqual(result.Run.Fills.Sum(f => f.Fee) + result.Financing, result.Run.Fees, "one opening fill: its commission, plus the financing");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void AsLiveTheCurrencyCapStopsNewBasketsNotTheAveragingsOfAnOpenOne()
|
||||
{
|
||||
// 10,000 EURUSD (100,000 of capital) bought at 0.9985, then three averagings 15 pips apart or more, each with z ≤ −2:
|
||||
// at 0.9960 (z −2.47), 0.9930 (−2.12) and 0.9860 (−2.26). Long EURUSD alone is long euro and short dollar, two entries
|
||||
// and more once averaged: the cap of two entries per currency is for a new basket (plan, section 5), never for the
|
||||
// levels of one already open. Prudente makes its three averagings; Fedele writes no note about them.
|
||||
double[] e = [.. BasketSynthetic.Alternate(1.0000, 1.0002, 10), 0.9985, 0.9985, 0.9960, 0.9960, 0.9930, 0.9930, 0.9860, 0.9860, 0.9860];
|
||||
var data = BasketSynthetic.Daily(new Dictionary<string, double[]> { ["EURUSD"] = e });
|
||||
|
||||
foreach (var profile in BasketProfiles.All)
|
||||
{
|
||||
var result = Run(data, SingleRules(EurUsd, BasketMode.AsLive) with { Distance = 15m, Profile = profile }, VenueCosts.None, 100_000m);
|
||||
|
||||
var trace = result.Traces.Single();
|
||||
Assert.AreEqual(4, trace.Levels, profile.Name);
|
||||
CollectionAssert.AreEqual(new[] { 11, 13, 15, 17 }, trace.Positions.Select(p => p.EntryBar).ToArray(), profile.Name);
|
||||
Assert.AreEqual(0, result.Events.Count(x => x.Reason == BasketReasons.CurrencyExposure), profile.Name);
|
||||
Assert.AreEqual(0, result.Run.Notes.Count(n => n.Reason == BasketReasons.CurrencyExposure), profile.Name);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Unit)]
|
||||
public void TheRollingRvolEqualsTheReference()
|
||||
|
||||
Reference in new issue
Block a user