scripts-strategy-financial-models
#!/usr/bin/env python3 """
title: "Strategy Financial Models" component_type: script version: "1.0.0" audience: contributor status: stable summary: "Strategy Financial Models =========================" keywords: ['analysis', 'financial', 'models', 'review', 'strategy'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "strategy-financial-models.py" language: python executable: true usage: "python3 scripts/strategy-financial-models.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false
Strategy Financial Models
Investment-grade financial analysis for strategy briefs. Includes unit economics, market sizing, revenue projections, DCF, and compliance costs.
Usage: python3 scripts/strategy-financial-models.py --model unit-economics --demo python3 scripts/strategy-financial-models.py --model market-sizing --input data.json python3 scripts/strategy-financial-models.py --model dcf --fcf 1,2,3,4,5 --wacc 0.12
Models: unit-economics - LTV, CAC, payback period, retention analysis market-sizing - TAM/SAM/SOM with top-down and bottom-up approaches revenue - Compound growth and cohort-based projections dcf - Discounted cash flow with sensitivity analysis compliance - Regulatory compliance cost modeling
Source: Adapted from ANALYZE-REVIEW/extracted-consulting/advanced_financial_models.py """
import argparse import json import math import sys from dataclasses import dataclass, asdict from pathlib import Path from typing import Dict, List, Any, Optional, Tuple
@dataclass class UnitEconomics: """Unit Economics Model for SaaS/subscription businesses."""
average_revenue_per_user: float
gross_margin: float
customer_acquisition_cost: float
monthly_retention_rate: float
monthly_operating_cost_per_user: float = 0.0
@property
def monthly_churn_rate(self) -> float:
return 1 - self.monthly_retention_rate
@property
def customer_lifetime_months(self) -> float:
if self.monthly_churn_rate == 0:
return float('inf')
return 1 / self.monthly_churn_rate
@property
def lifetime_value(self) -> float:
gross_profit = self.average_revenue_per_user * self.gross_margin
net_profit = gross_profit - self.monthly_operating_cost_per_user
if self.monthly_retention_rate >= 1.0:
return float('inf')
return net_profit / (1 - self.monthly_retention_rate)
@property
def ltv_cac_ratio(self) -> float:
if self.customer_acquisition_cost == 0:
return float('inf')
return self.lifetime_value / self.customer_acquisition_cost
@property
def payback_months(self) -> float:
gross_profit = self.average_revenue_per_user * self.gross_margin
net_profit = gross_profit - self.monthly_operating_cost_per_user
if net_profit <= 0:
return float('inf')
return self.customer_acquisition_cost / net_profit
def health_check(self) -> Dict[str, str]:
checks = {}
if self.ltv_cac_ratio >= 3.0:
checks['ltv_cac'] = 'Healthy (>3.0)'
elif self.ltv_cac_ratio >= 1.0:
checks['ltv_cac'] = 'Acceptable (1.0-3.0)'
else:
checks['ltv_cac'] = 'Unhealthy (<1.0)'
if self.payback_months <= 12:
checks['payback'] = 'Excellent (<12 months)'
elif self.payback_months <= 24:
checks['payback'] = 'Good (12-24 months)'
else:
checks['payback'] = 'Concerning (>24 months)'
if self.gross_margin >= 0.80:
checks['gross_margin'] = 'Software-like (>80%)'
elif self.gross_margin >= 0.60:
checks['gross_margin'] = 'Good (60-80%)'
else:
checks['gross_margin'] = 'Low (<60%)'
if self.monthly_retention_rate >= 0.95:
checks['retention'] = 'Excellent (>95%)'
elif self.monthly_retention_rate >= 0.90:
checks['retention'] = 'Good (90-95%)'
else:
checks['retention'] = 'Needs improvement (<90%)'
return checks
def to_dict(self) -> Dict[str, Any]:
return {
'inputs': asdict(self),
'outputs': {
'lifetime_value': self.lifetime_value,
'ltv_cac_ratio': self.ltv_cac_ratio,
'payback_months': self.payback_months,
'customer_lifetime_months': self.customer_lifetime_months,
},
'health_check': self.health_check()
}
class MarketSizingModel: """TAM/SAM/SOM market sizing calculations."""
@staticmethod
def calculate_tam_top_down(total_customers: int, avg_spend: float) -> float:
return total_customers * avg_spend
@staticmethod
def calculate_sam_from_tam(tam: float, geographic: float, segment: float,
regulatory: float = 1.0) -> float:
return tam * geographic * segment * regulatory
@staticmethod
def calculate_som_from_sam(sam: float, market_share: float, years: int = 5) -> Dict:
som = sam * market_share
projections = []
for year in range(1, years + 1):
progress = 1 / (1 + math.exp(-2 * (year / years - 0.5)))
projections.append({
'year': year,
'som': som * progress,
'market_share_pct': (som * progress / sam) * 100
})
return {'target_som': som, 'projections': projections}
class RevenueProjectionModel: """Revenue projections with multiple methodologies."""
@staticmethod
def project_compound_growth(start_arr: float, growth: float, years: int) -> List[Dict]:
projections = []
arr = start_arr
for year in range(1, years + 1):
arr *= (1 + growth)
projections.append({'year': year, 'arr': arr, 'growth_pct': growth * 100})
return projections
@staticmethod
def scenario_analysis(base_arr: float, base_growth: float,
scenarios: Dict[str, float], years: int) -> Dict:
results = {}
all_scenarios = {'base': base_growth, **scenarios}
for name, growth in all_scenarios.items():
proj = RevenueProjectionModel.project_compound_growth(base_arr, growth, years)
results[name] = {
'growth_rate': growth * 100,
'final_arr': proj[-1]['arr'],
'projections': proj
}
return results
class DCFModel: """Discounted Cash Flow valuation."""
@staticmethod
def calculate(fcf: List[float], wacc: float, terminal_growth: float) -> Dict:
pv_cf = sum(cf / ((1 + wacc) ** (i + 1)) for i, cf in enumerate(fcf))
terminal_value = (fcf[-1] * (1 + terminal_growth)) / (wacc - terminal_growth)
pv_terminal = terminal_value / ((1 + wacc) ** len(fcf))
ev = pv_cf + pv_terminal
return {
'enterprise_value': ev,
'pv_cash_flows': pv_cf,
'terminal_value': terminal_value,
'pv_terminal_value': pv_terminal,
'terminal_pct': (pv_terminal / ev) * 100
}
@staticmethod
def sensitivity(fcf: List[float], wacc_range: Tuple[float, float],
tg_range: Tuple[float, float], steps: int = 5) -> Dict:
waccs = [wacc_range[0] + (wacc_range[1] - wacc_range[0]) * i / (steps - 1)
for i in range(steps)]
tgs = [tg_range[0] + (tg_range[1] - tg_range[0]) * i / (steps - 1)
for i in range(steps)]
table = []
for w in waccs:
row = {'wacc': w * 100, 'values': []}
for tg in tgs:
dcf = DCFModel.calculate(fcf, w, tg)
row['values'].append({
'terminal_growth': tg * 100,
'ev': dcf['enterprise_value']
})
table.append(row)
return {'sensitivity_table': table}
class ComplianceCostModel: """Regulatory compliance cost modeling."""
INDUSTRY_RATES = {
'healthcare': 0.08,
'fintech': 0.12,
'general': 0.03
}
CERT_COSTS = {
'SOC 2 Type II': 25000,
'ISO 27001': 35000,
'HIPAA': 50000,
'PCI DSS': 30000,
'GDPR': 40000,
'SOX': 100000
}
@staticmethod
def calculate(revenue: float, industry: str, certs: List[str],
employees: int, jurisdictions: int) -> Dict:
base_rate = ComplianceCostModel.INDUSTRY_RATES.get(
industry.lower(), 0.03)
cert_cost = sum(ComplianceCostModel.CERT_COSTS.get(c, 10000) for c in certs)
employee_cost = 500 * employees
multiplier = 1 + (jurisdictions - 1) * 0.15
revenue_cost = revenue * base_rate * multiplier
total = (revenue * base_rate + cert_cost + employee_cost) * multiplier
return {
'total_annual_cost': total,
'pct_of_revenue': (total / revenue) * 100,
'breakdown': {
'revenue_based': revenue_cost,
'certifications': cert_cost * multiplier,
'employee_overhead': employee_cost * multiplier
}
}
def format_currency(value: float) -> str: if value >= 1e9: return f"${value/1e9:.2f}B" elif value >= 1e6: return f"${value/1e6:.2f}M" elif value >= 1e3: return f"${value/1e3:.1f}K" else: return f"${value:.2f}"
def run_demo(): """Run demo of all financial models.""" print("=" * 80) print("CODITECT FINANCIAL MODELING TOOLKIT") print("=" * 80)
# Unit Economics
print("\n1. UNIT ECONOMICS")
print("-" * 80)
ue = UnitEconomics(
average_revenue_per_user=5000,
gross_margin=0.95,
customer_acquisition_cost=15000,
monthly_retention_rate=0.98,
monthly_operating_cost_per_user=200
)
print(f"LTV: {format_currency(ue.lifetime_value)}")
print(f"LTV:CAC Ratio: {ue.ltv_cac_ratio:.2f}x")
print(f"Payback: {ue.payback_months:.1f} months")
for k, v in ue.health_check().items():
print(f" {k}: {v}")
# Market Sizing
print("\n2. MARKET SIZING")
print("-" * 80)
tam = MarketSizingModel.calculate_tam_top_down(50000, 60000)
sam = MarketSizingModel.calculate_sam_from_tam(tam, 0.30, 0.20, 0.90)
som = MarketSizingModel.calculate_som_from_sam(sam, 0.05, 5)
print(f"TAM: {format_currency(tam)}")
print(f"SAM: {format_currency(sam)}")
print(f"SOM (5yr): {format_currency(som['target_som'])}")
# DCF
print("\n3. DCF VALUATION")
print("-" * 80)
fcf = [1e6, 1.5e6, 2.5e6, 4e6, 6e6]
dcf = DCFModel.calculate(fcf, 0.12, 0.03)
print(f"Enterprise Value: {format_currency(dcf['enterprise_value'])}")
print(f"Terminal Value %: {dcf['terminal_pct']:.1f}%")
# Compliance
print("\n4. COMPLIANCE COSTS")
print("-" * 80)
compliance = ComplianceCostModel.calculate(
10e6, 'healthcare', ['SOC 2 Type II', 'HIPAA'], 50, 3)
print(f"Total Cost: {format_currency(compliance['total_annual_cost'])}")
print(f"% of Revenue: {compliance['pct_of_revenue']:.1f}%")
print("\n" + "=" * 80)
def main(): parser = argparse.ArgumentParser( description="Strategy Financial Models", formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument('--model', choices=['unit-economics', 'market-sizing', 'revenue', 'dcf', 'compliance', 'all'], default='all', help='Model to run') parser.add_argument('--demo', action='store_true', help='Run demo') parser.add_argument('--input', help='Input JSON file') parser.add_argument('--output', help='Output file') parser.add_argument('--format', choices=['json', 'text'], default='text')
args = parser.parse_args()
if args.demo or args.model == 'all':
run_demo()
elif args.input:
data = json.loads(Path(args.input).read_text())
# Process based on model type
print(f"Processing {args.model} with input data...")
else:
print("Provide --demo or --input file", file=sys.stderr)
sys.exit(1)
if name == "main": main()