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+
|
| 3 |
+
# --- Calculation Logic ---
|
| 4 |
+
|
| 5 |
+
def format_currency(value):
|
| 6 |
+
"""Formats a number into a currency string."""
|
| 7 |
+
if value is None:
|
| 8 |
+
return "$0.00"
|
| 9 |
+
return f"${value:,.2f}"
|
| 10 |
+
|
| 11 |
+
def calculate_arr_valuation(arr, yoy_growth, nrr, ebitda, base_multiple):
|
| 12 |
+
"""
|
| 13 |
+
Calculates SaaS valuation based on an adjusted ARR multiple.
|
| 14 |
+
V = ARR * (Base Multiple * Growth Factor * Retention Factor * Efficiency Factor)
|
| 15 |
+
"""
|
| 16 |
+
if not all(isinstance(i, (int, float)) for i in [arr, yoy_growth, nrr, ebitda, base_multiple]) or arr <= 0:
|
| 17 |
+
return "Please provide valid inputs for all fields.", "$0.00"
|
| 18 |
+
|
| 19 |
+
# Convert percentages from 0-100 scale to decimal for calculations
|
| 20 |
+
g = yoy_growth / 100.0
|
| 21 |
+
nrr_decimal = nrr / 100.0
|
| 22 |
+
ebitda_margin = ebitda / arr
|
| 23 |
+
|
| 24 |
+
# --- Model Constants and Benchmarks ---
|
| 25 |
+
w_g = 0.30 # Growth Factor Weight
|
| 26 |
+
w_r = 0.50 # Retention Factor Weight
|
| 27 |
+
w_e = 0.20 # Efficiency Factor Weight
|
| 28 |
+
g_b = 0.40 # Benchmark YoY Growth (40%)
|
| 29 |
+
nrr_b = 1.05 # Benchmark NRR (105%)
|
| 30 |
+
r40_b = 0.40 # Benchmark Rule of 40
|
| 31 |
+
|
| 32 |
+
# 1. Calculate Growth Factor
|
| 33 |
+
f_growth = 1 + w_g * ((g - g_b) / g_b)
|
| 34 |
+
|
| 35 |
+
# 2. Calculate Retention Factor
|
| 36 |
+
f_retention = 1 + w_r * ((nrr_decimal - nrr_b) / nrr_b)
|
| 37 |
+
|
| 38 |
+
# 3. Calculate Efficiency Factor (based on Rule of 40)
|
| 39 |
+
rule_of_40_score = g + ebitda_margin
|
| 40 |
+
f_efficiency = 1 + w_e * ((rule_of_40_score - r40_b) / r40_b)
|
| 41 |
+
|
| 42 |
+
# Calculate the final adjusted multiple
|
| 43 |
+
m_adj = base_multiple * f_growth * f_retention * f_efficiency
|
| 44 |
+
|
| 45 |
+
# Apply a reasonable cap/floor to the adjusted multiple to avoid extreme results
|
| 46 |
+
m_adj = max(1.0, min(m_adj, 50.0))
|
| 47 |
+
|
| 48 |
+
# Calculate the final valuation
|
| 49 |
+
valuation = arr * m_adj
|
| 50 |
+
|
| 51 |
+
# --- Create summary text for display ---
|
| 52 |
+
summary_text = (
|
| 53 |
+
f"Base Multiple: {base_multiple:.2f}x\n"
|
| 54 |
+
f"YoY Growth Factor Adj: {f_growth:.2f}x\n"
|
| 55 |
+
f"Net Revenue Retention Factor Adj: {f_retention:.2f}x\n"
|
| 56 |
+
f"Efficiency (Rule of 40) Factor Adj: {f_efficiency:.2f}x\n"
|
| 57 |
+
f"--------------------------------------\n"
|
| 58 |
+
f"Final Adjusted Multiple: {m_adj:.2f}x"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
return summary_text, format_currency(valuation)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def calculate_simple_valuation(financial_metric, multiple):
|
| 65 |
+
"""Calculates a simple valuation (Metric * Multiple)."""
|
| 66 |
+
if not all(isinstance(i, (int, float)) for i in [financial_metric, multiple]):
|
| 67 |
+
return "$0.00"
|
| 68 |
+
valuation = financial_metric * multiple
|
| 69 |
+
return format_currency(valuation)
|
| 70 |
+
|
| 71 |
+
# --- Gradio UI ---
|
| 72 |
+
|
| 73 |
+
# CSS for styling the output boxes
|
| 74 |
+
css = "#valuation_output { font-size: 24px; font-weight: bold; color: #1d4ed8; text-align: center; }"
|
| 75 |
+
|
| 76 |
+
with gr.Blocks(title="SaaS Valuation Calculator", css=css) as demo:
|
| 77 |
+
gr.Markdown(
|
| 78 |
+
"""
|
| 79 |
+
# SaaS Business Valuation Calculator
|
| 80 |
+
Estimate the market value of a SaaS business using three common valuation models.
|
| 81 |
+
Adjust the sliders and inputs to see how different metrics affect the final valuation in real-time.
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
with gr.Tabs():
|
| 86 |
+
with gr.TabItem("Comprehensive (ARR-Based)"):
|
| 87 |
+
with gr.Row():
|
| 88 |
+
with gr.Column(scale=2):
|
| 89 |
+
gr.Markdown("### Core Financials")
|
| 90 |
+
arr_input = gr.Number(label="Annual Recurring Revenue (ARR)", value=2_000_000, step=10000)
|
| 91 |
+
yoy_growth_input = gr.Slider(minimum=0, maximum=200, value=50, step=1, label="YoY Growth (%)")
|
| 92 |
+
nrr_input = gr.Slider(minimum=70, maximum=150, value=110, step=1, label="Net Revenue Retention (NRR %)")
|
| 93 |
+
ebitda_input = gr.Number(label="EBITDA (for Rule of 40)", value=-100_000, step=10000)
|
| 94 |
+
base_multiple_input = gr.Slider(minimum=1, maximum=20, value=7, step=0.5, label="Market Base Multiple")
|
| 95 |
+
|
| 96 |
+
with gr.Column(scale=1):
|
| 97 |
+
gr.Markdown("### Calculation Breakdown")
|
| 98 |
+
summary_output = gr.Textbox(label="Adjusted Multiple Calculation", lines=6, interactive=False)
|
| 99 |
+
gr.Markdown("<br>",)
|
| 100 |
+
arr_valuation_output = gr.Textbox(label="Estimated Valuation", interactive=False, elem_id="valuation_output")
|
| 101 |
+
|
| 102 |
+
arr_inputs = [arr_input, yoy_growth_input, nrr_input, ebitda_input, base_multiple_input]
|
| 103 |
+
arr_outputs = [summary_output, arr_valuation_output]
|
| 104 |
+
for component in arr_inputs:
|
| 105 |
+
component.change(fn=calculate_arr_valuation, inputs=arr_inputs, outputs=arr_outputs)
|
| 106 |
+
|
| 107 |
+
with gr.TabItem("EBITDA Multiple"):
|
| 108 |
+
with gr.Row():
|
| 109 |
+
with gr.Column():
|
| 110 |
+
gr.Markdown(
|
| 111 |
+
"""
|
| 112 |
+
### EBITDA-Based Valuation
|
| 113 |
+
A straightforward model typically used for mature, profitable companies where earnings are a key indicator of value.
|
| 114 |
+
"""
|
| 115 |
+
)
|
| 116 |
+
ebitda_simple_input = gr.Number(label="EBITDA", value=500_000, step=10000)
|
| 117 |
+
ebitda_multiple_input = gr.Slider(minimum=1, maximum=25, value=10, step=1, label="EBITDA Multiple")
|
| 118 |
+
|
| 119 |
+
with gr.Column():
|
| 120 |
+
ebitda_valuation_output = gr.Textbox(label="Estimated Valuation", interactive=False, elem_id="valuation_output")
|
| 121 |
+
|
| 122 |
+
ebitda_inputs = [ebitda_simple_input, ebitda_multiple_input]
|
| 123 |
+
for component in ebitda_inputs:
|
| 124 |
+
component.change(fn=calculate_simple_valuation, inputs=ebitda_inputs, outputs=ebitda_valuation_output)
|
| 125 |
+
|
| 126 |
+
with gr.TabItem("SDE Multiple"):
|
| 127 |
+
with gr.Row():
|
| 128 |
+
with gr.Column():
|
| 129 |
+
gr.Markdown(
|
| 130 |
+
"""
|
| 131 |
+
### SDE-Based Valuation
|
| 132 |
+
Common for smaller, owner-operated businesses. SDE adds back the owner's salary and other discretionary expenses to net profit to show the full cash flow benefit to a single owner.
|
| 133 |
+
"""
|
| 134 |
+
)
|
| 135 |
+
sde_input = gr.Number(label="Seller's Discretionary Earnings (SDE)", value=300_000, step=5000)
|
| 136 |
+
sde_multiple_input = gr.Slider(minimum=1, maximum=10, value=4, step=0.5, label="SDE Multiple")
|
| 137 |
+
with gr.Column():
|
| 138 |
+
sde_valuation_output = gr.Textbox(label="Estimated Valuation", interactive=False, elem_id="valuation_output")
|
| 139 |
+
|
| 140 |
+
sde_inputs = [sde_input, sde_multiple_input]
|
| 141 |
+
for component in sde_inputs:
|
| 142 |
+
component.change(fn=calculate_simple_valuation, inputs=sde_inputs, outputs=sde_valuation_output)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
# Trigger initial calculations on load
|
| 146 |
+
demo.load(
|
| 147 |
+
fn=calculate_arr_valuation, inputs=arr_inputs, outputs=arr_outputs
|
| 148 |
+
).then(
|
| 149 |
+
fn=calculate_simple_valuation, inputs=ebitda_inputs, outputs=ebitda_valuation_output
|
| 150 |
+
).then(
|
| 151 |
+
fn=calculate_simple_valuation, inputs=sde_inputs, outputs=sde_valuation_output
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
if __name__ == "__main__":
|
| 156 |
+
demo.launch()
|