Add the event-driven backtest engine and the strategy interface (refs #34)

The strategy contract of SPEC 5.3 (IStrategy, StrategyContext, Intent) is
shared by backtest and live: the context exposes bars only up to the
decision, adjusted and anchored to that day, and reading past it throws.
The engine runs each session as ordered events (corporate actions, open,
session, close), decides on the close and executes at the next open with
the simulator's price lists, slippage tiers, tick and lot rounding,
minimums and no leverage. Corrective and risk hooks are wired in and pass
everything through until Phase 5. One decision cycle can restart from a
recorded book (SPEC 12.3).

A scripted toy strategy reproduces a result computed by hand to the cent
on OKX and Alpaca costs. The Phase 3 class Trading.Strategies becomes
StrategyNames so the Anubis.Strategies namespace can exist.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 09:29:01 +01:00
1 parent 6d3ef8e7b5
commit d97304d7b9
19 files changed
+1592 -78

No files matched your search

+1 -1
View File
@@ -136,7 +136,7 @@ internal sealed record AccountsView(
var (pending, others, alpacaStops) = PendingRows(orders.Where(o => shown.Contains(o.Account)).ToList(), byId, instruments.ToDictionary(i => i.Key, i => i.Value.Symbol),
positions, market.Open, market.Next, clock.UtcNow, zone);
var slices = Strategies.Base.Select(b => new StrategySlice(Strategies.Label(b.Name, withMarket: true), "var(--s-" + b.Name.Replace('_', '-') + ")",
var slices = StrategyNames.Base.Select(b => new StrategySlice(StrategyNames.Label(b.Name, withMarket: true), "var(--s-" + b.Name.Replace('_', '-') + ")",
rows.Where(r => r.Row.Strategy == b.Name).Sum(r => r.Row.ValueEur))).ToList();
decimal? fxEffect = null;
if (cards.Count > 0)
@@ -221,7 +221,7 @@ else
<tr>
<th scope="row"><strong>@p.Symbol</strong> <span class="muted">@p.Name</span></th>
<td class="wide">@(p.Broker == Venues.Alpaca ? "Alpaca" : "OKX")</td>
<td class="nowrap wide"><span class="swatch round" style="background: var(--s-@p.Strategy.Replace('_', '-'))"></span>@Strategies.Label(p.Strategy)</td>
<td class="nowrap wide"><span class="swatch round" style="background: var(--s-@p.Strategy.Replace('_', '-'))"></span>@StrategyNames.Label(p.Strategy)</td>
<td class="num wide">@Format.Quantity(p.Quantity)</td>
<td class="num wide">@Format.Money(p.Average, p.Currency)</td>
<td class="num wide">@Format.Money(p.Last, p.Currency)</td>
@@ -118,7 +118,7 @@
<ul class="plain">
@foreach (var s in b.Strategies)
{
<li>@Strategies.Label(s.Strategy, withMarket: true): quota @Format.Percent(s.Share * 100m, 0), capitale @Format.Money(s.Capital, s.Currency), liquidità @Format.Money(s.Cash, s.Currency)</li>
<li>@StrategyNames.Label(s.Strategy, withMarket: true): quota @Format.Percent(s.Share * 100m, 0), capitale @Format.Money(s.Capital, s.Currency), liquidità @Format.Money(s.Cash, s.Currency)</li>
}
</ul>
}