"""Reproduce AMD article arithmetic. Run from the workspace: python -I scripts/amd_cash_bridge.py scripts/amd_inputs.json outputs All amounts are USD millions. Decimal arithmetic; percentages rounded half-up. No statistical model, valuation model, or market-price analysis is performed. """ import json import sys from decimal import Decimal as D, ROUND_HALF_UP from pathlib import Path inputs = json.loads(Path(sys.argv[1]).read_text()) out = Path(sys.argv[2]) out.mkdir(parents=True, exist_ok=True) def dec(row, key): return D(row[key]) def pct(n, d): return str((n / d * 100).quantize(D('0.01'), rounding=ROUND_HALF_UP)) quarters = inputs['quarters'] results = {'unit': inputs['unit'], 'rounding': 'Decimal, percentages to 2 decimal places, half-up', 'quarters': {}, 'nine_months': {}} wc_keys = ['receivables_cf', 'inventory_cf', 'prepaids_other_assets_cf', 'payables_cf', 'accrued_other_liabilities_cf'] for period, row in quarters.items(): rev, cfo, capex = (dec(row, k) for k in ['revenue', 'continuing_cfo', 'capex']) fcf = cfo - capex item = {'revenue': str(rev), 'continuing_cfo': str(cfo), 'capex': str(capex), 'fcf': str(fcf), 'fcf_margin_pct': pct(fcf, rev), 'gaap_operating_margin_pct': pct(dec(row, 'gaap_operating_income'), rev)} if 'payables_cf' in row: wc = sum((dec(row, k) for k in wc_keys), D(0)) item.update({'operating_asset_liability_cash_effect': str(wc), 'cfo_before_operating_asset_liability_changes': str(cfo-wc)}) if 'debt' in row: item['cash_plus_short_term_investments_less_debt'] = str(dec(row, 'cash_short_term_investments') - dec(row, 'debt')) results['quarters'][period] = item for year, row in inputs['nine_months'].items(): rev, cfo, capex = (dec(row, k) for k in ['revenue', 'continuing_cfo', 'continuing_capex']) fcf = cfo-capex results['nine_months'][year] = {'revenue':str(rev), 'continuing_cfo':str(cfo), 'capex':str(capex), 'fcf':str(fcf), 'fcf_margin_pct':pct(fcf,rev)} a, b, prev = quarters['Q3_2026'], quarters['Q3_2025'], quarters['Q2_2026'] ra, rb = results['quarters']['Q3_2026'], results['quarters']['Q3_2025'] bridge = {k: str(dec(a,k)-dec(b,k)) for k in wc_keys} results['year_on_year'] = { 'revenue_growth_pct':pct(dec(a,'revenue')-dec(b,'revenue'),dec(b,'revenue')), 'gaap_operating_income_growth_pct':pct(dec(a,'gaap_operating_income')-dec(b,'gaap_operating_income'),dec(b,'gaap_operating_income')), 'fcf_change_pct':pct(D(ra['fcf'])-D(rb['fcf']),D(rb['fcf'])), 'revenue_increase':str(dec(a,'revenue')-dec(b,'revenue')), 'data_center_revenue_increase':str(dec(a,'data_center_revenue')-dec(b,'data_center_revenue')), 'data_center_share_of_revenue_increase_pct':pct(dec(a,'data_center_revenue')-dec(b,'data_center_revenue'),dec(a,'revenue')-dec(b,'revenue')), 'non_data_center_revenue_change':str((dec(a,'revenue')-dec(a,'data_center_revenue'))-(dec(b,'revenue')-dec(b,'data_center_revenue'))), 'cfo_before_working_capital_change':str(D(ra['cfo_before_operating_asset_liability_changes'])-D(rb['cfo_before_operating_asset_liability_changes'])), 'working_capital_line_changes':bridge, 'working_capital_total_change':str(D(ra['operating_asset_liability_cash_effect'])-D(rb['operating_asset_liability_cash_effect'])), 'continuing_cfo_change':str(dec(a,'continuing_cfo')-dec(b,'continuing_cfo')), 'capex_increase':str(dec(a,'capex')-dec(b,'capex')), 'fcf_change':str(D(ra['fcf'])-D(rb['fcf'])) } q3_adjustments = ['net_income','depreciation_amortization','acquisition_intangible_amortization','sbc','investment_gains_cf','noncash_customer_warrants_cf','deferred_taxes_cf','other_adjustments_cf'] results['q3_2026_cfo_bridge'] = {k: a[k] for k in q3_adjustments+wc_keys} results['q3_2026_cfo_bridge']['sum'] = str(sum((dec(a,k) for k in q3_adjustments+wc_keys),D(0))) results['liquidity'] = {'qoq_liquid_assets_change':str(dec(a,'cash_short_term_investments')-dec(prev,'cash_short_term_investments')), 'qoq_debt_change':str(dec(a,'debt')-dec(prev,'debt')), 'qoq_net_liquid_assets_change':str(D(ra['cash_plus_short_term_investments_less_debt'])-D(results['quarters']['Q2_2026']['cash_plus_short_term_investments_less_debt'])), 'q3_net_debt_issuance_cash':str(dec(a,'debt_issuance_proceeds_net')-dec(a,'debt_repayments'))} results['scenario_no_payables_contribution'] = {'assumption':inputs['scenarios']['no_payables_contribution']['assumption'], 'continuing_cfo':str(dec(a,'continuing_cfo')-dec(a,'payables_cf')), 'fcf':str(D(ra['fcf'])-dec(a,'payables_cf'))} g=inputs['guidance'] mid=dec(g,'revenue_midpoint') results['guidance_arithmetic']={'revenue_midpoint':str(mid),'revenue_low':str(mid*(1-dec(g,'revenue_range_fraction'))),'revenue_high':str(mid*(1+dec(g,'revenue_range_fraction'))),'qoq_revenue_growth_pct':pct(mid-dec(a,'revenue'),dec(a,'revenue')),'implied_non_gaap_gross_profit_at_midpoint':str(mid*dec(g,'non_gaap_gross_margin_pct')/100),'non_gaap_gross_profit_increase_vs_q3':str(mid*dec(g,'non_gaap_gross_margin_pct')/100-dec(a,'non_gaap_gross_profit'))} results['formulas']={'fcf':'continuing_cfo - purchases_of_property_and_equipment','fcf_margin_pct':'100 * fcf / revenue','cash_bridge':'cfo_before_operating_asset_liability_changes + sum(operating_asset_liability_cash_effects) = continuing_cfo','growth_pct':'100 * (current - prior) / prior','net_liquid_assets':'cash + short_term_investments - reported_total_debt; excludes leases and other obligations'} (out/'calculations.json').write_text(json.dumps(results,indent=2)+'\n') lines=['# AMD calculation tables','', 'Amounts in USD millions; percentages calculated with Decimal and rounded half-up.','', '## Quarterly continuing-operations comparison','', '| Period | Revenue | Operating cash flow | Capex | Free cash flow | FCF margin |','|---|---:|---:|---:|---:|---:|'] for p,r in results['quarters'].items(): lines.append(f"| {p} | {r['revenue']} | {r['continuing_cfo']} | {r['capex']} | {r['fcf']} | {r['fcf_margin_pct']}% |") lines += ['', '## Nine-month continuing-operations history', '', '| Year | Revenue | Operating cash flow | Capex | Free cash flow | FCF margin |','|---|---:|---:|---:|---:|---:|'] for p,r in results['nine_months'].items(): lines.append(f"| {p} | {r['revenue']} | {r['continuing_cfo']} | {r['capex']} | {r['fcf']} | {r['fcf_margin_pct']}% |") lines += ['', '## Q3 2026 cash bridge', '', '| Item | Cash effect |', '|---|---:|'] for k,v in results['q3_2026_cfo_bridge'].items(): lines.append(f'| {k} | {v} |') lines += ['', '## Public sources', '', *[f"- {key}: {val['url']}" for key,val in inputs['sources'].items()], '', 'Inputs and formulas are retained in the accompanying reproduction files. Only company disclosures are used; scenarios are explicitly labelled in calculations.json.'] (out/'calculation-tables.md').write_text('\n'.join(lines)+'\n') print(json.dumps(results,indent=2))