"""Illustrative fully diluted ownership model for up to three priced primary rounds. No network, dependencies or source-file writes. Reads a JSON scenario and prints JSON. All six scope assumptions must be explicitly confirmed. Does not model legal rights. """ import json import sys from decimal import Decimal, localcontext from fractions import Fraction ASSUMPTIONS = {'priced_primary_equity_only', 'fixed_option_pool', 'no_convertibles', 'no_secondary', 'no_other_share_changes', 'equal_price_per_round'} def keys(value, required, where): if not isinstance(value, dict) or set(value) != set(required): raise ValueError(where + ': fields must be exactly ' + ', '.join(sorted(required))) def number(value, where, positive=False): if isinstance(value, bool) or not isinstance(value, (int, str)): raise ValueError(where + ': use an integer or decimal string') try: result = Fraction(value) except (ValueError, ZeroDivisionError): raise ValueError(where + ': invalid number') from None if result < 0 or (positive and result == 0): raise ValueError(where + ': must be ' + ('positive' if positive else 'nonnegative')) return result def label(value, where): if not isinstance(value, str) or not value.strip(): raise ValueError(where + ': nonempty text required') return value.strip() def display(value, digits=8): with localcontext() as c: c.prec = 60 return format(Decimal(value.numerator) / Decimal(value.denominator), '.' + str(digits) + 'f') def positions(holdings, kinds): total = sum(holdings.values(), Fraction(0)) assert total > 0 return [{'name': name, 'kind': kinds[name], 'units_exact': str(units), 'ownership_percent': display(units / total * 100, 6)} for name, units in holdings.items()] def model(data): keys(data, {'currency', 'share_basis', 'assumptions', 'holders', 'rounds'}, 'scenario') currency = label(data['currency'], 'currency') if len(currency) != 3 or not currency.isascii() or not currency.isalpha() or not currency.isupper(): raise ValueError('currency: supply one uppercase three-letter currency code') if data['share_basis'] != 'fully_diluted': raise ValueError('share_basis: this model requires a confirmed fully_diluted denominator') keys(data['assumptions'], ASSUMPTIONS, 'assumptions') if not all(v is True for v in data['assumptions'].values()): raise ValueError('Unsupported or unconfirmed assumptions: clarify before modeling') if not isinstance(data['holders'], list) or not data['holders']: raise ValueError('holders: nonempty list required') if not isinstance(data['rounds'], list) or not 0 <= len(data['rounds']) <= 3: raise ValueError('rounds: supply zero to three priced rounds') holdings, kinds = {}, {} for row in data['holders']: keys(row, {'name', 'kind', 'units'}, 'holder') name = label(row['name'], 'holder name') if name.casefold() in {n.casefold() for n in holdings}: raise ValueError('Duplicate holder name: ' + name) if row['kind'] not in ('founder', 'investor', 'employee', 'option_pool', 'other'): raise ValueError('holder kind: unsupported value') holdings[name] = number(row['units'], 'holder units') kinds[name] = row['kind'] if sum(holdings.values()) <= 0: raise ValueError('Starting fully diluted units must be positive') starting = positions(holdings, kinds) output = [] round_names = set() for r in data['rounds']: keys(r, {'name', 'pre_money', 'raise', 'investors'}, 'round') name = label(r['name'], 'round name') if name.casefold() in round_names: raise ValueError('Round names must be distinct') round_names.add(name.casefold()) pre = number(r['pre_money'], 'pre_money', positive=True) cash = number(r['raise'], 'raise', positive=True) if not isinstance(r['investors'], list) or not r['investors']: raise ValueError('investors: nonempty list required') investments = {} for i in r['investors']: keys(i, {'name', 'amount'}, 'investor') investor = label(i['name'], 'investor name') if investor.casefold() in {n.casefold() for n in investments}: raise ValueError('Duplicate investor within round: ' + investor) matches = [n for n in holdings if n.casefold() == investor.casefold()] if matches and matches[0] != investor: raise ValueError('Use exactly the existing holder label: ' + matches[0]) if investor in kinds and kinds[investor] == 'option_pool': raise ValueError('An option reserve cannot invest cash') investments[investor] = number(i['amount'], 'investment amount') if sum(investments.values()) != cash: raise ValueError('Investment amounts must sum exactly to raise') before = dict(holdings) initial_total = sum(before.values()) price = pre / initial_total issued = {investor: amount / price for investor, amount in investments.items()} for investor, units in issued.items(): holdings[investor] = holdings.get(investor, Fraction(0)) + units kinds.setdefault(investor, 'investor') total = sum(holdings.values()) new_total = sum(issued.values()) assert total == initial_total + new_total assert new_total / total == cash / (pre + cash) assert sum(units / total for units in holdings.values()) == 1 changes = [] for holder, old_units in before.items(): old_pct = old_units / initial_total * 100 new_pct = holdings[holder] / total * 100 changes.append({'name': holder, 'before_percent': display(old_pct, 6), 'after_percent': display(new_pct, 6), 'percentage_point_change': display(new_pct - old_pct, 6), 'participated': issued.get(holder, 0) > 0}) output.append({'name': name, 'pre_money_exact': str(pre), 'post_money_exact': str(pre + cash), 'raise_exact': str(cash), 'price_per_unit': display(price), 'price_per_unit_exact': str(price), 'initial_units_exact': str(initial_total), 'new_units_exact': str(new_total), 'total_units_exact': str(total), 'round_investment_ownership_percent': display(new_total / total * 100, 6), 'issuance': [{'name': n, 'amount_exact': str(investments[n]), 'new_units_exact': str(u)} for n, u in issued.items()], 'fractional_units_present': any(u.denominator != 1 for u in holdings.values()), 'positions': positions(holdings, kinds), 'changes': changes, 'checks': {'investment_total_matches': True, 'exact_ownership_total_is_one': True, 'units_reconcile': True}}) return {'currency': currency, 'share_basis': 'fully_diluted', 'notice': 'Illustrative ownership units, not issued-share registry, voting rights or exit proceeds. Percentages rounded to six decimals; *_exact fields retain rational values. Fixed option reserve is counted once and is not a legal shareholder.', 'starting_positions': starting, 'rounds': output} if __name__ == '__main__': try: if len(sys.argv) != 2: raise ValueError('Usage: python3 calculate.py scenario.json') with open(sys.argv[1], encoding='utf-8') as f: source = json.load(f, parse_float=str) print(json.dumps(model(source), indent=2, ensure_ascii=False)) except (ValueError, OSError, TypeError) as exc: print('Cannot calculate: ' + str(exc), file=sys.stderr) sys.exit(2)