基于Python实现的一个简单的资本运营框架;
企业生命周期演示:观察初创→成长→上市→并购全流程
行业对比分析:不同行业的财务特征和估值差异
资本运作策略:体验IPO定价、投资决策、并购整合等操作
市场动态观察:通过仪表盘跟踪市场结构变化
"""
资本运营模拟教学系统(完整增强版)
功能:多公司模拟、IPO全流程、智能并购、交互投资
版本:4.0(教学旗舰版)
"""
import random
from dataclasses import dataclass
from typing import List, Dict, Optional, Tuple
from enum import Enum
# ========== 知识库模块 ==========
class KnowledgeBase:
@staticmethod
def explain(concept: str) -> str:
"""行业知识增强库"""
concepts = {
'IPO': (
"📈 IPO全流程详解:\n"
"1. 预路演(测试市场反应)\n"
"2. 估值建模(DCF/可比公司法)\n"
"3. 监管申报(SEC/FCA备案)\n"
"4. 累计投标(价格发现)\n"
"5. 挂牌交易(开盘价机制)"
),
'M&A': (
"🔄 并购整合策略:\n"
"• 横向并购:扩大市场份额\n"
"• 纵向并购:控制供应链\n"
"• 混合并购:多元化经营\n"
"案例:亚马逊收购Whole Foods实现零售业整合"
)
}
return concepts.get(concept, "知识库暂未收录该词条")
# ========== 数据模型模块 ==========
class Industry(Enum):
TECH = "科技"
FINANCE = "金融"
HEALTHCARE = "医疗"
CONSUMER = "消费品"
MANUFACTURING = "制造"
@dataclass
class FinancialReport:
year: int
revenue: float
net_profit: float
total_assets: float
debt: float
def display(self) -> str:
"""财务报告可视化"""
return (
f"{self.year}财务简报\n"
f"├─ 营业收入: ${self.revenue / 1e6:.1f}M\n"
f"├─ 净利润率: {self.net_profit / self.revenue * 100:.1f}%\n"
f"└─ 资产负债率: {self.debt / self.total_assets * 100:.1f}%"
)
class Company:
def __init__(self, name: str, industry: Industry):
self.name = name
self.industry = industry
self.is_public = False
self.financials: List[FinancialReport] = []
self.cash = random.randint(5_000_000, 5_000_000) # 初始资金$5M-$20M
self.ownership = {"创始人团队": 1.0}
self.employees = random.randint(50, 500)
def generate_report(self, year: int) -> FinancialReport:
"""行业特征财务模型"""
industry_params = {
Industry.TECH: {
'rev_growth': random.uniform(0.3, 0.5),
'margin': 0.25,
'asset_turnover': 2.0
},
Industry.FINANCE: {
'rev_growth': random.uniform(0.1, 0.2),
'margin': 0.15,
'asset_turnover': 0.5
},
Industry.HEALTHCARE: {
'rev_growth': random.uniform(0.2, 0.3),
'margin': 0.20,
'asset_turnover': 1.2
},
Industry.CONSUMER: {
'rev_growth': random.uniform(0.15, 0.25),
'margin': 0.10,
'asset_turnover': 1.5
},
Industry.MANUFACTURING: {
'rev_growth': random.uniform(0.1, 0.15),
'margin': 0.08,
'asset_turnover': 0.8
}
}
params = industry_params[self.industry]
if self.financials:
last_rev = self.financials[-1].revenue
revenue = last_rev * (1 + params['rev_growth'])
else:
revenue = random.uniform(1e7, 5e7)
net_profit = revenue * params['margin']
total_assets = (revenue / params['asset_turnover'])
report = FinancialReport(
year=year,
revenue=revenue,
net_profit=net_profit,
total_assets=total_assets,
debt=total_assets * random.uniform(0.1, 0.3)
)
self.cash += net_profit
self.financials.append(report)
print(f"[{self.name}] {report.display()}")
return report
# ========== 业务逻辑模块 ==========
class Underwriter:
"""承销商类"""
def __init__(self, name: str):
self.name = name
self.deals_completed = 0
def price_ipo(self, company: Company) -> Optional[float]:
"""IPO定价模型"""
if not company.financials:
return None
latest = company.financials[-1]
industry_multiples = {
Industry.TECH: 25,
Industry.FINANCE: 12,
Industry.HEALTHCARE: 18,
Industry.CONSUMER: 15,
Industry.MANUFACTURING: 10
}
return latest.net_profit * industry_multiples.get(company.industry, 10)
def execute_ipo(self, company: Company) -> str:
"""执行IPO流程"""
valuation = self.price_ipo(company)
if not valuation:
return "IPO失败:无法定价"
# 发行25%新股
shares_issued = valuation * 0.25
fee = shares_issued * 0.07
# 更新公司状态
company.cash += shares_issued
company.is_public = True
company.ownership["公众股东"] = 0.25
for k in company.ownership:
if k != "公众股东":
company.ownership[k] *= 0.75
self.deals_completed += 1
return (
f"🏛️ {self.name} 成功承销 {company.name} IPO!\n"
f"├─ 发行估值: ${valuation / 1e6:.1f}M\n"
f"├─ 募集资金: ${shares_issued / 1e6:.1f}M\n"
f"└─ 承销费用: ${fee / 1e6:.1f}M"
)
class VentureCapital:
"""风险投资机构"""
def __init__(self, name: str, fund_size: float):
self.name = name
self.fund = fund_size
self.portfolio = []
def evaluate(self, company: Company) -> float:
"""估值模型(风险调整现值法)"""
latest = company.financials[-1]
discount_rates = {
Industry.TECH: 0.4,
Industry.FINANCE: 0.3,
Industry.HEALTHCARE: 0.35,
Industry.CONSUMER: 0.25,
Industry.MANUFACTURING: 0.2
}
growth_rate = 0.2 # 假设行业平均增长率
terminal_value = latest.net_profit * (1 + growth_rate) / (discount_rates[company.industry] - growth_rate)
return terminal_value
def invest(self, company: Company, amount: float) -> str:
"""分阶段投资逻辑"""
pre_val = self.evaluate(company)
post_val = pre_val + amount
equity = amount / post_val
if amount > self.fund:
return f"❌ 投资失败:资金不足(可用:${self.fund / 1e6:.1f}M)"
# 更新资金和股权
self.fund -= amount
company.cash += amount
company.ownership[self.name] = equity
# 稀释现有股东
dilution = 1 - equity
for k in company.ownership:
if k != self.name:
company.ownership[k] *= dilution
self.portfolio.append(company)
return (
f"💼 {self.name} 投资 {company.name}\n"
f"├─ 投资金额: ${amount / 1e6:.1f}M\n"
f"├─ 占股比例: {equity * 100:.1f}%\n"
f"└─ 投后估值: ${post_val / 1e6:.1f}M"
)
# ========== 模拟系统模块 ==========
class CapitalSimulator:
def __init__(self):
self.companies = []
self.banks = []
self.vcs = []
self.year = 2024
def add_company(self, name: str, industry: Industry):
"""添加公司(行业均衡分布)"""
self.companies.append(Company(name, industry))
def init_default_entities(self):
"""初始化默认实体(公司数量翻倍)"""
# 投行
self.banks = [
Underwriter("高盛"),
Underwriter("摩根士丹利"),
Underwriter("中信证券")
]
# 风险投资
self.vcs = [
VentureCapital("红杉资本", 1e9),
VentureCapital("软银愿景", 2e9),
VentureCapital("淡马锡", 1.5e9)
]
# 公司列表(数量增加)
companies = [
("星海科技", Industry.TECH),
("云端医疗", Industry.HEALTHCARE),
("智造未来", Industry.MANUFACTURING),
("悦享消费", Industry.CONSUMER),
("银河金融", Industry.FINANCE),
("量子计算", Industry.TECH),
("精准医疗", Industry.HEALTHCARE),
("绿色制造", Industry.MANUFACTURING)
]
for name, industry in companies:
self.add_company(name, industry)
def run_ipo_phase(self):
"""IPO阶段模拟"""
candidates = [c for c in self.companies if not c.is_public]
if not candidates:
print("⚠️ 所有公司均已上市")
return
company = random.choice(candidates)
underwriter = random.choice(self.banks)
print(f"\n[IPO进程] {underwriter.execute_ipo(company)}")
def run_vc_phase(self):
"""风险投资阶段"""
if not self.vcs:
return
vc = random.choice(self.vcs)
targets = [c for c in self.companies if not c.is_public]
if not targets:
print("⚠️ 无未上市投资标的")
return
target = random.choice(targets)
investment = min(vc.fund * 0.2, 1e8) # 单笔投资不超过$100M
print(f"\n[私募市场] {vc.invest(target, investment)}")
def run_ma_phase(self):
"""并购阶段模拟"""
if len(self.companies) < 2:
return
acquirer, target = random.sample(self.companies, 2)
if acquirer == target:
return
# 简单协同效应计算
synergy = (acquirer.financials[-1].revenue + target.financials[-1].revenue) * 0.15
acquirer.cash += target.cash
self.companies.remove(target)
print(
f"\n[并购快讯] {acquirer.name} 收购 {target.name}\n"
f"└─ 协同价值: ${synergy / 1e6:.1f}M"
)
def run_year(self):
"""年度模拟主循环"""
print(f"\n{'=' * 30} {self.year}资本运营框架测试 {'=' * 30}")
# 生成年度报告
for co in self.companies:
co.generate_report(self.year)
# 各阶段模拟
self.run_ipo_phase()
self.run_vc_phase()
self.run_ma_phase()
self.year += 1
# ========== 交互模块 ==========
class InteractiveSimulator(CapitalSimulator):
def show_dashboard(self):
"""实时数据仪表盘"""
print("\n📊 市场全景:")
print(f"上市公司: {sum(1 for c in self.companies if c.is_public)}")
print(f"私募公司: {len(self.companies) - sum(1 for c in self.companies if c.is_public)}")
print(f"活跃投行: {len(self.banks)}")
print(f"VC机构: {len(self.vcs)}")
def user_invest(self):
"""用户投资交互"""
targets = [c for c in self.companies if not c.is_public]
if not targets:
print("⚠️ 当前无可投资公司")
return
print("\n可投资项目:")
for i, co in enumerate(targets):
print(f"{i + 1}. {co.name} ({co.industry.value})")
choice = input("请选择编号(0跳过): ").strip()
if not choice.isdigit():
print("⚠️ 输入无效")
return
idx = int(choice) - 1
if idx < 0 or idx >= len(targets):
return
target = targets[idx]
vc = self.vcs[0] # 假设用户控制第一个VC
while True:
amount = input(f"投资金额(可用: ${vc.fund / 1e6:.1f}M): ").strip()
if not amount:
print("⚠️ 跳过投资")
return
try:
amount = float(amount) * 1e6
if 0 < amount <= vc.fund:
break
print(f"金额需在0-{vc.fund / 1e6:.1f}之间")
except:
print("请输入有效数字")
print(f"\n[用户操作] {vc.invest(target, amount)}")
def run_year(self):
"""带交互的年度运行"""
super().run_year()
self.show_dashboard()
self.user_invest()
# ========== 运行示例 ==========
if __name__ == "__main__":
sim = InteractiveSimulator()
sim.init_default_entities()
# 运行10年模拟
for _ in range(10):
sim.run_year()
input("\n按回车继续下一年...")