From e15e4c6e206f6111b4b80838caf0393d0f72743c Mon Sep 17 00:00:00 2001 From: kjh2064 Date: Sun, 12 Jul 2026 11:54:06 +0900 Subject: [PATCH] feat: connect formula decisions to learning ledger --- .../Services/FormulaService.cs | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/dotnet/QuantEngine.Application/Services/FormulaService.cs b/src/dotnet/QuantEngine.Application/Services/FormulaService.cs index 21950af3..42813dbb 100644 --- a/src/dotnet/QuantEngine.Application/Services/FormulaService.cs +++ b/src/dotnet/QuantEngine.Application/Services/FormulaService.cs @@ -8,10 +8,12 @@ namespace QuantEngine.Application.Services public class FormulaService { private readonly IPostgresqlHistoryStore _historyStore; + private readonly DecisionLearningService _learningService; - public FormulaService(IPostgresqlHistoryStore historyStore) + public FormulaService(IPostgresqlHistoryStore historyStore, DecisionLearningService learningService) { _historyStore = historyStore; + _learningService = learningService; } public TimingDecisionResult ComputeTimingDecision(Dictionary ctx) @@ -23,6 +25,27 @@ namespace QuantEngine.Application.Services public FinalDecisionResult ComputeFinalDecision(Dictionary ctx) => FormulaEngine.ComputeFinalDecision(ctx); + public async Task ComputeAndRecordFinalDecisionAsync( + Dictionary ctx, + string decisionKey, + string instrumentId, + string sourceVersion, + IEnumerable factorEvidence) + { + var decision = ComputeFinalDecision(ctx); + return await _learningService.RecordDecisionAsync( + decisionKey, + DateTimeOffset.UtcNow, + instrumentId, + decision.FinalAction, + "PASS", + Convert.ToDecimal(decision.PriorityScore), + sourceVersion, + factorEvidence, + new { context_keys = ctx.Keys.OrderBy(key => key).ToArray() }, + new { formula = "FormulaEngine.ComputeFinalDecision", source_version = sourceVersion }); + } + public CashShortfallResult ComputeCashShortfallHarness( Dictionary asResult, double totalAsset,