[GAP-047]: runtime confluence weights complete
- ConfluenceScorer.cs: apply designed factor baseline weights - ConfluenceScorerTests.cs: cover 5.85 total weight, worked example, and overrides - TASK_GAP047_PART2_WEIGHT_RUNTIME_PROMPT.md: add accepted runtime prompt - docs/00-governance: record DEC implementation and fresh-freeze requirement - SPRINT_BOARD.md: mark GAP-047 Part 2 implemented Build: clean | Tests: 514 passing; Core 425 passing | Deploy: backup 20260823_135331
This commit is contained in:
@@ -208,6 +208,68 @@ namespace NT8.Core.Tests.Intelligence
|
||||
Assert.AreEqual(0.666666, result.WeightedScore, 0.0005);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CalculateScore_DefaultDesignedWeights_TotalWeightIs585()
|
||||
{
|
||||
var scorer = CreateScorer();
|
||||
var intent = CreateIntent();
|
||||
var context = CreateContext();
|
||||
var bar = CreateBar();
|
||||
var factors = CreateWorkedExampleFactors();
|
||||
|
||||
var result = scorer.CalculateScore(intent, context, bar, factors);
|
||||
|
||||
Assert.AreEqual(5.85, Convert.ToDouble(result.Metadata["total_weight"]), 0.000001);
|
||||
AssertFactorWeight(result, FactorType.Setup, 1.0);
|
||||
AssertFactorWeight(result, FactorType.Trend, 1.0);
|
||||
AssertFactorWeight(result, FactorType.Volatility, 1.0);
|
||||
AssertFactorWeight(result, FactorType.Timing, 1.0);
|
||||
AssertFactorWeight(result, FactorType.ExecutionQuality, 1.0);
|
||||
AssertFactorWeight(result, FactorType.NarrowRange, 0.20);
|
||||
AssertFactorWeight(result, FactorType.OrbRangeVsAtr, 0.15);
|
||||
AssertFactorWeight(result, FactorType.GapDirectionAlignment, 0.15);
|
||||
AssertFactorWeight(result, FactorType.BreakoutVolumeStrength, 0.20);
|
||||
AssertFactorWeight(result, FactorType.PriorDayCloseStrength, 0.15);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CalculateScore_WorkedExample_UsesDesignedWeightsAndReturnsB()
|
||||
{
|
||||
var scorer = CreateScorer();
|
||||
var intent = CreateIntent();
|
||||
var context = CreateContext();
|
||||
var bar = CreateBar();
|
||||
var factors = CreateWorkedExampleFactors();
|
||||
|
||||
var result = scorer.CalculateScore(intent, context, bar, factors);
|
||||
|
||||
Assert.AreEqual(0.640, result.RawScore, 0.0005);
|
||||
Assert.AreEqual(0.727, result.WeightedScore, 0.0005);
|
||||
Assert.AreEqual(TradeGrade.B, result.Grade);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateFactorWeights_OverridesDesignedBaselineWeights()
|
||||
{
|
||||
var scorer = CreateScorer();
|
||||
var intent = CreateIntent();
|
||||
var context = CreateContext();
|
||||
var bar = CreateBar();
|
||||
var updates = new Dictionary<FactorType, double>();
|
||||
updates.Add(FactorType.NarrowRange, 1.0);
|
||||
scorer.UpdateFactorWeights(updates);
|
||||
|
||||
var factors = new List<IFactorCalculator>();
|
||||
factors.Add(new FixedFactorCalculator(FactorType.Setup, 1.0, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.NarrowRange, 0.0, 0.20));
|
||||
|
||||
var result = scorer.CalculateScore(intent, context, bar, factors);
|
||||
|
||||
Assert.AreEqual(2.0, Convert.ToDouble(result.Metadata["total_weight"]), 0.000001);
|
||||
Assert.AreEqual(0.5, result.WeightedScore, 0.000001);
|
||||
AssertFactorWeight(result, FactorType.NarrowRange, 1.0);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void UpdateFactorWeights_InvalidWeight_ThrowsArgumentException()
|
||||
{
|
||||
@@ -357,6 +419,36 @@ namespace NT8.Core.Tests.Intelligence
|
||||
return factors;
|
||||
}
|
||||
|
||||
private static List<IFactorCalculator> CreateWorkedExampleFactors()
|
||||
{
|
||||
var factors = new List<IFactorCalculator>();
|
||||
factors.Add(new FixedFactorCalculator(FactorType.Setup, 1.00, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.Trend, 0.30, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.Volatility, 0.70, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.Timing, 1.00, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.ExecutionQuality, 0.80, 1.0));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.NarrowRange, 0.45, 0.20));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.OrbRangeVsAtr, 0.50, 0.15));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.GapDirectionAlignment, 0.10, 0.15));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.BreakoutVolumeStrength, 0.85, 0.20));
|
||||
factors.Add(new FixedFactorCalculator(FactorType.PriorDayCloseStrength, 0.70, 0.15));
|
||||
return factors;
|
||||
}
|
||||
|
||||
private static void AssertFactorWeight(ConfluenceScore result, FactorType type, double expectedWeight)
|
||||
{
|
||||
for (var i = 0; i < result.Factors.Count; i++)
|
||||
{
|
||||
if (result.Factors[i].Type == type)
|
||||
{
|
||||
Assert.AreEqual(expectedWeight, result.Factors[i].Weight, 0.000001);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.Fail("Missing factor type {0}", type);
|
||||
}
|
||||
|
||||
private class FixedFactorCalculator : IFactorCalculator
|
||||
{
|
||||
private readonly FactorType _type;
|
||||
|
||||
Reference in New Issue
Block a user