"""C03股份支付教学构造模型。仅标准库;金额为元,数量为份或股。 所有金额从本文件内显式输入重建;不估值实际工具、不判断真实合同分类。 内部使用Fraction,展示金额保留两位,比例保留六位;展示数不回流计算。 运行时只写自身相邻JSON,不依赖当前目录、仓库、网络或系统时间。 """ from fractions import Fraction as F from decimal import Decimal, localcontext, ROUND_HALF_UP from pathlib import Path import json def rounded(value, places=2): value = F(value) with localcontext() as ctx: ctx.prec = 40 return format((Decimal(value.numerator) / Decimal(value.denominator)).quantize( Decimal(1).scaleb(-places), rounding=ROUND_HALF_UP), f'.{places}f') def cumulative_counts(counts, units, value, years): previous = F(0) result = [] for year, count in enumerate(counts, 1): cumulative = F(count * units * value * min(year, years), years) result.append({'year': year, 'people': count, 'units': count * units, 'progress': f'{min(year, years)}/{years}', 'cumulative': rounded(cumulative), 'previous': rounded(previous), 'current': rounded(cumulative - previous)}) previous = cumulative return result def equity_lock(p): rows = [] for year in range(1, p['years'] + 1): rows.append({'year': year, 'down_stock_price': p['down_prices'][year - 1], 'up_stock_price': p['up_prices'][year - 1], 'locked_value': p['grant_value'], 'units': p['units'], 'progress': f'{year}/{p["years"]}', 'cumulative': rounded(F(p['units'] * p['grant_value'] * year, p['years'])), 'current_both_paths': rounded(F(p['units'] * p['grant_value'], p['years']))}) scenarios = [] for path in ['down', 'up']: for n in [p['units'], p['lower_units']]: scenarios.append({'price_path': path, 'final_units': n, 'grant_value': p['grant_value'], 'final_cost': rounded(n * p['grant_value'])}) return {'lock': [{'grant_date': p['grant_date'], 'grant_stock_price': p['grant_stock_price'], 'grant_value': p['grant_value'], 'units': p['units'], 'grant_total': rounded(p['units'] * p['grant_value'])}], 'annual': rows, 'orthogonal': scenarios, 'wrong_stock_price_total': rounded(p['units'] * p['down_prices'][-1]), 'checks': {'same_cost_despite_price_paths': scenarios[0]['final_cost'] == scenarios[2]['final_cost'], 'quantity_change_total': rounded((p['units'] - p['lower_units']) * p['grant_value'])}} def count_trueup(p): base = cumulative_counts(p['estimates'], p['units_each'], p['grant_value'], p['years']) reverse = cumulative_counts(p['reverse_estimates'], p['units_each'], p['grant_value'], p['years']) return {'base': base, 'reverse': reverse, 'wrong_current_only': [{'year': x['year'], 'wrong': rounded(F(x['people'] * p['units_each'] * p['grant_value'], p['years'])), 'difference_wrong_less_correct': rounded(F(x['people'] * p['units_each'] * p['grant_value'], p['years']) - F(x['current']))} for x in base], 'wrong_initial_people_total': rounded(p['initial_people'] * p['units_each'] * p['grant_value']), 'checks': {'final_actual_units': p['estimates'][-1] * p['units_each'], 'base_sum': rounded(sum(F(x['current']) for x in base)), 'reverse_sum': rounded(sum(F(x['current']) for x in reverse))}} def tranche_matrix(p): def schedule(waits): return [[F(t['units'] * t['grant_value'], waits[i]) if year <= waits[i] else F(0) for year in range(1, max(waits) + 1)] for i, t in enumerate(p['tranches'])] waits = [t['wait_years'] for t in p['tranches']] matrix = schedule(waits) total = sum(t['units'] * t['grant_value'] for t in p['tranches']) equal = F(total, max(waits)) rows = [] for i, t in enumerate(p['tranches']): rows.append({**t, 'total': rounded(t['units'] * t['grant_value']), 'progress': [f'{min(y, waits[i])}/{waits[i]}' for y in range(1, 4)], 'annual': [rounded(n) for n in matrix[i]]}) annual = [] for year in range(3): good = sum(row[year] for row in matrix) annual.append({'year': year + 1, 'correct': rounded(good), 'wrong_equal': rounded(equal), 'difference': rounded(good - equal)}) variant = schedule([3 for _ in waits]) return {'tranches': rows, 'annual': annual, 'all_wait_three': [{'year': y + 1, 'cost': rounded(sum(row[y] for row in variant))} for y in range(3)], 'checks': {'total': rounded(total), 'annual_sum': rounded(sum(sum(x) for x in matrix)), 'difference_sum': rounded(sum(F(x['difference']) for x in annual))}} def cash_liability(p): previous, old_progress, old_value = F(0), F(0), F(p['values'][0]) rows = [] for label, val, progress in zip(p['dates'], p['values'], p['progress']): progress = F(progress) value = F(val) target = p['units'] * progress * value service = p['units'] * (progress - old_progress) * old_value revalue = p['units'] * progress * (value - old_value) rows.append({'date': label, 'units': p['units'], 'unit_value': val, 'progress': str(progress), 'opening': rounded(previous), 'service_factor': rounded(service), 'value_factor': rounded(revalue), 'current_profit_charge': rounded(target - previous), 'before_payment': rounded(target), 'payment': rounded(target if label == p['dates'][-1] else 0), 'closing': rounded(0 if label == p['dates'][-1] else target)}) previous, old_progress, old_value = target, progress, value alternative = p['units'] * p['alternative_settle_value'] return {'rollforward': rows, 'alternative': [{'settle_value': p['alternative_settle_value'], 'opening': rows[-1]['opening'], 'revalue': rounded(alternative - F(rows[-1]['opening'])), 'payment': rounded(alternative), 'closing': rounded(0)}], 'checks': {'profit_charge_sum': rounded(sum(F(x['current_profit_charge']) for x in rows)), 'payment_sum': rounded(sum(F(x['payment']) for x in rows))}} def expiry(p): full = p['units'] * p['grant_value'] paths = [] for path, estimates in [('service_failed', [p['units'], 0]), ('vested_then_expired', [p['units'], p['units']])]: previous = F(0) for y, n in enumerate(estimates, 1): target = F(n * p['grant_value'] * y, p['wait_years']) paths.append({'path': path, 'date': f'{p["start_year"] + y - 1}-12-31', 'valid_units': n, 'cumulative_cost': rounded(target), 'current_cost': rounded(target - previous), 'capital_reserve': rounded(target)}) previous = target if path == 'vested_then_expired': paths.append({'path': path, 'date': p['expiry_date'], 'valid_units': 0, 'cumulative_cost': rounded(full), 'current_cost': rounded(0), 'capital_reserve': rounded(full)}) for row in paths: row['retained_earnings_effect'] = rounded(-F(row['cumulative_cost'])) row['total_equity_effect'] = rounded(F(row['capital_reserve']) - F(row['cumulative_cost'])) return {'timeline': paths, 'expiry_controls': [{'item': 'effective_option_units', 'before': p['units'], 'change': -p['units'], 'after': 0}, {'item': 'recognized_service_cost', 'before': full, 'change': 0, 'after': full}, {'item': 'total_owner_equity_change_from_expiry', 'before': 0, 'change': 0, 'after': 0}], 'checks': {'wrong_reversal_overstates_profit': rounded(full)}} def parent_child(p): if not p['parent_own_equity'] or p['child_obligation'] or p['recharge']: raise ValueError('本数值模型仅支持母公司自身权益结算、子公司无结算义务且无收费的已给定条件') yearly = F(p['units'] * p['grant_value'], p['wait_years']) entries = [] for year in range(p['wait_years']): entries.append({'year': p['start_year'] + year, 'parent_investment_debit': rounded(yearly), 'parent_reserve_credit': rounded(yearly), 'child_expense_debit': rounded(yearly), 'child_reserve_credit': rounded(yearly), 'elimination_child_reserve_debit': rounded(yearly), 'elimination_investment_credit': rounded(yearly), 'consolidated_expense': rounded(yearly), 'consolidated_parent_reserve': rounded(yearly)}) return {'entries': entries, 'conditions': [{'service_receiver': 'S', 'settler': 'P', 'parent_own_equity': p['parent_own_equity'], 'child_settlement_obligation': p['child_obligation'], 'recharge': p['recharge'], 'result': 'equity_service_and_parent_investment'}, {'service_receiver': 'S', 'settler': 'S', 'parent_own_equity': False, 'child_settlement_obligation': True, 'recharge': None, 'result': 'outside_this_model_need_contract_classification'}], 'checks': {'total_group_cost': rounded(yearly * p['wait_years']), 'wrong_omission_per_year': rounded(yearly), 'wrong_double_cost_per_year': rounded(yearly * 2)}} def transfers(p): total = p['units'] * p['grant_value'] monthly = F(total, p['months']) def calendar(first_months): return [{'month': f'{p["start_year"] + (m - 1) // 12}-{(m - 1) % 12 + 1:02}', 'receiver': 'A' if m <= first_months else 'B', 'cost': rounded(monthly)} for m in range(1, p['months'] + 1)] base = calendar(p['a_months']) alt = calendar(p['alternative_a_months']) def summary(rows): result = [] for year in sorted({r['month'][:4] for r in rows}): a = sum(F(r['cost']) for r in rows if r['month'].startswith(year) and r['receiver'] == 'A') b = sum(F(r['cost']) for r in rows if r['month'].startswith(year) and r['receiver'] == 'B') result.append({'year': int(year), 'a': rounded(a), 'b': rounded(b), 'group': rounded(a + b)}) return result return {'calendar': base, 'annual': summary(base), 'alternative_annual': summary(alt), 'allocation': [{'scenario': 'base', 'a_months': p['a_months'], 'b_months': p['months'] - p['a_months'], 'a_cost': rounded(monthly * p['a_months']), 'b_cost': rounded(monthly * (p['months'] - p['a_months'])), 'group': rounded(total)}, {'scenario': 'earlier_transfer', 'a_months': p['alternative_a_months'], 'b_months': p['months'] - p['alternative_a_months'], 'a_cost': rounded(monthly * p['alternative_a_months']), 'b_cost': rounded(monthly * (p['months'] - p['alternative_a_months'])), 'group': rounded(total)}]} def minority(p): expense = F(p['units'] * p['grant_value'], p['wait_years']) rows = [] for label, pre, ratio in [('base', p['child_before'], F(p['parent_ratio'])), ('wholly_owned', p['child_before'], F(1)), ('loss_after_charge', p['alternative_child_before'], F(p['parent_ratio']))]: child = F(pre) - expense parent_contribution = child * ratio nci = child * (1 - ratio) rows.append({'scenario': label, 'child_before': rounded(pre), 'expense': rounded(expense), 'child_after': rounded(child), 'parent_ratio': rounded(ratio, 6), 'parent_child_contribution': rounded(parent_contribution), 'minority_profit': rounded(nci), 'parent_own_profit': rounded(p['parent_own_profit']), 'group_profit': rounded(p['parent_own_profit'] + child), 'attributable_parent': rounded(p['parent_own_profit'] + parent_contribution), 'minority_expense_share': rounded(expense * (1 - ratio))}) return {'profit_bridge': [{'stage': 'before_charge', 'child': rounded(p['child_before']), 'parent_share': rounded(F(p['child_before']) * F(p['parent_ratio'])), 'minority_share': rounded(F(p['child_before']) * (1 - F(p['parent_ratio'])))}, {'stage': 'after_charge', 'child': rows[0]['child_after'], 'parent_share': rows[0]['parent_child_contribution'], 'minority_share': rows[0]['minority_profit']}], 'allocation': rows, 'settler': [{'parent_tool_service_amount': rounded(expense), 'child_service_expense': rounded(expense), 'additional_parent_profit_expense': rounded(0), 'parent_expense_share': rounded(expense * F(p['parent_ratio'])), 'minority_expense_share': rows[0]['minority_expense_share']}]} def repurchase(p): n, issue, par, price = p['shares'], p['issue_price'], p['par'], p['repurchase_price'] cash, capital, premium, obligation = n * issue, n * par, n * (issue - par), n * price def entry(stage, debit, credit): return {'stage': stage, 'debit': {k: rounded(v) for k, v in debit.items()}, 'credit': {k: rounded(v) for k, v in credit.items()}, 'debit_total': rounded(sum(debit.values())), 'credit_total': rounded(sum(credit.values()))} entries = [entry('registration', {'bank': cash}, {'share_capital': capital, 'share_premium': premium}), entry('recognize_repurchase', {'treasury': obligation}, {'repurchase_payable': obligation}), entry('unlock', {'repurchase_payable': obligation}, {'treasury': obligation}), entry('fail_payment', {'repurchase_payable': obligation}, {'bank': obligation}), entry('fail_cancel', {'share_capital': capital, 'share_premium': obligation - capital}, {'treasury': obligation})] states = [{'state': 'waiting', 'bank': cash, 'share_capital': capital, 'share_premium': premium, 'treasury': obligation, 'repurchase_payable': obligation}, {'state': 'unlock', 'bank': cash, 'share_capital': capital, 'share_premium': premium, 'treasury': 0, 'repurchase_payable': 0}, {'state': 'fail_cancelled', 'bank': cash - obligation, 'share_capital': 0, 'share_premium': premium - (obligation - capital), 'treasury': 0, 'repurchase_payable': 0}] for r in states: r['subledger_equity'] = r['share_capital'] + r['share_premium'] - r['treasury'] r['asset_less_liability'] = r['bank'] - r['repurchase_payable'] for k in list(r): if k != 'state': r[k] = rounded(r[k]) return {'entries': entries, 'states': states, 'checks': {'all_entries_balanced': all(x['debit_total'] == x['credit_total'] for x in entries), 'all_states_balanced': all(x['subledger_equity'] == x['asset_less_liability'] for x in states)}, 'boundary': 'only_subscription_and_repurchase_subledger_excludes_service_expense_and_tax'} def outsiders(p): calendar = [] for m in p['milestones']: equity = m['units'] * m['equity_value'] calendar.append({**m, 'service_branch': rounded(m['service_value']), 'equity_branch': rounded(equity), 'difference': rounded(m['service_value'] - equity)}) branches = [] for service, equity in p['evidence_states']: status = 'service_fair_value' if service else 'equity_at_service_date' if equity else 'pending_evidence' total = sum(m['service_value'] if service else m['units'] * m['equity_value'] for m in p['milestones']) if service or equity else None branches.append({'service_reliable': service, 'equity_reliable': equity, 'measurement': status, 'total': rounded(total) if total is not None else None}) wrong = sum(m['units'] for m in p['milestones']) * p['signing_unit_value'] return {'calendar': calendar, 'branches': branches, 'wrong_signing_value': {'total_units': sum(m['units'] for m in p['milestones']), 'unit_value': p['signing_unit_value'], 'wrong_total': rounded(wrong), 'understatement_service': rounded(F(branches[0]['total']) - wrong), 'understatement_equity': rounded(F(branches[1]['total']) - wrong)}} def disclosure(p): rows = [] for b in p['batches']: close = b['opening'] + b['granted'] - b['exercised'] - b['forfeited'] target = F(b['estimated_vested'] * b['grant_value']) * F(b['progress']) previous = F(b['previous_cumulative']) rows.append({**b, 'closing': close, 'target_cumulative': rounded(target), 'current_cost': rounded(target - previous)}) totals = {k: sum(r[k] for r in rows) for k in ['opening', 'granted', 'exercised', 'forfeited', 'closing']} costs = sum(F(r['current_cost']) for r in rows) exercise_day_price = F(sum(e['units'] * e['stock_price'] for e in p['exercise_events']), sum(e['units'] for e in p['exercise_events'])) return {'batches': rows, 'totals': {**totals, 'current_cost': rounded(costs)}, 'mapping': [{'batch': b['batch'], 'closing': b['closing'], 'exercise_price': b['exercise_price'], 'remaining_years': b['remaining_years']} for b in rows], 'disclosure': {'strike_low': min(b['exercise_price'] for b in rows if b['closing']), 'strike_high': max(b['exercise_price'] for b in rows if b['closing']), 'exercise_day_weighted_stock_price': rounded(exercise_day_price, 6), 'weighted_remaining_years': rounded(F(sum(b['closing'] * b['remaining_years'] for b in rows), totals['closing']), 6)}, 'comparison': [{'scenario': 'base', 'closing': totals['closing'], 'cost': rounded(costs)}, {'scenario': 'no_exercise_of_already_vested_A', 'closing': totals['closing'] + rows[0]['exercised'], 'cost': rounded(costs)}]} def build(): cases = { 'DJ4-023': (equity_lock, {'grant_date': '2026-01-01', 'grant_stock_price': 18, 'units': 60000, 'grant_value': 9, 'years': 3, 'down_prices': [18, 12, 6], 'up_prices': [18, 24, 30], 'lower_units': 48000}), 'DJ4-024': (count_trueup, {'start_year': 2026, 'initial_people': 100, 'units_each': 800, 'grant_value': 6, 'years': 3, 'estimates': [92, 80, 84], 'reverse_estimates': [92, 35, 84]}), 'DJ4-025': (tranche_matrix, {'grant_date': '2026-01-01', 'tranches': [ {'batch': 'A', 'units': 12000, 'grant_value': 6, 'wait_years': 1}, {'batch': 'B', 'units': 12000, 'grant_value': 7, 'wait_years': 2}, {'batch': 'C', 'units': 12000, 'grant_value': 8, 'wait_years': 3}]}), 'DJ4-026': (cash_liability, {'grant_date': '2026-01-01', 'units': 12000, 'dates': ['2026-12-31', '2027-12-31', '2028-12-31', '2029-06-30'], 'values': [8, 11, 9, 10], 'progress': ['1/3', '2/3', '1', '1'], 'alternative_settle_value': 6}), 'DJ4-027': (expiry, {'start_year': 2026, 'units': 10000, 'grant_value': 5, 'wait_years': 2, 'expiry_date': '2029-12-31'}), 'DJ4-028': (parent_child, {'start_year': 2026, 'units': 10000, 'grant_value': 12, 'wait_years': 2, 'parent_owns_all': True, 'parent_own_equity': True, 'child_obligation': False, 'recharge': False}), 'DJ4-029': (transfers, {'start_year': 2026, 'units': 2400, 'grant_value': 15, 'months': 24, 'a_months': 9, 'alternative_a_months': 6}), 'DJ4-030': (minority, {'units': 20000, 'grant_value': 12, 'wait_years': 2, 'child_before': 1000000, 'parent_ratio': '7/10', 'parent_own_profit': 200000, 'alternative_child_before': 80000}), 'DJ4-031': (repurchase, {'shares': 10000, 'issue_price': 5, 'par': 1, 'repurchase_price': 5, 'register_date': '2026-01-01', 'resolution_date': '2027-12-31', 'dividends': 0}), 'DJ4-032': (outsiders, {'sign_date': '2026-01-01', 'signing_unit_value': 6, 'evidence_states': [[True, True], [False, True], [False, False]], 'milestones': [ {'date': '2026-01-31', 'service': '界面评估', 'units': 1000, 'service_value': 9000, 'equity_value': 8}, {'date': '2026-04-30', 'service': '数据迁移', 'units': 1500, 'service_value': 12500, 'equity_value': 9}, {'date': '2026-07-31', 'service': '使用培训', 'units': 2000, 'service_value': 16000, 'equity_value': 7}]}), 'DJ4-033': (disclosure, {'report_date': '2026-12-31', 'batches': [ {'batch': 'A', 'opening': 20000, 'granted': 0, 'exercised': 5000, 'forfeited': 2000, 'exercise_price': 4, 'remaining_years': 1, 'grant_value': 5, 'estimated_vested': 20000, 'progress': '1', 'previous_cumulative': 100000}, {'batch': 'B', 'opening': 10000, 'granted': 0, 'exercised': 0, 'forfeited': 1000, 'exercise_price': 8, 'remaining_years': 3, 'grant_value': 6, 'estimated_vested': 9000, 'progress': '2/3', 'previous_cumulative': 19000}, {'batch': 'C', 'opening': 0, 'granted': 6000, 'exercised': 0, 'forfeited': 0, 'exercise_price': 10, 'remaining_years': 5, 'grant_value': 7, 'estimated_vested': 6000, 'progress': '1/4', 'previous_cumulative': 0}], 'exercise_events': [{'date': '2026-06-30', 'batch': 'A', 'units': 5000, 'stock_price': 12}]}) } return {identity: {'inputs': inputs, 'output': function(inputs)} for identity, (function, inputs) in cases.items()} if __name__ == '__main__': payload = json.dumps(build(), ensure_ascii=False, indent=2, allow_nan=False) + '\n' with Path(__file__).with_suffix('.json').open('w', encoding='utf-8', newline='\n') as output_file: output_file.write(payload)