Fix the defects of the Phase 4 review (refs #34 #35 #36)
ci / test (postgres) (push) Successful in 2m41s
ci / test (sqlite) (push) Successful in 1m56s
ci / test (postgres) (pull_request) Successful in 3m45s
ci / test (sqlite) (pull_request) Successful in 2m22s
ci / image (push) Successful in 1m10s
ci / image (pull_request) Successful in 13s

- An error of the database (PostgreSQL restarting) no longer stops the
  laboratory until the next start: the queue logs it, waits 30 seconds
  on the injectable clock and tries the same trial again.
- Buy and hold, the comparison of every report, buys an instrument
  whose history starts later at its first close, with the share kept
  free for it; before, it was never bought and the others took its
  weight. Its version goes to 2.
- The comparison page reads a and b as text: a malformed id shows
  "two finished tests needed" instead of an error page.
- A trial re-checks the hash of its plan before running and refuses a
  plan that no longer matches it.
- Parameters that count days take whole numbers only (10.5 would run
  as 10 and count twice in the DSR); the capital starts from 1, as the
  message says.

ADR 0010 says so, and corrects the estimated minimum of the research
history: 5 does refuse smaller orders, like the exchanges' minimums.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 10:17:18 +01:00
1 parent af7528560f
commit f278ff4f67
10 files changed
+158 -28

No files matched your search

+22
View File
@@ -222,6 +222,28 @@ public sealed class BacktestTests
Assert.IsEmpty(run.Decisions[0].Final);
}
[TestMethod]
[TestCategory(Category.Unit)]
public void BuyAndHoldKeepsTheShareOfAnInstrumentWhoseHistoryStartsLater()
{
// ETH has bars only from day 30: buy and hold buys it then, with half the equity, not never.
var data = new BacktestDataset(
[
new BacktestInstrument(BacktestData.Btc(), BacktestData.Walk(60, 3, start: 40_000, from: D1)),
new BacktestInstrument(BacktestData.Btc() with { Symbol = "ETH-EUR", BaseCurrency = "ETH" }, BacktestData.Walk(30, 5, start: 2_000, from: D1.AddDays(30))),
], "EUR");
var run = BacktestEngine.Run(new BuyAndHold(2), data);
Assert.HasCount(2, run.Fills);
var btc = run.Fills.Single(f => f.Symbol == "BTC-EUR");
var eth = run.Fills.Single(f => f.Symbol == "ETH-EUR");
Assert.AreEqual(D1.AddDays(1), btc.Day);
Assert.AreEqual(D1.AddDays(31), eth.Day);
Assert.AreEqual(0.4975, (double)(btc.Gross / run.InitialCapital), 0.005);
var before = run.Equity.Single(p => p.Day == D1.AddDays(30)).Equity;
Assert.AreEqual(0.4975, (double)(eth.Gross / before), 0.01);
Assert.IsTrue(run.Equity.All(e => e.Cash >= 0m));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void OneCycleRestartsFromARecordedBook()