Lawfare Group → Knowledge Institute → Lawfare Academy
Reproduce the worked examples
Copy the complete code below into a UTF-8 file named verify.py and run python verify.py with Python 3. It uses only the standard library and performs exact or rational synthetic calculations. It does not access a network or learner records. Assertions fail if the expected synthetic results change.
These checks verify the stated arithmetic and query behavior, not independent academic acceptance or production migration safety.
"""Original Financial Statement Analysis cases. Standard library; no network or learner data."""
from fractions import Fraction as F
import json
out={}
opening={'cash':20,'ar':60,'inventory':80,'ppe':140,'ap':50,'debt':100,'equity':150}
closing={'cash':25,'ar':90,'inventory':100,'ppe':165,'ap':65,'debt':120,'equity':195}
def assets(b):return sum(b[k] for k in ['cash','ar','inventory','ppe'])
def funding(b):return sum(b[k] for k in ['ap','debt','equity'])
assert assets(opening)==funding(opening)==300 and assets(closing)==funding(closing)==380
sales=600;cogs=360;cash_expense=150;depreciation=20;interest=10;tax=15
ebit=sales-cogs-cash_expense-depreciation;income=ebit-interest-tax
collections=opening['ar']+sales-closing['ar'];purchases=cogs+closing['inventory']-opening['inventory'];supplier_payments=opening['ap']+purchases-closing['ap']
cfo_direct=collections-supplier_payments-cash_expense-interest-tax
cfo_indirect=income+depreciation-(closing['ar']-opening['ar'])-(closing['inventory']-opening['inventory'])+(closing['ap']-opening['ap'])
assert ebit==70 and income==45 and collections==570 and purchases==380 and supplier_payments==365
assert cfo_direct==cfo_indirect==30
assert opening['equity']+income==closing['equity'] and opening['ppe']+45-depreciation==closing['ppe']
assert opening['cash']+cfo_direct-45+20==closing['cash']
out['statement_reconstruction']={'opening_assets':300,'closing_assets':380,'ebit':ebit,'income':income,'collections':collections,'purchases':purchases,'supplier_payments':supplier_payments,'direct_and_indirect_operating_cash':[cfo_direct,cfo_indirect],'cash_change':5,'operating_cash_less_capex':-15}
avg_assets=F(300+380,2);avg_equity=F(150+195,2);margin=F(45,600);turnover=F(600,avg_assets);multiplier=avg_assets/avg_equity;roe=F(45,avg_equity)
assert margin*turnover*multiplier==roe==F(6,23)
assert F(45,340)*multiplier==roe and F(45,195)==F(3,13)
assert F(5,100)*F(15,10)*2==F(15,100) and F(5,100)*F(15,10)*4==F(30,100)
out['dupont']={'average_assets':float(avg_assets),'average_equity':float(avg_equity),'net_margin':float(margin),'turnover':float(turnover),'equity_multiplier':float(multiplier),'roe_average_equity':float(roe),'roe_ending_equity':float(F(45,195)),'net_income_roa':float(F(45,340)),'operating_income_roa':float(F(70,340))}
current_liabilities=65+20;current_assets=25+90+100
assert current_assets==215 and current_liabilities==85
ar_loss=dict(closing);ar_loss['ar']-=20;ar_loss['equity']-=20
assert assets(ar_loss)==funding(ar_loss)==360 and ar_loss['cash']==25
adjusted_income=45-20
net_method=adjusted_income+20-(ar_loss['ar']-opening['ar'])-(ar_loss['inventory']-opening['inventory'])+(ar_loss['ap']-opening['ap'])
gross_method=adjusted_income+20+20-(90-60)-(100-80)+(65-50)
assert net_method==gross_method==30
dio=F(90,360)*365;dso=F(75,600)*365;dpo=F(115,2)/380*365;dpo_proxy=F(115,2)/360*365
cycle=dio+dso-dpo;proxycycle=dio+dso-dpo_proxy
assert dio==F(365,4) and dso==F(365,8) and F(90,600)*365==F(219,4)
out['liquidity_and_quality']={'reported_current_ratio':float(F(215,85)),'reported_quick_ratio':float(F(115,85)),'cash_ratio':float(F(25,85)),'ar_adjusted_current_ratio':float(F(195,85)),'ar_adjusted_quick_ratio':float(F(95,85)),'ar_adjusted_income':adjusted_income,'operating_cash_after_non_cash_adjustment':net_method,'inventory_days':float(dio),'receivable_days_average':float(dso),'payable_days_purchases':float(dpo),'cycle_purchases':float(cycle),'payable_days_cogs_proxy':float(dpo_proxy),'cycle_cogs_proxy':float(proxycycle),'receivable_days_ending':54.75}
peer_a={'sales':600,'cogs':360,'cash_expense':150,'depreciation':20};peer_b={'sales':600,'cogs':330,'cash_expense':180,'depreciation':20}
def operating(p):return p['sales']-p['cogs']-p['cash_expense']-p['depreciation']
assert operating(peer_a)==operating(peer_b)==70
normalized_b=dict(peer_b);normalized_b['cogs']+=30;normalized_b['cash_expense']-=30
assert normalized_b==peer_a
assert F(600-330,600)==F(45,100) and F(600-360,600)==F(40,100)
assert 82-12+8==78 and 82+20==102 and 78+20==98
assert (600-480)/480==0.25 and (600-60-480)/480==0.125
assert 20-8==12
out['comparability']={'peer_reported_gross_margins':[0.4,0.45],'normalized_gross_margins':[0.4,0.4],'both_operating_profit':70,'reported_operating_profit':82,'proposed_adjusted_operating_profit':78,'reported_plus_da':102,'adjusted_plus_da':98,'reported_growth':0.25,'constant_perimeter_growth':0.125,'separate_disposal_proceeds':20,'disposal_gain':12}
def forecast(ar_end):
sales=720;cogs=432;cash_expense=180;depreciation=22;interest=12;tax=18;capex=50;distribution=10
income=sales-cogs-cash_expense-depreciation-interest-tax
inv=120;ap=78;ppe=closing['ppe']+capex-depreciation;equity=closing['equity']+income-distribution
cfo=income+depreciation-(ar_end-closing['ar'])-(inv-closing['inventory'])+(ap-closing['ap'])
pre=closing['cash']+cfo-capex-distribution;required=30-pre
end={'cash':30,'ar':ar_end,'inventory':inv,'ppe':ppe,'ap':ap,'debt':closing['debt']+required,'equity':equity}
assert assets(end)==funding(end)
assert closing['cash']+cfo-capex+required-distribution==end['cash']
return dict(income=income,operating_cash=cfo,pre_financing_cash=pre,required_financing=required,ending_balance=end,assets=assets(end))
base=forecast(108);stress=forecast(180)
assert base['income']==56 and base['operating_cash']==53 and base['pre_financing_cash']==18 and base['required_financing']==12 and base['assets']==451
assert base['ending_balance']['debt']==132 and base['ending_balance']['equity']==241
assert stress['income']==56 and stress['operating_cash']==-19 and stress['required_financing']==84 and stress['assets']==523 and stress['ending_balance']['debt']==204
assert stress['pre_financing_cash']+40==-14 and 30-(-14)==44
out['forecast_coherence']={'base':base,'collection_delay':stress,'facility_40_shortfall':44}
cash_before_interest=30+10;service=10+40
assert F(cash_before_interest,service)==F(4,5) and F(90,service)==F(9,5)
assert F(cash_before_interest-15,service)==F(1,2) and 30-40-15==-25
assert 25+30-40-15==0 and 10-0==10
assert F(12,10)*50-40==20
lost_revenue=F(25,100)*600;lost_contribution=F(40,100)*lost_revenue
assert lost_revenue==150 and lost_contribution==60 and 70-lost_contribution==10
assert 70*F(2,100)==F(7,5)
bb=(90-20)*F(8,10)+60*F(1,2);headroom=min(bb,100)-80;stressed_bb=(90-40)*F(8,10)+60*F(1,2)
assert bb==86 and headroom==6 and stressed_bb==70 and 80-stressed_bb==10
out['credit_judgment']={'cash_coverage_before_maintenance':0.8,'ebitda_coverage':1.8,'cash_coverage_after_maintenance':0.5,'cash_after_operating_principal_maintenance':-25,'gap_to_reserve_from_opening_cash':10,'hypothetical_coverage_numerator_gap':20,'customer_loss_operating_income':10,'interest_increase_two_points':1.4,'borrowing_base':86,'facility_headroom':6,'stressed_borrowing_base':70,'draw_over_stressed_base':10}
overlay=dict(closing);overlay['ar']-=20;overlay['inventory']-=15;overlay['equity']-=35
assert assets(overlay)==funding(overlay)==345
overlay_income=45-35;overlay_cfo=overlay_income+20-(overlay['ar']-opening['ar'])-(overlay['inventory']-opening['inventory'])+(overlay['ap']-opening['ap'])
assert overlay_income==10 and overlay_cfo==30 and overlay['cash']==25
assert F(25+70+85,85)==F(36,17) and F(25+70,85)==F(19,17)
out['cumulative_dossier']={'combined_losses':35,'adjusted_income':10,'adjusted_assets':345,'adjusted_equity':160,'cash_unchanged':25,'operating_cash_net_balance_method':30,'adjusted_current_ratio':float(F(180,85)),'adjusted_quick_ratio':float(F(95,85)),'unqualified_growth_funding_supported':False}
# Retain a check of the native unit's separate original example.
assert 30+45-20==55
out['preserved_native_example']={'original_cash_conversion_cycle':55}
print(json.dumps({'passed':True,'cases':out},indent=2))
Related chapters
- Reconstruct the business before interpreting the ratios
- Decompose return and test the denominator
- Test the quality behind current assets and conversion days
- Normalize the comparison without rewriting the evidence
- Make the forecast balance for an economic reason
- Turn ratios into a conditional credit and investment judgment
- Statement analysis clinic: reconcile the evidence before recommending action