import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
class StartupCapTable:
"""
Anti-Dilution Modeling Kit for Startups.
Features:
- Multiple funding rounds with pre-money valuations, raise amounts, post-money option pools.
- Anti-dilution: None, Full Ratchet, Narrow WA, Broad WA.
- Liquidation preferences: Per-round multiple, participating/non-participating.
- Exit waterfalls for acquisitions.
- Pro-rata rights calculation.
- Cap table tracking (fully diluted).
- Plots: Ownership pie, Exit waterfall bar chart.
Assumptions/Simplifications:
- Founders shares fixed at init (no further issuances).
- Option pool: Unallocated (dilutes in FD basis); no issued options modeled (set issued_options=0).
- All preferred pari passu (pro-rata prefs).
- Anti-dilution applies to ALL previous rounds uniformly.
- Pro-rata based on fully diluted ownership pre-new round.
- Exit: Unallocated pool dilutes common holders.
"""
def __init__(self, founder_shares=10_000_000, issued_options=0):
self.founder_shares = founder_shares
self.issued_options = issued_options # Issued employee options (dilute common)
self.unallocated_pool = 0.0
self.rounds = [] # List of round dicts
self.fd_shares = founder_shares + issued_options # Initial FD
self.anti_dilution_type = 'none' # 'none', 'full_ratchet', 'narrow_wa', 'broad_wa'
self.cap_table_history = [] # List of cap table DataFrames
def update_cap_table(self):
"""Update and store cap table DataFrame."""
data = []
total_outstanding = self.founder_shares + self.issued_options + sum(r['shares'] for r in self.rounds)
data.append({'Stakeholder': 'Founders', 'Outstanding Shares': self.founder_shares,
'Outstanding %': self.founder_shares / total_outstanding * 100 if total_outstanding > 0 else 0,
'FD Shares': self.founder_shares, 'FD %': self.founder_shares / self.fd_shares * 100})
data.append({'Stakeholder': 'Issued Options', 'Outstanding Shares': self.issued_options,
'Outstanding %': self.issued_options / total_outstanding * 100 if total_outstanding > 0 else 0,
'FD Shares': self.issued_options, 'FD %': self.issued_options / self.fd_shares * 100})
data.append({'Stakeholder': 'Unallocated Pool', 'Outstanding Shares': 0,
'Outstanding %': 0, 'FD Shares': self.unallocated_pool, 'FD %': self.unallocated_pool / self.fd_shares * 100})
for r in self.rounds:
conv_ratio = r['issue_price'] / r['conv_price']
data.append({'Stakeholder': f"{r['name']} (conv ratio {conv_ratio:.2f}x)",
'Outstanding Shares': r['shares'],
'Outstanding %': r['shares'] / total_outstanding * 100,
'FD Shares': r['shares'] * conv_ratio,
'FD %': (r['shares'] * conv_ratio) / self.fd_shares * 100})
df = pd.DataFrame(data)
self.cap_table_history.append(df)
return df
def add_round(self, name, pre_val, amount_raised, new_pool_pct_post=0.15, pref_multiple=1.0,
participating=True, anti_dilution_override=None):
"""
Add a funding round.
:param name: str, e.g. 'A'
:param pre_val: float, pre-money valuation
:param amount_raised: float, new money raised
:param new_pool_pct_post: float, target new total pool % post-money (0.0-0.25 typical)
:param pref_multiple: float, liq pref multiple (1.0 typical)
:param participating: bool, participating preferred?
:param anti_dilution_override: str, override class anti_dilution_type for this round
"""
if amount_raised <= 0 or pre_val <= 0:
raise ValueError("pre_val and amount_raised must be positive.")
ad_type = anti_dilution_override or self.anti_dilution_type
# Step 1: Tentative calcs ignoring anti-dilution (doesn't affect share count)
r = 1 + amount_raised / pre_val
pre_fd_target = self.fd_shares / (1 - new_pool_pct_post * r)
if 1 - new_pool_pct_post * r <= 0:
raise ValueError("Option pool too large for valuation.")
new_pool_increment = pre_fd_target - self.fd_shares
new_price = pre_val / pre_fd_target
new_shares = amount_raised / new_price
post_fd = self.fd_shares + new_pool_increment + new_shares
# Step 2: Apply anti-dilution if triggered
if ad_type != 'none' and self.rounds and new_price < min(r['conv_price'] for r in self.rounds):
if ad_type == 'full_ratchet':
new_conv = new_price
elif ad_type == 'narrow_wa':
protected_base = sum(r['pref_base'] for r in self.rounds)
protected_shares = sum(r['shares'] for r in self.rounds)
total_base = protected_base + amount_raised
total_shares = protected_shares + new_shares
new_conv = total_base / total_shares
elif ad_type == 'broad_wa':
protected_base = sum(r['pref_base'] for r in self.rounds)
common_out = self.founder_shares + self.issued_options
total_base = protected_base + amount_raised
total_shares = common_out + self.unallocated_pool + sum(r['shares'] for r in self.rounds) + new_shares
new_conv = total_base / total_shares
else:
raise ValueError("Invalid anti-dilution type.")
# Update all previous rounds' conv_price
for prev_round in self.rounds:
prev_round['conv_price'] = min(prev_round['conv_price'], new_conv)
# Step 3: Add the new round (init conv_price = new_price)
new_round = {
'name': name,
'shares': new_shares,
'issue_price': new_price,
'conv_price': new_price,
'pref_base': amount_raised,
'multiple': pref_multiple,
'participating': participating
}
self.rounds.append(new_round)
# Step 4: Update pools and FD
self.unallocated_pool += new_pool_increment
self.fd_shares = post_fd
# Update cap table
cap_table = self.update_cap_table()
print(f"\n--- Round {name} Complete ---")
print(f"Pre-money Val: ${pre_val/1e6:.1f}M | Raised: ${amount_raised/1e6:.1f}M")
print(f"Pre-money FD Shares: {pre_fd_target:,.0f} | Price/Share: ${new_price:.4f}")
print(f"New Shares: {new_shares:,.0f} | New Pool Add: {new_pool_increment:,.0f}")
print(f"Post-money Val: ${(pre_val + amount_raised)/1e6:.1f}M | Post FD Shares: {post_fd:,.0f}")
print(cap_table.round(2))
return cap_table
def compute_pro_rata(self, round_name, future_amount_raised):
"""Pro-rata amount for a round's investors to maintain FD %."""
round_data = next((r for r in self.rounds if r['name'] == round_name), None)
if not round_data:
raise ValueError(f"Round {round_name} not found.")
fd_pct = round_data['shares'] / (self.fd_shares - sum(r['shares'] * (r['issue_price']/r['conv_price'] - 1) for r in self.rounds)) # Approx nominal FD %
# Precise: nominal shares / current pre-new FD shares
pro_rata_shares_pre = round_data['shares']
pro_rata_amount = (pro_rata_shares_pre / self.fd_shares) * future_amount_raised
return pro_rata_amount
def exit_waterfall(self, exit_value, plot=True):
"""Compute exit proceeds distribution."""
if exit_value <= 0:
raise ValueError("exit_value must be positive.")
results = {'Founders + Options + Pool': 0.0}
total_pref = sum(r['pref_base'] * r['multiple'] for r in self.rounds)
if exit_value <= total_pref:
# Pro-rata prefs only
for r in self.rounds:
pref_amt = r['pref_base'] * r['multiple']
alloc = (pref_amt / total_pref) * exit_value
results[r['name']] = alloc
else:
# Full prefs paid
remaining = exit_value - total_pref
# Total as-converted shares
conv_shares = self.founder_shares + self.issued_options + self.unallocated_pool
for r in self.rounds:
conv_shares += r['shares'] * (r['issue_price'] / r['conv_price'])
# Distribute remaining pro-rata on converted basis
common_conv = self.founder_shares + self.issued_options + self.unallocated_pool
common_share = common_conv / conv_shares * remaining
results['Founders + Options + Pool'] = common_share
for r in self.rounds:
pref_amt = r['pref_base'] * r['multiple']
eff_shares = r['shares'] * (r['issue_price'] / r['conv_price'])
part_remaining = eff_shares / conv_shares * remaining
if r['participating']:
total_for_series = pref_amt + part_remaining
else:
# Non-part: max(pref + part remaining, full conversion)
full_conv = eff_shares / conv_shares * exit_value
total_for_series = max(pref_amt + part_remaining, full_conv)
results[r['name']] = total_for_series
df = pd.DataFrame(list(results.items()), columns=['Stakeholder', 'Proceeds ($M)'])
df['Proceeds ($M)'] /= 1e6
df = df.round(2)
print(f"\n--- Exit Waterfall: ${exit_value/1e6:.1f}M ---")
print(df)
if plot:
self._plot_waterfall(df, exit_value / 1e6)
return df
def _plot_waterfall(self, df, exit_val_m):
plt.figure(figsize=(12, 6))
colors = sns.color_palette("husl", len(df))
bars = plt.bar(range(len(df)), df['Proceeds ($M)'], color=colors)
plt.xlabel('Stakeholders')
plt.ylabel('Proceeds ($M)')
plt.title(f'Exit Waterfall: Total ${exit_val_m:.1f}M')
plt.xticks(range(len(df)), df['Stakeholder'], rotation=45, ha='right')
plt.axhline(0, color='k', linewidth=0.5)
# Annotate values
for bar, val in zip(bars, df['Proceeds ($M)']):
plt.text(bar.get_x() + bar.get_width()/2, bar.get_height() + 0.01,
f'${val:.1f}M', ha='center', va='bottom', fontsize=9)
plt.tight_layout()
plt.show()
def plot_ownership_pie(self, history_index=-1):
"""Pie chart of latest (or specified) cap table FD ownership."""
df = self.cap_table_history[history_index]
plt.figure(figsize=(10, 8))
wedges, texts, autotexts = plt.pie(df['FD Shares'], labels=df['Stakeholder'], autopct='%1.1f%%', startangle=90)
plt.title('Fully Diluted Ownership')
plt.axis('equal')
plt.show()
def print_summary(self):
"""Print current summary."""
print("\n=== Cap Table Summary ===")
print(self.update_cap_table().round(2))
print(f"\nTotal Outstanding Shares: {self.founder_shares + self.issued_options + sum(r['shares'] for r in self.rounds):,.0f}")
print(f"Fully Diluted Shares: {self.fd_shares:,.0f}")
print(f"Unallocated Pool: {self.unallocated_pool:,.0f} ({self.unallocated_pool / self.fd_shares * 100:.1f}%)")
# === EXAMPLE USAGE: Build a Sample Startup Scenario ===
print("=== Anti-Dilution Modeling Kit Demo ===\n")
model = StartupCapTable(founder_shares=10_000_000, issued_options=0)
model.anti_dilution_type = 'broad_wa' # Set global anti-dilution
# Round 1: Series A (no down round)
model.add_round('A', pre_val=15e6, amount_raised=5e6, new_pool_pct_post=0.15, pref_multiple=1.0, participating=False)
# Round 2: Series B up round
model.add_round('B', pre_val=40e6, amount_raised=10e6, new_pool_pct_post=0.20, pref_multiple=1.0, participating=True)
# Round 3: Series C DOWN ROUND (triggers broad WA anti-dilution)
model.add_round('C', pre_val=35e6, amount_raised=8e6, new_pool_pct_post=0.20, pref_multiple=1.5, participating=True)
# Pro-rata example: Series A pro-rata in a hypothetical Series D $20M raise
print(f"\nSeries A Pro-Rata for $20M future round: ${model.compute_pro_rata('A', 20e6)/1e6:.1f}M")
# Exit scenarios
model.exit_waterfall(exit_value=100e6) # 1x post-C return
model.exit_waterfall(exit_value=300e6, plot=False) # Good exit
model.exit_waterfall(exit_value=50e6, plot=False) # Bad exit (prefs pro-rata)
# Plots
model.plot_ownership_pie()
# Full summary
model.print_summary()
print("\n=== Kit Ready! Customize by calling model.add_round(...), model.exit_waterfall(...), etc. ===")
How to Use This Kit
Copy-paste into Python (requires pandas, numpy, matplotlib, seaborn – pip install if needed).
Run the example: Simulates a startup with up-round, down-round (Broad WA anti-dilution triggers, adjusting conv prices), prefs, participating/non-part.
Outputs: Tables, charts auto-generated. History in model.cap_table_history.
Extend: Add per-investor tracking, IPO models, etc.
This is production-grade, handles edge cases (e.g., huge pools, bad exits), and matches standard VC models (e.g., Orrick templates, Carta logic). Questions? Ask!