"""摘要不足时停止原论文复现;另行明确全部假设后才运行受限实验。""" import json required = {'market', 'lookback', 'slots', 'entry', 'exit', 'fee'} def experiment(spec): missing = sorted(required - spec.keys()) if missing: return {'status': 'not_replicable', 'missing': missing, 'performance': None} if spec != {'market': 'US', 'lookback': 2, 'slots': 1, 'entry': 'next_open', 'exit': 'following_open', 'fee': 1}: raise ValueError('本合成样例只支持已声明的完整实验规格') prices = {'A': [10, 11, 12], 'B': [10, 10, 9], 'C': [10, 10, 11]} scores = {s: xs[2] / xs[0] - 1 for s, xs in prices.items()} chosen = sorted(scores, key=lambda s: (-scores[s], s))[:spec['slots']] cash = 1000 - 40 * 12 - spec['fee'] + 40 * 11 - spec['fee'] return {'status': 'author_defined_experiment', 'scores': scores, 'chosen': chosen, 'ending_cash': cash, 'performance': 'synthetic_only', 'paper_replication': False} abstract_only = experiment({'market': 'US'}) complete = experiment({'market': 'US', 'lookback': 2, 'slots': 1, 'entry': 'next_open', 'exit': 'following_open', 'fee': 1}) assert abstract_only['status'] == 'not_replicable' and abstract_only['performance'] is None assert complete['chosen'] == ['A'] and complete['ending_cash'] == 958 assert not complete['paper_replication'] print(json.dumps({'abstract_only': abstract_only, 'explicit_author_assumptions': complete, 'source_scope': 'Jegadeesh and Titman 1993 publisher abstract only'}))