Upload financial_analyzer.py
Browse files
EasyReportDataMCP/financial_analyzer.py
CHANGED
|
@@ -109,6 +109,10 @@ class FinancialAnalyzer:
|
|
| 109 |
if not all_annual_filings:
|
| 110 |
return []
|
| 111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
# Step 3: Extract filing years from annual reports
|
| 113 |
filing_year_map = {} # Map: filing_year -> list of filings
|
| 114 |
|
|
@@ -166,6 +170,7 @@ class FinancialAnalyzer:
|
|
| 166 |
|
| 167 |
# Step 6: Generate period list for target years
|
| 168 |
# For each year: FY -> Q4 -> Q3 -> Q2 -> Q1 (descending order)
|
|
|
|
| 169 |
periods = []
|
| 170 |
for file_year in target_years:
|
| 171 |
# Try to get fiscal year from mapping, otherwise use filing year
|
|
@@ -179,14 +184,16 @@ class FinancialAnalyzer:
|
|
| 179 |
'filing_year': file_year
|
| 180 |
})
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# Step 7: Get financial data for each period
|
| 192 |
for idx, period_info in enumerate(periods):
|
|
|
|
| 109 |
if not all_annual_filings:
|
| 110 |
return []
|
| 111 |
|
| 112 |
+
# Detect if company is a 20-F filer (foreign company)
|
| 113 |
+
is_20f_filer = len(filings_20f) > 0 and len(filings_10k) == 0
|
| 114 |
+
has_quarterly = False # 20-F filers typically don't have quarterly reports
|
| 115 |
+
|
| 116 |
# Step 3: Extract filing years from annual reports
|
| 117 |
filing_year_map = {} # Map: filing_year -> list of filings
|
| 118 |
|
|
|
|
| 170 |
|
| 171 |
# Step 6: Generate period list for target years
|
| 172 |
# For each year: FY -> Q4 -> Q3 -> Q2 -> Q1 (descending order)
|
| 173 |
+
# For 20-F filers: only FY (no quarterly data)
|
| 174 |
periods = []
|
| 175 |
for file_year in target_years:
|
| 176 |
# Try to get fiscal year from mapping, otherwise use filing year
|
|
|
|
| 184 |
'filing_year': file_year
|
| 185 |
})
|
| 186 |
|
| 187 |
+
# Only add quarterly data for 10-K filers (not for 20-F filers)
|
| 188 |
+
if not is_20f_filer:
|
| 189 |
+
# Then add quarterly data in descending order: Q4, Q3, Q2, Q1
|
| 190 |
+
for quarter in range(4, 0, -1):
|
| 191 |
+
periods.append({
|
| 192 |
+
'period': f"{fiscal_year}Q{quarter}",
|
| 193 |
+
'type': 'quarterly',
|
| 194 |
+
'fiscal_year': fiscal_year,
|
| 195 |
+
'filing_year': file_year
|
| 196 |
+
})
|
| 197 |
|
| 198 |
# Step 7: Get financial data for each period
|
| 199 |
for idx, period_info in enumerate(periods):
|