feat: connect formula decisions to learning ledger
This commit is contained in:
@@ -8,10 +8,12 @@ namespace QuantEngine.Application.Services
|
|||||||
public class FormulaService
|
public class FormulaService
|
||||||
{
|
{
|
||||||
private readonly IPostgresqlHistoryStore _historyStore;
|
private readonly IPostgresqlHistoryStore _historyStore;
|
||||||
|
private readonly DecisionLearningService _learningService;
|
||||||
|
|
||||||
public FormulaService(IPostgresqlHistoryStore historyStore)
|
public FormulaService(IPostgresqlHistoryStore historyStore, DecisionLearningService learningService)
|
||||||
{
|
{
|
||||||
_historyStore = historyStore;
|
_historyStore = historyStore;
|
||||||
|
_learningService = learningService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimingDecisionResult ComputeTimingDecision(Dictionary<string, object> ctx)
|
public TimingDecisionResult ComputeTimingDecision(Dictionary<string, object> ctx)
|
||||||
@@ -23,6 +25,27 @@ namespace QuantEngine.Application.Services
|
|||||||
public FinalDecisionResult ComputeFinalDecision(Dictionary<string, object> ctx)
|
public FinalDecisionResult ComputeFinalDecision(Dictionary<string, object> ctx)
|
||||||
=> FormulaEngine.ComputeFinalDecision(ctx);
|
=> FormulaEngine.ComputeFinalDecision(ctx);
|
||||||
|
|
||||||
|
public async Task<Guid> ComputeAndRecordFinalDecisionAsync(
|
||||||
|
Dictionary<string, object> ctx,
|
||||||
|
string decisionKey,
|
||||||
|
string instrumentId,
|
||||||
|
string sourceVersion,
|
||||||
|
IEnumerable<FactorEvidenceInput> 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(
|
public CashShortfallResult ComputeCashShortfallHarness(
|
||||||
Dictionary<string, object> asResult,
|
Dictionary<string, object> asResult,
|
||||||
double totalAsset,
|
double totalAsset,
|
||||||
|
|||||||
Reference in New Issue
Block a user