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.

"""Synthetic small-business valuation and finance laboratory. Python 3, standard library.
All monetary amounts are thousands. Hypothetical assumptions are not market quotes,
legal rules, tax rates, lending approval or a forecast of any actual business.
No network, production system or learner records are accessed.
"""
from math import isclose
import json

checks={}
def check(name,actual,expected):
    assert isclose(actual,expected,rel_tol=1e-10,abs_tol=1e-9),(name,actual,expected)
    checks[name]=actual
def pv(cash,rate):return sum(v/(1+rate)**t for t,v in enumerate(cash))
def payment(principal,rate,years):return principal*rate/(1-(1+rate)**(-years))

normalized=160-(60-20)+10+12-(24-12)
check('transferable EBITDA',normalized,130)
sde=160+20+10+12
check('seller discretionary illustration',sde,202)
check('SDE normalized back to transferable EBITDA',sde-60-12,normalized)
cash=normalized-20-10-25
check('unlevered operating cash',cash,75)
flows=[75,80,85,90,95];r=.13;g=.03
terminal=flows[-1]*(1+g)/(r-g)
check('terminal at year five',terminal,978.5)
enterprise=pv([0]+flows,r)+terminal/(1+r)**5
check('DCF enterprise value',enterprise,825.7841566659888)
check('terminal present value fraction',terminal/(1+r)**5/enterprise,.6431348834781224)
check('defined EBITDA multiple comparison',normalized*5.5,715)
check('wrong SDE multiple basis',sde*5.5,1111)

check('project initial economic investment',60+5+8,73)
check('project actual initial cheques',60+5,65)
project=pv([-73,25,27,29+12+5],.12)
check('project NPV',project,3.5875546647230188)
check('reduced working capital recovery NPV',pv([-73,25,27,29+12+2],.12),project-3/1.12**3)
assert -73+25+27<0 and -73+25+27+46>0 # strictly year-end receipts: payback year 3
buy=60+pv([0,4,4,4-12],.12)
lease=pv([22,22,22],.12)
check('equivalent buy cost PV',buy,61.065962099125365)
check('equivalent advance lease cost PV',lease,59.18112244897959)
check('lease PV advantage',buy-lease,1.884839650145775)

nwc=80+30-35;shortfall=90-nwc
equity_price=700-120+30-shortfall
check('eligible closing NWC',nwc,75)
check('equity consideration',equity_price,595)
uses=equity_price+120+25+40
check('nominal sources and uses',uses,780)
check('heavy funding balances',450+150+180,uses)
check('seller cash proceeds',equity_price-150,445)
check('cash funding balances',450+180,(equity_price-150)+120+25+40)
check('new acquisition debt',450+150,600)
bank=payment(450,.08,5);light=payment(200,.08,5)
check('heavy bank annual payment',bank,112.70540455507638)
check('heavy first principal payment',bank-450*.08,76.70540455507638)
check('heavy first remaining principal',450-(bank-36),373.2945954449236)
balance=450
for year in range(1,6):balance-=bank-balance*.08
check('five-year amortization remaining balance',balance,0)
service=bank+150*.06
check('heavy years one to four service',service,121.70540455507638)
check('heavy final balloon year service',service+150,271.70540455507637)
check('light annual service',light,50.09129091336728)
balance=200
for year in range(1,6):balance-=light-balance*.08
check('light five-year remaining balance',balance,0)
check('light funding balances',200+580,uses)
check('extra equity in lower-debt alternative',580-180,400)

check('heavy cash coverage',75/service,.6162421486061419)
check('heavy annual cash deficit',service-75,46.70540455507638)
check('EBITDA coverage is different',130/service,1.0681530575839793)
check('light cash coverage',75/light,1.4972662639042833)
check('downside light coverage',60/light,1.1978130111234266)
check('cash needed for hypothetical 1.25 minimum',1.25*light-60,2.6141136417091)
check('heavy year-five shortfall',service+150-95,176.70540455507637)

season=[-30,-25,20,-15,35,90]
assert sum(season)==75
running=70;unfinanced=[]
for x in season:running+=x;unfinanced.append(running)
assert unfinanced==[40,15,35,20,55,145]
def revolver(term_service):
    cash=70;debt=0;peak=0;draws=[];records=[]
    for i,change in enumerate(season):
        cash+=change
        if i==5:cash-=term_service # annual term payment at final interval
        if cash<30:
            draw=30-cash;debt+=draw;cash+=draw;draws.append(draw)
        else:
            repay=min(debt,cash-30);cash-=repay;debt-=repay
        peak=max(peak,debt);records.append([cash,debt])
    return cash,debt,peak,draws,records
l=revolver(light);h=revolver(service)
check('light ending cash',l[0],94.90870908663272)
check('light ending revolver',l[1],0)
check('light peak revolver',l[2],15)
check('heavy ending cash floor',h[0],30)
check('heavy ending revolver',h[1],6.70540455507638)
check('heavy peak revolver',h[2],15)
check('heavy total draws',sum(h[3]),31.70540455507638)
checks['seasonal light cash and debt']=l[4];checks['seasonal heavy cash and debt']=h[4]

revised_nwc=(80-10)+(30-8)-35
check('diligence revised NWC',revised_nwc,57)
revised_price=700-120+30-(90-revised_nwc)
check('revised equity consideration',revised_price,577)
check('price reduction from diligence',equity_price-revised_price,18)
check('AR-only adjusted equity price',700-120+30-(90-((80-10)+30-35)),585)
earnout=50*.4/1.12**2
check('illustrative expected earnout present value',earnout,15.943877551020407)
check('illustrative expected consideration',595+earnout,610.9438775510204)
check('lost concentrated contribution',1000*.35*.4,140)
check('concentrated loss EBITDA',130-140,-10)
check('year-two light debt cash residual',80-light,29.90870908663272)
check('triggered earnout exceeds year residual',50-(80-light),20.09129091336728)
revised_uses=revised_price+120+25+40
check('revised closing uses',revised_uses,762)
check('revised light buyer equity',revised_uses-200,562)
check('unchanged financing excess',780-revised_uses,18)
timing_loss=30/1.13-30/1.13**2
check('collection delay present value loss',timing_loss,3.0542720651578037)
check('delay NPV bridge',pv([0]+flows,r)-pv([0,45,110,85,90,95],r),timing_loss)
print(json.dumps({'passed':True,'checks':checks,'assumptions':'Synthetic thousands; year-end flows except stated advance lease; zero-cost revolver only for isolating timing; fictional rates and thresholds; no actual tax or legal rates.'},indent=2))

Related chapters