financial.pyβ’4.7 kB
"""
Financial data models for advanced analysis
TDD Green Phase: Models to support financial analysis
"""
from dataclasses import dataclass
from typing import Dict, List, Any, Optional
from datetime import datetime, date
@dataclass
class FinancialStatements:
"""Enhanced financial statements model"""
company_code: str
period: str
statements: List[Dict[str, Any]]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"period": self.period,
"statements": self.statements
}
@dataclass
class RatioAnalysis:
"""Financial ratio analysis results"""
company_code: str
analysis_date: datetime
profitability_ratios: Dict[str, float]
liquidity_ratios: Dict[str, float]
leverage_ratios: Dict[str, float]
efficiency_ratios: Dict[str, float]
market_ratios: Dict[str, float]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"analysis_date": self.analysis_date.isoformat(),
"profitability_ratios": self.profitability_ratios,
"liquidity_ratios": self.liquidity_ratios,
"leverage_ratios": self.leverage_ratios,
"efficiency_ratios": self.efficiency_ratios,
"market_ratios": self.market_ratios
}
@dataclass
class TrendAnalysis:
"""Financial trend analysis results"""
company_code: str
analysis_period: str
revenue_trends: Dict[str, Any]
profit_trends: Dict[str, Any]
margin_trends: Dict[str, Any]
growth_rates: Dict[str, float]
forecasts: Dict[str, Any]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"analysis_period": self.analysis_period,
"revenue_trends": self.revenue_trends,
"profit_trends": self.profit_trends,
"margin_trends": self.margin_trends,
"growth_rates": self.growth_rates,
"forecasts": self.forecasts
}
@dataclass
class PeerComparison:
"""Peer comparison analysis results"""
company_code: str
industry_code: str
comparison_date: datetime
company_metrics: Dict[str, float]
peer_metrics: Dict[str, Any]
industry_benchmarks: Dict[str, float]
ranking: Dict[str, Any]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"industry_code": self.industry_code,
"comparison_date": self.comparison_date.isoformat(),
"company_metrics": self.company_metrics,
"peer_metrics": self.peer_metrics,
"industry_benchmarks": self.industry_benchmarks,
"ranking": self.ranking
}
@dataclass
class FinancialHealthScore:
"""Financial health scoring model"""
company_code: str
assessment_date: datetime
overall_score: float
component_scores: Dict[str, float]
grade: str
risk_factors: List[str]
strengths: List[str]
recommendations: List[str]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"assessment_date": self.assessment_date.isoformat(),
"overall_score": self.overall_score,
"component_scores": self.component_scores,
"grade": self.grade,
"risk_factors": self.risk_factors,
"strengths": self.strengths,
"recommendations": self.recommendations
}
@dataclass
class CashFlowAnalysis:
"""Cash flow analysis model"""
company_code: str
analysis_period: str
operating_cash_flow: float
investing_cash_flow: float
financing_cash_flow: float
free_cash_flow: float
cash_flow_ratios: Dict[str, float]
cash_conversion_cycle: Dict[str, int]
def to_dict(self) -> Dict[str, Any]:
"""Convert to dictionary representation"""
return {
"company_code": self.company_code,
"analysis_period": self.analysis_period,
"operating_cash_flow": self.operating_cash_flow,
"investing_cash_flow": self.investing_cash_flow,
"financing_cash_flow": self.financing_cash_flow,
"free_cash_flow": self.free_cash_flow,
"cash_flow_ratios": self.cash_flow_ratios,
"cash_conversion_cycle": self.cash_conversion_cycle
}