Files
RichardandClaude Opus 4.8 2a312ca035 R8: Accounting- + Supervisor-Modul + Core-Datenfundament (S-0)
Portierung der beiden fehlenden Grundbausteine aus PolytraderSharp (voller Ausbau).

Core S-0 (Datenfundament fuer Analyse/Forensik):
- core_decision_journal + core_order_events (+ ReasonCode/Decision/OrderEvent-Enums),
  IDecisionJournal/IOrderEventLog mit fehlertoleranten EF-Impls (Handel bricht nie).
- SignalId-Durchreichung TradeSignal -> ExecutionService -> core_trade_history;
  ExecutionService schreibt an jeder Verzweigung Journal/Order-Events.
- JSONL-Log-Sink (LogJson + Dual-Sink), pure Analytik: RealizedPnlEngine (FIFO),
  TradeAnalytics, DossierBuilder. Migration AddAnalysisFoundation.

Accounting-Modul (acc_): unabhaengiger IBKR-Kontoauszug (Activity Flex Query) hinter
Interfaces mit Offline-Null-Stubs -> append-only Ledger + Periodenabrechnung/BWA + FX
(USD/EUR) + CSV/PDF (PDFsharp/MigraDoc). Steuerschicht bewusst offen (Platzhalter-Tab).
Kein Handel. Migration InitialAccounting.

Supervisor-Modul (sup_): read-only OpenRouter-Agent (Function-Calling-Loop) + read-only
Tool-Registry (8 Tools) + Profile + Dossier-Browser + Counterfactual-Job (Stub) +
Tagesbericht/MCP-Light (opt-in). Migration InitialSupervisor.

Verdrahtung: Program.cs (beide Module + Icons), slnx/App/Tests-Referenzen,
provision-db.ps1, AppSettings-Sektionen, docs/konzepte, README.

Tests: 79 -> 117 gruen (FIFO/KPIs/Dossier/JSONL, Classifier/Engine/FX/Idempotenz,
OpenRouter/Registry/Agent/MCP, STA-Konstruktion beider neuen Fenster).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-31 09:25:18 +02:00

66 lines
1.9 KiB
C#

using FluentAssertions;
using IBKRTrader.Core.Analytics;
using IBKRTrader.Core.Persistence.Entities;
namespace IBKRTrader.Tests.Analytics;
[Trait("cat", "unit")]
public class TradeAnalyticsTests
{
private static CoreTrade Fill(string module, string action, decimal qty, decimal price, int minute, string symbol = "AAPL") =>
new()
{
Module = module, Symbol = symbol, Action = action,
Quantity = qty, Price = price, TotalValue = qty * price,
TradedAt = new DateTime(2026, 1, 1, 0, minute, 0, DateTimeKind.Utc)
};
[Fact]
public void EmptyInput_YieldsZeroKpis()
{
var k = TradeAnalytics.ComputeKpis(Array.Empty<CoreTrade>());
k.TradeCount.Should().Be(0);
k.NetPnl.Should().Be(0m);
k.WinRatePct.Should().Be(0d);
}
[Fact]
public void ComputesWinRateAndProfitFactor()
{
var fills = new[]
{
Fill("CT", "BUY", 10, 100m, 0),
Fill("CT", "SELL", 10, 130m, 1), // +300 Gewinner
Fill("CT", "BUY", 10, 100m, 2, "MSFT"),
Fill("CT", "SELL", 10, 90m, 3, "MSFT") // -100 Verlierer
};
var k = TradeAnalytics.ComputeKpis(fills);
k.TradeCount.Should().Be(2);
k.NetPnl.Should().Be(200m);
k.WinRatePct.Should().Be(50d);
k.ProfitFactor.Should().Be(3d); // 300 / 100
}
[Fact]
public void PnlByModule_GroupsAndSorts()
{
var fills = new[]
{
Fill("A", "BUY", 10, 100m, 0),
Fill("A", "SELL", 10, 130m, 1), // +300
Fill("B", "BUY", 10, 100m, 2, "MSFT"),
Fill("B", "SELL", 10, 90m, 3, "MSFT") // -100
};
var buckets = TradeAnalytics.PnlByModule(fills);
buckets.Should().HaveCount(2);
buckets[0].Key.Should().Be("A");
buckets[0].Pnl.Should().Be(300m);
buckets[1].Key.Should().Be("B");
}
}