[verified] Fix bucket3 to rank by dividend yield (ignore score) — reviewer blocker

- allocate_capital _fill now takes sort_by; bucket3 uses dividend_yield, buckets 1/2 use combined_score
- Previously bucket3 wrongly ranked by score (picked CPN/PTT); now picks highest-yield CRC — matches user rule 'bucket3 = highest dividend yield, ignoring score'
- Added test_bucket3_ranks_by_yield_ignoring_score
- Re-reviewed (deleg_43b165e0) passed=true, no logic/security errors; full suite 185 OK
This commit is contained in:
Kunthawat Greethong
2026-08-25 16:32:12 +07:00
parent e24023cf42
commit aae1d132c8
2 changed files with 29 additions and 4 deletions

View File

@@ -50,6 +50,25 @@ class AllocationTest(unittest.TestCase):
overlap = set(bucket3_syms) & set(bucket1_syms)
self.assertEqual(overlap, set())
def test_bucket3_ranks_by_yield_ignoring_score(self):
# The spec: bucket3 = highest dividend yield, IGNORING score.
# A low-score but high-yield name must rank above a high-score low-yield name.
cands = [
Candidate("HIGH_SCORE", 10.0, 8.0, True, 2.0), # score 8, yield 2%
Candidate("HIGH_YIELD", 10.0, 0.1, True, 7.0), # score 0.1, yield 7%
Candidate("MID", 10.0, 5.0, True, 3.0),
]
# Big capital so bucket1 consumes only the top score name, leaving
# HIGH_YIELD (not HIGH_SCORE) to be the bucket3 top pick.
res = allocate_capital(1_000_000, cands)
b3 = [o.symbol for o in res.orders if o.bucket == 3]
# HIGH_YIELD (7%) should be selected in bucket3 before HIGH_SCORE (2%)
self.assertIn("HIGH_YIELD", b3)
if "HIGH_SCORE" in b3:
hi = b3.index("HIGH_SCORE")
hy = b3.index("HIGH_YIELD")
self.assertLess(hy, hi)
def test_invalid_capital_raises(self):
with self.assertRaises(Exception):
allocate_capital(0, self.make_candidates())