人工关注缺券商覆盖仍进入建仓评估
This commit is contained in:
parent
981987dbc7
commit
9e6927bf32
9
card.py
9
card.py
|
|
@ -100,7 +100,7 @@ def judge(ev: dict[str, Any], *, start_pct: float = 3.0,
|
|||
logic_stale_days: int = 90, require_started: bool = True,
|
||||
company_review: dict | None = None, quality_gate: bool = True,
|
||||
stale_days: int = 120, require_accum_confirm: bool = True,
|
||||
consensus_admission: bool = False) -> dict[str, Any]:
|
||||
consensus_admission: bool = False, user_no_coverage: bool = False) -> dict[str, Any]:
|
||||
"""一只票的证据字典 -> 判决字典。
|
||||
|
||||
ev 里认的键(缺键按缺失处理,不报错):
|
||||
|
|
@ -213,7 +213,11 @@ def judge(ev: dict[str, Any], *, start_pct: float = 3.0,
|
|||
if user_selected and not gates['pointed']:
|
||||
missing = [x for x in missing if x != '所在环节当日没有被传导指向']
|
||||
reasons.insert(0, '用户添加,按现有条件评估')
|
||||
effective = dict(gates, pointed=gates['pointed'] or user_selected or consensus_admission)
|
||||
# 只豁免有效人工来源的“没有覆盖”;已有负空间和覆盖数据不完整仍走原门槛。
|
||||
# 原始 gates 与 missing 保留缺覆盖事实,不把人工来源伪装成券商覆盖。
|
||||
coverage_exempt = bool(user_no_coverage and user_selected and not ev.get('covered') and upside is None)
|
||||
effective = dict(gates, pointed=gates['pointed'] or user_selected or consensus_admission,
|
||||
covered=gates['covered'] or coverage_exempt)
|
||||
all_gates = all(effective.values())
|
||||
failed = [k for k, ok in effective.items() if not ok]
|
||||
# 判决依据是这张卡上唯一一句"为什么",PMS 原样显示在页面上给人读。所以它必须是
|
||||
|
|
@ -263,6 +267,7 @@ def judge(ev: dict[str, Any], *, start_pct: float = 3.0,
|
|||
|
||||
return {"verdict": verdict, "reasons": reasons, "missing": missing, "risk": risk,
|
||||
"reference_risk": reference_risk,
|
||||
"user_coverage_exempt": coverage_exempt,
|
||||
"gates": gates, "effective_gates": effective,
|
||||
"consensus_admission": bool(consensus_admission),
|
||||
"confirm": confirm, "confirm_required": bool(require_accum_confirm and not consensus_admission),
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ CARD_ACCUM_MAX_AGE = int(os.environ.get("CARD_ACCUM_MAX_AGE", "30")) # 确认
|
|||
# 默认保留旧模式以兼容其他调用方;切换必须发布新计划版本,不能改历史快照。
|
||||
CARD_ACCUM_CONFIRM_REQUIRED = os.environ.get("CARD_ACCUM_CONFIRM_REQUIRED", "1").lower() not in ("0", "false", "no")
|
||||
CARD_CONSENSUS_ADMISSION_ENABLED = os.environ.get('CARD_CONSENSUS_ADMISSION_ENABLED', '0').lower() in ('1', 'true', 'yes')
|
||||
CARD_USER_NO_COVERAGE_ENABLED = os.environ.get('CARD_USER_NO_COVERAGE_ENABLED', '0').lower() in ('1', 'true', 'yes')
|
||||
# 计划快照落点(容器内路径;仓库根挂在 /app,故默认落在仓库 data/plan/)。
|
||||
# 每日 JSON 含主榜与观察档全部行与全部证据线,是复盘与对账的唯一底本。
|
||||
PLAN_SNAPSHOT_DIR = os.environ.get("PLAN_SNAPSHOT_DIR", "data/plan")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
# 人工关注缺券商覆盖的定向调整
|
||||
|
||||
用户仅授权取消人工关注股票因没有券商覆盖而不能进入建仓评估的限制,其他链路保持。实现位置为选股桥候选卡,不修改PMS三源合议、研判、自决、资金、排序、仓位及退出纪律。
|
||||
|
||||
新增桥配置`CARD_USER_NO_COVERAGE_ENABLED`,默认关闭,155发布时开启。仅当计划使用有效人工登记、原覆盖字段为false且预期空间缺失时,豁免这一项资格;原始覆盖字段与“没有券商覆盖”的证据提示保留。已有覆盖但空间不足、覆盖数据不完整、ST、有效期及其他资格继续按原规则。公司质地差仍按现有规则分流,不因人工关注直接获得买入批准。
|
||||
|
||||
计划冻结配置保存此开关。历史冻结版本缺少该键时按关闭重放;运行开关变化由既有plan-refresh生成独立修订,真实截止时间与父子版本保留,不改写晨版。仅依赖该豁免的股票标为人工来源必需,未显式支持人工来源的消费者不取得这类候选。取消登记或过期后不继续继承豁免。修订失败保留旧版本,并对人工来源保留待核实状态。
|
||||
|
||||
新增隔离回归验证人工缺覆盖放行、普通候选不变、负空间与风险不放行、旧配置重放、真实装配及来源移除、旧消费者隔离、失败版本保护。开发机和候选全量结果、实际发布及PMS消费情况在完成后追加。
|
||||
8
plan.py
8
plan.py
|
|
@ -450,6 +450,7 @@ def _assemble_cards(ds: str, codes: list, ev: dict, upside: pd.Series,
|
|||
accum_max_age=config.CARD_ACCUM_MAX_AGE,
|
||||
require_accum_confirm=config.CARD_ACCUM_CONFIRM_REQUIRED,
|
||||
consensus_admission=config.CARD_CONSENSUS_ADMISSION_ENABLED,
|
||||
user_no_coverage=config.CARD_USER_NO_COVERAGE_ENABLED,
|
||||
neg_tol=config.UPSIDE_NEG_TOLERANCE,
|
||||
logic_stale_days=config.LOGIC_STALE_DAYS,
|
||||
require_started=config.CARD_REQUIRE_STARTED,
|
||||
|
|
@ -662,7 +663,7 @@ def collect(date: str | None = None, top: int = 20, obs_top: int = 10,
|
|||
"logic_claims": c.get("logic_claims") or []})
|
||||
if k in selected:
|
||||
r['user_candidate'] = selected[k]
|
||||
r['user_required'] = k not in ordinary or not r['pointed']
|
||||
r['user_required'] = k not in ordinary or not r['pointed'] or bool(c.get('user_coverage_exempt'))
|
||||
if not names.get(k):
|
||||
r.update(verdict=card.VERDICT_SHOW, basis='证券资料尚未齐全,暂不参与交易')
|
||||
return r
|
||||
|
|
@ -781,6 +782,7 @@ def collect(date: str | None = None, top: int = 20, obs_top: int = 10,
|
|||
"transmission 时按 09-14 的质地调整分序",
|
||||
# ---- 候选卡(2026-09-02):分数与档位之外的另一份产物,不受 top / theme_cap 裁剪 ----
|
||||
"card_params": {"start_pct": config.CARD_START_PCT,
|
||||
"user_no_coverage": config.CARD_USER_NO_COVERAGE_ENABLED,
|
||||
"consensus_admission": config.CARD_CONSENSUS_ADMISSION_ENABLED,
|
||||
"accum_confirm_required": config.CARD_ACCUM_CONFIRM_REQUIRED,
|
||||
"admission_rule": ("consensus-admission-v3-20261110" if config.CARD_CONSENSUS_ADMISSION_ENABLED else
|
||||
|
|
@ -801,7 +803,9 @@ def collect(date: str | None = None, top: int = 20, obs_top: int = 10,
|
|||
"吸筹仅作参考,非明确、潜在、缺评分或陈旧本身不否决;"
|
||||
"高位派发及其他真实风险仍拦截,质地差仍按现行规则降为关注;"
|
||||
"建仓看基本面、技术面和择时三源合议,由PMS按命令、风控与现行自决档处理;"
|
||||
"因果论断只展示不进判决")},
|
||||
"因果论断只展示不进判决") +
|
||||
(";有效人工关注不因缺少券商覆盖被排除,已有估值空间限制及其他条件不变"
|
||||
if config.CARD_USER_NO_COVERAGE_ENABLED else "")},
|
||||
"card_counts": card_counts,
|
||||
"candidates": _by_verdict(card.VERDICT_CANDIDATE),
|
||||
"watch": _by_verdict(card.VERDICT_WATCH),
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class Config:
|
|||
if bundle is not None and name in bundle.params:
|
||||
return bundle.params[name]
|
||||
# 老冻结版本从未启用新规则,不能继承今天服务器的开关。
|
||||
if bundle is not None and bundle.replay and name in ('PLAN_RATING_PRIORITY_ENABLED', 'CARD_CONSENSUS_ADMISSION_ENABLED'):
|
||||
if bundle is not None and bundle.replay and name in ('PLAN_RATING_PRIORITY_ENABLED', 'CARD_CONSENSUS_ADMISSION_ENABLED', 'CARD_USER_NO_COVERAGE_ENABLED'):
|
||||
return False
|
||||
return getattr(self.module, name)
|
||||
|
||||
|
|
|
|||
|
|
@ -58,9 +58,13 @@ def refresh(day=None, *, now=None, regime_value=None):
|
|||
rating_changed = params.get('PLAN_RATING_PRIORITY_ENABLED', False) != config.PLAN_RATING_PRIORITY_ENABLED
|
||||
params['PLAN_RATING_PRIORITY_ENABLED'] = config.PLAN_RATING_PRIORITY_ENABLED
|
||||
params['PLAN_RATING_PRIORITY_DAYS'] = config.PLAN_RATING_PRIORITY_DAYS
|
||||
coverage_changed = params.get('CARD_USER_NO_COVERAGE_ENABLED', False) != config.CARD_USER_NO_COVERAGE_ENABLED
|
||||
params['CARD_USER_NO_COVERAGE_ENABLED'] = config.CARD_USER_NO_COVERAGE_ENABLED
|
||||
inputs = copy.deepcopy(env['inputs'])
|
||||
import user_candidates as uc
|
||||
selected = uc.active(root, now)
|
||||
if coverage_changed:
|
||||
pending.update(r['code'] for r in selected + inputs.get('user_candidates', []))
|
||||
candidates_changed = selected != inputs.get('user_candidates', [])
|
||||
if candidates_changed:
|
||||
pending.update(r['code'] for r in selected + inputs.get('user_candidates', []))
|
||||
|
|
@ -96,8 +100,10 @@ def refresh(day=None, *, now=None, regime_value=None):
|
|||
inputs['regime'] = regime_value
|
||||
if policy_changed:
|
||||
pending.update(r['code'] for b in ('main', 'observe') for r in old.get(b, []))
|
||||
if coverage_changed:
|
||||
pending.update(r['code'] for r in selected + inputs.get('user_candidates', []))
|
||||
pv.health(root, day, pending_codes=sorted(pending), error=None)
|
||||
if pv.digest(inputs) == old['decision']['input_hash'] and not policy_changed and not rating_changed:
|
||||
if pv.digest(inputs) == old['decision']['input_hash'] and not policy_changed and not rating_changed and not coverage_changed:
|
||||
pv.health(root, day, pending_codes=[], error=None, decision_id=old['decision']['id'])
|
||||
return {'status': 'unchanged', 'decision': old['decision']}
|
||||
bundle = pi.Bundle(records=None if candidates_changed else inputs['records'],
|
||||
|
|
@ -121,6 +127,8 @@ def refresh(day=None, *, now=None, regime_value=None):
|
|||
reason = '评析或评级排序期限更新'
|
||||
if consensus_changed:
|
||||
reason = '选股方向统一交由三源合议' if config.CARD_CONSENSUS_ADMISSION_ENABLED else '恢复原选股方向门槛'
|
||||
if coverage_changed:
|
||||
reason = '人工关注不再要求券商覆盖' if config.CARD_USER_NO_COVERAGE_ENABLED else '恢复人工关注券商覆盖要求'
|
||||
published = pv.publish(root, data, inputs, params, cutoff_at=now.isoformat(), reason=reason)
|
||||
plan.write_published_md(published)
|
||||
return {'status': 'published', 'decision': published['decision']}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,137 @@
|
|||
"""人工关注缺券商覆盖的范围、真实装配和版本隔离;外部来源全部替身。"""
|
||||
import copy
|
||||
import datetime as dt
|
||||
import tempfile
|
||||
import unittest
|
||||
from contextlib import ExitStack, contextmanager
|
||||
from unittest.mock import patch
|
||||
|
||||
import pandas as pd
|
||||
import test_api_support
|
||||
import card, config, factors, judgement, logic_state_daily, plan, sources, user_research
|
||||
import plan_inputs as pi
|
||||
import plan_refresh
|
||||
import plan_versions as pv
|
||||
import user_candidates as uc
|
||||
|
||||
NOW = dt.datetime.fromisoformat('2026-11-11T12:30:00+08:00')
|
||||
DAY = '2026-11-10'
|
||||
|
||||
|
||||
class CoverageTests(unittest.TestCase):
|
||||
def judge(self, **changes):
|
||||
ev = dict(pointed=True, covered=False, upside=None, pct0=4, user_selected=True)
|
||||
return card.judge(dict(ev, **changes), consensus_admission=True, user_no_coverage=True)
|
||||
|
||||
def test_manual_missing_coverage_reaches_evaluation_without_inventing_data(self):
|
||||
r = self.judge()
|
||||
self.assertEqual(r['verdict'], '候选')
|
||||
self.assertFalse(r['gates']['covered'])
|
||||
self.assertTrue(r['effective_gates']['covered'])
|
||||
self.assertNotIn('covered', r['failed_gates'])
|
||||
self.assertIn('没有券商覆盖', r['missing'])
|
||||
self.assertFalse(any(x.startswith('券商覆盖,') for x in r['reasons']))
|
||||
|
||||
def test_ordinary_and_disabled_rule_keep_coverage_requirement(self):
|
||||
self.assertEqual(self.judge(user_selected=False)['verdict'], '仅展示')
|
||||
self.assertEqual(card.judge(dict(pointed=True, covered=False, pct0=4,
|
||||
user_selected=True), consensus_admission=True)['verdict'], '仅展示')
|
||||
|
||||
def test_existing_valuation_and_other_gates_still_block(self):
|
||||
for values in [dict(covered=True, upside=-.13), dict(covered=True, upside=None),
|
||||
dict(covered=False, upside=-.13), dict(risk_name=True),
|
||||
dict(stale_snapshot=True), dict(pct0=1)]:
|
||||
with self.subTest(values=values):
|
||||
self.assertEqual(self.judge(**values)['verdict'], '仅展示')
|
||||
r = card.judge(dict(pointed=True, covered=False, user_selected=True, pct0=4),
|
||||
user_no_coverage=True, consensus_admission=True,
|
||||
company_review={'overall':'差','age_days':1})
|
||||
self.assertEqual(r['verdict'], '关注')
|
||||
|
||||
def test_covered_stock_does_not_change_with_rule(self):
|
||||
ev = dict(pointed=True, covered=True, upside=.2, pct0=4, user_selected=True)
|
||||
self.assertEqual(card.judge(ev, consensus_admission=True),
|
||||
card.judge(ev, consensus_admission=True, user_no_coverage=True))
|
||||
|
||||
def test_old_frozen_params_do_not_inherit_live_rule(self):
|
||||
with patch.object(config, 'CARD_USER_NO_COVERAGE_ENABLED', True):
|
||||
with pi.Bundle(records={}, params={}).use():
|
||||
self.assertFalse(plan.config.CARD_USER_NO_COVERAGE_ENABLED)
|
||||
|
||||
@contextmanager
|
||||
def fixture(self, root):
|
||||
codes = ['SH600001','SH600002']
|
||||
with ExitStack() as s:
|
||||
def stub(obj, name, **kw): return s.enter_context(patch.object(obj, name, **kw))
|
||||
for k,v in {'PLAN_SNAPSHOT_DIR':root,'PLAN_RANK_AXIS':'quality',
|
||||
'CARD_CONSENSUS_ADMISSION_ENABLED':True,'CARD_USER_NO_COVERAGE_ENABLED':False}.items():
|
||||
stub(config, k, new=v)
|
||||
stub(user_research,'load_reports',return_value={})
|
||||
stub(plan,'_factor',side_effect=lambda table,day: pd.Series(dtype=float) if 'upside' in table else pd.Series([240.,230.],index=codes))
|
||||
stub(plan,'_latest_date',return_value=DAY)
|
||||
stub(plan,'_prev_date',return_value=None)
|
||||
stub(plan,'_names',return_value=dict(zip(codes,['甲','乙'])))
|
||||
stub(uc,'catalog',return_value=dict(zip(codes,['甲','乙'])))
|
||||
stub(plan,'_evidence',return_value=({}, {DAY}))
|
||||
stub(plan,'_segments_of',return_value={})
|
||||
stub(factors,'_risk_set',return_value=set())
|
||||
stub(factors,'build_upside',return_value=pd.DataFrame())
|
||||
stub(judgement,'load_previous',return_value=[])
|
||||
stub(judgement,'recent_rows',return_value={})
|
||||
stub(logic_state_daily,'history',return_value={})
|
||||
for name in ('broker_reports','logic_claims','broker_actions','close_prices',
|
||||
'valuation_scenarios','analyst_events','event_day_fields','news_flashes',
|
||||
'segment_catalysts','catalysts_for_codes'):
|
||||
stub(sources,name,return_value={})
|
||||
stub(sources,'moved_members',return_value={c:{'theme':'板块','n_sources':1,'chain_fit':1} for c in codes})
|
||||
stub(sources,'stock_daily',return_value={c:{'pct0':4} for c in codes})
|
||||
stub(sources,'night_conclusions',return_value={})
|
||||
stub(sources,'company_reviews',side_effect=lambda cs,*a,**kw:{c:{'overall':'好','age_days':0,'review_ref':'r'} for c in cs})
|
||||
uc.save(root,{'codes':['600001'],'reason':'人工关注','expires_on':'2026-11-12'},'甲',NOW)
|
||||
selected=uc.active(root,NOW)
|
||||
bundle=pi.Bundle(params=pi.effective_config(config),cutoff_at=NOW.isoformat())
|
||||
with bundle.use(): data=plan.collect(DAY,user_candidates=selected)
|
||||
data.update(data.pop('_full'))
|
||||
with pv.writer(root):
|
||||
morning=pv.publish(root,data,{'records':bundle.records,'market':{},'regime':None,'user_candidates':selected},
|
||||
bundle.params,cutoff_at=NOW.isoformat(),reason='晨版')
|
||||
yield morning,selected
|
||||
|
||||
def test_real_assembly_revision_consumer_isolation_and_removal(self):
|
||||
with tempfile.TemporaryDirectory() as root, self.fixture(root) as (morning, selected):
|
||||
frozen=copy.deepcopy(morning)
|
||||
ordinary=next(r for r in morning['main'] if r['code']=='SH600002')
|
||||
with patch.object(config,'CARD_USER_NO_COVERAGE_ENABLED',True):
|
||||
result=plan_refresh.refresh(now=NOW)
|
||||
self.assertEqual(result['status'],'published')
|
||||
new=pv.load(root)
|
||||
rows={r['code']:r for r in new['main']}
|
||||
self.assertEqual(rows['SH600001']['verdict'],'候选')
|
||||
self.assertTrue(rows['SH600001']['pointed'])
|
||||
self.assertTrue(rows['SH600001']['user_required'])
|
||||
self.assertEqual(rows['SH600002'],ordinary)
|
||||
self.assertEqual(rows['SH600001']['score'],240.)
|
||||
self.assertEqual(rows['SH600001']['research_rank'],1)
|
||||
self.assertNotIn('SH600001',[r['code'] for r in uc.consumer_view(new)['main']])
|
||||
self.assertEqual(new['decision']['reason'],'人工关注不再要求券商覆盖')
|
||||
self.assertEqual(new['decision']['input_hash'],morning['decision']['input_hash'])
|
||||
self.assertNotEqual(new['decision']['params_hash'],morning['decision']['params_hash'])
|
||||
self.assertEqual(pv.load(root,morning=True),frozen)
|
||||
self.assertEqual(plan_refresh.refresh(now=NOW)['status'],'unchanged')
|
||||
uc.remove(root,selected[0]['id'],'甲',NOW)
|
||||
plan_refresh.refresh(now=NOW)
|
||||
after=pv.load(root)
|
||||
row=next(r for r in after['main'] if r['code']=='SH600001')
|
||||
self.assertEqual(row['verdict'],'仅展示')
|
||||
self.assertNotIn('user_candidate',row)
|
||||
|
||||
def test_failed_revision_keeps_old_version_and_pending_manual_codes(self):
|
||||
with tempfile.TemporaryDirectory() as root, self.fixture(root) as (morning, selected):
|
||||
with patch.object(config,'CARD_USER_NO_COVERAGE_ENABLED',True), \
|
||||
patch.object(plan,'collect',side_effect=ValueError('材料损坏')):
|
||||
with self.assertRaises(ValueError): plan_refresh.refresh(now=NOW)
|
||||
self.assertEqual(pv.load(root),morning)
|
||||
self.assertEqual(pv.health(root,DAY)['pending_codes'],['SH600001'])
|
||||
|
||||
|
||||
if __name__ == '__main__': unittest.main()
|
||||
Loading…
Reference in New Issue