Review the base strategies every three months
Every quarter the base strategies are tried again on the longer history with the slippage in force, compared with how they did live, and the report is published in the laboratory with the base rates measured again and the balance of the restrictions of 10.5. In observation the outcome replaces the old one and a strategy that passed goes to simulation after its 90 days; with capital nothing moves but the demotion condition of 12.3. A restart halfway goes on and the review concludes once; the outcome of a review survives a restart with an older build. refs #74 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79bb194de0
commit
2257c3e16c
34 files changed
+2308
-87
No files matched your search
@@ -589,6 +589,82 @@ public sealed class RiskEngineTests
|
||||
Assert.AreEqual(RiskReasons.LiveNotConfirmed, (await live.Manager.SubmitAsync(Buy(s, 0.001m), _none)).Refusal);
|
||||
}
|
||||
|
||||
private static async Task<AccountContext> ReducedAsync(Setup s, Func<Qualification, Qualification>? change = null)
|
||||
{
|
||||
var live = await s.Rig.AccountAsync(Venues.Okx, TradingEnvironments.Live, "OKX reale (finto)");
|
||||
await s.Rig.Ledger.RecordCapitalAsync(live.AccountId, StrategyNames.CryptoTrend, 2_500m, "EUR", "test", _none);
|
||||
await RequirementsMetAsync(s);
|
||||
await s.Stages.ConfirmLiveAsync(new LiveConfirmation(StrategyNames.CryptoTrend, live.AccountId, StageBook.Phrase(StrategyNames.CryptoTrend, StrategyStages.Reduced), Password, null, "utente"), _none);
|
||||
if (change is not null)
|
||||
{
|
||||
var q = change((await s.Stages.GetAsync(StrategyNames.CryptoTrend, _none))!.Qualification!);
|
||||
await s.Rig.Db.WriteAsync(x => x.ExecuteAsync("UPDATE strategy_state SET qualification = @q", _none, ("q", new DbJson(System.Text.Json.JsonSerializer.Serialize(q, Qualification.Json)))), _none);
|
||||
}
|
||||
|
||||
return live;
|
||||
}
|
||||
|
||||
/// <summary>SPEC 12.3: a review not passed with the costs in force takes the strategy back to simulation, once; one that waits does not.</summary>
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task AReviewNotPassedDemotesAStrategyWithRealMoneyOnce()
|
||||
{
|
||||
await using var s = await CreateAsync(Consent());
|
||||
await ReducedAsync(s);
|
||||
foreach (var verdict in new[] { ReviewVerdicts.Waiting, ReviewVerdicts.Error })
|
||||
{
|
||||
await QuarterlyReviewTests.NextAsync(s.Rig.Db, s.Rig.Clock, verdict, new DateOnly(2026, verdict == ReviewVerdicts.Waiting ? 9 : 10, 30));
|
||||
}
|
||||
|
||||
Assert.IsEmpty(await s.Stages.CheckDemotionsAsync(_none));
|
||||
await QuarterlyReviewTests.NextAsync(s.Rig.Db, s.Rig.Clock, ReviewVerdicts.Rejected, new DateOnly(2026, 12, 31));
|
||||
Assert.HasCount(1, await s.Stages.CheckDemotionsAsync(_none));
|
||||
Assert.IsEmpty(await s.Stages.CheckDemotionsAsync(_none));
|
||||
var stage = (await s.Stages.GetAsync(StrategyNames.CryptoTrend, _none))!;
|
||||
Assert.AreEqual((StrategyStages.Simulation, false), (stage.Stage, stage.ExitOnly), "no real position to close");
|
||||
Assert.HasCount(1, await EventsAsync(s.Rig, "demotion"));
|
||||
Assert.HasCount(1, (await NewsRulesTests.DiaryAsync(s.Rig.Db)).Where(d => d.Contains("torna in simulazione (revisione trimestrale non superata)", StringComparison.Ordinal)).ToList());
|
||||
Assert.HasCount(1, await s.Rig.QueryAsync("SELECT message FROM notifications WHERE message LIKE '%revisione trimestrale non superata%'", r => r.Text("message")));
|
||||
}
|
||||
|
||||
/// <summary>SPEC 12.3: past the year the expected path covers, its last value holds; the slippage is the strategy's own, stops aside.</summary>
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task TheDemotionConditionsHoldAfterAYearAndLookAtTheStrategyAlone()
|
||||
{
|
||||
await using var s = await CreateAsync(Consent());
|
||||
var live = await ReducedAsync(s, q => q with { ExpectedPathP5 = [.. Enumerable.Range(0, 365).Select(i => -0.05)], MaxDrawdown = 0.9m });
|
||||
var since = (await s.Stages.GetAsync(StrategyNames.CryptoTrend, _none))!.StageSince!.Value;
|
||||
for (var day = 0; day <= 400; day++)
|
||||
{
|
||||
var index = day < 380 ? 1m : 0.9m;
|
||||
await s.Rig.Db.WriteAsync(x => x.ExecuteAsync(
|
||||
"INSERT INTO equity_snapshots (id, taken_at, scope, account_id, strategy, equity, cash, invested, drawdown_pct, created_at, world, currency, flows, twr_index, peak_index) " +
|
||||
"VALUES (@id, @t, 'strategy', @a, 'crypto_trend', @e, @e, 0, 0, @t, 'real', 'EUR', 2500, @x, 1)", _none,
|
||||
("id", Ids.NewId(s.Rig.Clock)), ("t", since.AddDays(day)), ("a", live.AccountId), ("e", 2_500m * index), ("x", index)), _none);
|
||||
}
|
||||
|
||||
var stage = (await s.Stages.GetAsync(StrategyNames.CryptoTrend, _none))!;
|
||||
Assert.AreEqual("expected_path", (await s.Stages.DemotionConditionsAsync(stage, _none)).Single().Key);
|
||||
|
||||
async Task FillAsync(string strategy, OrderPurpose purpose, decimal bp)
|
||||
{
|
||||
var order = Ids.NewId(s.Rig.Clock);
|
||||
await s.Rig.Db.WriteAsync(x => x.ExecuteAsync("INSERT INTO orders (id, account_id, instrument_id, strategy, side, order_type, quantity, status, client_order_id, purpose, created_at, updated_at) " +
|
||||
"VALUES (@id, @a, @i, @s, 'buy', 'market', 0.0001, 'filled', @c, @p, @t, @t)", _none, ("id", order), ("a", live.AccountId), ("i", s.Btc.Id), ("s", strategy),
|
||||
("c", "T" + order.ToString("N")[..20]), ("p", Wire.Text(purpose)), ("t", s.Rig.Clock.UtcNow)), _none);
|
||||
await s.Rig.Ledger.RecordFillAsync(s.Rig.Fill(live, s.Btc, strategy, OrderSide.Buy, 0.0001m, 60_000m) with { OrderId = order, ReferencePrice = 60_000m / (1m + (bp / 10_000m)) }, _none);
|
||||
}
|
||||
|
||||
await FillAsync(StrategyNames.CryptoTrend, OrderPurpose.Entry, 6m);
|
||||
await FillAsync(StrategyNames.CryptoTrend, OrderPurpose.Stop, 400m);
|
||||
await FillAsync("sma_cross", OrderPurpose.Entry, 400m);
|
||||
Assert.AreEqual(6m, Math.Round((await s.Stages.FiguresAsync(stage, _none)).SlippageBp!.Value, 2));
|
||||
Assert.IsFalse((await s.Stages.DemotionConditionsAsync(stage, _none)).Any(c => c.Key == "slippage"));
|
||||
await FillAsync(StrategyNames.CryptoTrend, OrderPurpose.Entry, 40m);
|
||||
Assert.IsTrue((await s.Stages.DemotionConditionsAsync(stage, _none)).Any(c => c.Key == "slippage"), "23 points against 5 expected");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task TheTwinIsPhotographedButLeftOutOfTheTotals()
|
||||
|
||||
Reference in new issue
Block a user