AI-powered financial analysis and investment evaluation tool.
bash
pip install numpy pandas
python
from financial_analyzer import FinancialAnalyzer
analyzer = FinancialAnalyzer()
# Analyze a company
result = analyzer.analyze(
company="茅台",
statements={
'balance_sheet': balance_data,
'income_statement': income_data,
'cash_flow': cash_flow_data
}
)
print(result['summary'])
python
# Calculate all ratios
ratios = analyzer.calculate_ratios(statements)
print(ratios['liquidity'])
# {
# 'current_ratio': 2.5,
# 'quick_ratio': 1.8,
# 'cash_ratio': 0.5
# }
print(ratios['profitability'])
# {
# 'roe': 0.28,
# 'roa': 0.18,
# 'gross_margin': 0.75,
# 'net_margin': 0.52
# }
python
# DCF Valuation
dcf = analyzer.dcf_valuation(
free_cash_flow=50e9,
growth_rate=0.05,
discount_rate=0.10,
terminal_growth=0.03
)
print(f"Intrinsic Value: {dcf['enterprise_value']:,.0f}")
# Relative Valuation
relative = analyzer.relative_valuation(
company="茅台",
peers=["五粮液", "泸州老窖"],
metrics={'pe': 35, 'pb': 8}
)
python
# Altman Z-Score (bankruptcy risk)
z_score = analyzer.altman_z_score(statements)
print(f"Z-Score: {z_score['score']:.2f}")
print(f"Risk Level: {z_score['risk_level']}")
# Z-Score: 5.2
# Risk Level: Safe (Z > 2.99)
# Piotroski F-Score (financial health)
f_score = analyzer.piotroski_f_score(statements)
print(f"F-Score: {f_score['score']}/9")
python
# Comprehensive health check
health = analyzer.health_check(statements)
print(health['overall_score']) # 85/100
print(health['strengths'])
print(health['weaknesses'])
print(health['recommendations'])
MethodDescriptionanalyze(company, statements)Full analysisanalyze_balance_sheet(data)Balance sheet analysisanalyze_income(data)Income statement analysisanalyze_cash_flow(data)Cash flow analysis
MethodDescriptioncalculate_ratios(statements)All ratiosliquidity_ratios(data)Liquidity metricssolvency_ratios(data)Solvency metricsprofitability_ratios(data)Profitability metricsefficiency_ratios(data)Efficiency metrics
MethodDescriptiondcf_valuation(...)DCF modelrelative_valuation(...)Peer comparisongraham_number(...)Graham's formulaearnings_power_value(...)EPV valuation
MethodDescriptionaltman_z_score(statements)Bankruptcy riskpiotroski_f_score(statements)Financial healthcredit_risk_score(statements)Credit assessmentoperational_risk(statements)Business risk
MethodDescriptiongenerate_report(analysis)Full reportsummary_report(analysis)Summarypeer_comparison(company, peers)Compare with peers
RatioFormulaGood RangeCurrent RatioCurrent Assets / Current Liabilities1.5 - 3.0Quick Ratio(CA - Inventory) / CL1.0 - 2.0Cash RatioCash / CL0.2 - 0.5
RatioFormulaInterpretationROENet Income / EquityHigher is betterROANet Income / AssetsHigher is betterGross MarginGross Profit / RevenueIndustry dependentNet MarginNet Income / RevenueHigher is better
RatioFormulaGood RangeDebt/EquityTotal Debt / Equity< 2.0Interest CoverageEBIT / Interest> 3.0Debt/AssetsTotal Debt / Assets< 0.6
RatioFormulaInterpretationAsset TurnoverRevenue / AssetsHigher is betterInventory TurnoverCOGS / InventoryIndustry dependentReceivables TurnoverRevenue / ReceivablesHigher is better
python
{
'method': 'dcf',
'steps': [
'Project free cash flows',
'Calculate terminal value',
'Discount to present value',
'Subtract debt, add cash'
],
'inputs': {
'fcf': 'Free cash flow',
'growth_rate': 'Expected growth',
'wacc': 'Weighted average cost of capital',
'terminal_growth': 'Long-term growth'
}
}
python
graham_number = sqrt(22.5 * EPS * Book_Value_Per_Share)
text
Z = 1.2*X1 + 1.4*X2 + 3.3*X3 + 0.6*X4 + 1.0*X5
X1 = Working Capital / Total Assets
X2 = Retained Earnings / Total Assets
X3 = EBIT / Total Assets
X4 = Market Value Equity / Total Liabilities
X5 = Sales / Total Assets
Interpretation:
Z > 2.99: Safe Zone
1.81 < Z < 2.99: Grey Zone
Z < 1.81: Distress Zone
text
9 criteria, 1 point each:
1. Positive ROA
2. Positive Operating Cash Flow
3. ROA improving
4. OCF > Net Income
5. Lower debt ratio
6. Higher current ratio
7. No share dilution
8. Higher gross margin
9. Higher asset turnover
Score interpretation:
8-9: Strong
6-7: Good
4-5: Average
0-3: Weak
python
from financial_analyzer import FinancialAnalyzer
analyzer = FinancialAnalyzer()
# Company financial data
statements = {
'balance_sheet': {
'total_assets': 200e9,
'total_liabilities': 50e9,
'current_assets': 80e9,
'current_liabilities': 30e9,
'cash': 40e9,
'inventory': 10e9,
'equity': 150e9
},
'income_statement': {
'revenue': 100e9,
'cost_of_goods': 25e9,
'operating_expenses': 10e9,
'net_income': 50e9,
'ebit': 60e9
},
'cash_flow': {
'operating_cf': 55e9,
'investing_cf': -15e9,
'financing_cf': -10e9,
'free_cash_flow': 40e9
}
}
# Run full analysis
result = analyzer.analyze("Example Corp", statements)
print(f"ROE: {result['ratios']['profitability']['roe']:.1%}")
print(f"Z-Score: {result['risk']['z_score']:.2f}")
print(f"Health Score: {result['health_score']}/100")
Supports both: