Standardization
This would make edgar tools 100x better than anything else.
Maybe I am just struggling, however using code provided in the docs:
companies = ["AAPL", "MSFT", "GOOGL", "AMZN", "META"]
for ticker in companies:
company = Company(ticker)
metrics = {
'revenue': company.get_financials().get_revenue(),
'net_income': company.get_financials().get_net_income(),
'total_assets': company.get_financials().get_total_assets()
}
python 'revenue': company.get_financials().get_revenue(),
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Financials' object has no attribute 'get_revenue
Any ideas of how to ensure this standardized.
To elaborate on the real problem=> TSLA uses custom concepts Some companies Revenue, Contract Revenue, etc. If you can standardize all of these to ensure that I always get revenue when load a filing within it, that would be gold. Reference, fiscal does it i believe: here
LLMs are for narrative rather than calculations. Thus this would be greatly helpful, to improve the accuracy of LLM explanations by 90%+.
Have tried most means of standardization, and all dont work
It sort of makes you wonder how some of the commercial data providers are doing 10-K/Q standardization and how good it actually is. I've spent a couple years wrestling this problem and my only answer is completely non-scalable. I took about 2,000 gaap xbrl tags and mapped them to the standard items I wanted (very specific to my needs). But on average every company used about 10 custom tags that also required mapping, so for the roughly 400 companies I care about that's another 4,000 tags to map.
Standardization already exists in edgartools, and technically you could do
ic = xbrl.income_statement(standard=True)
df = ic.to_dataframe()
and then merge on the labels you want. But this isn't that easy or convenient.
I'm now working on concept level standardization making it easier to get the data how you described it. This could be available later this week
FEAT-411 Implementation Progress Update
🎯 Implementation Summary
We've made significant progress on the standardized financial concept API requested in this issue. Here's what has been implemented:
✅ Core Standardized Methods
Added 7 new methods to the EntityFacts class that provide consistent access to key financial concepts across all companies:
from edgar import Company
# Works consistently across ALL companies regardless of their XBRL concept naming
company = Company("AAPL") # or "TSLA", "MSFT", "GOOGL", etc.
facts = company.get_facts()
# Core financial metrics - same API for every company
revenue = facts.get_revenue()
net_income = facts.get_net_income()
assets = facts.get_total_assets()
liabilities = facts.get_total_liabilities()
equity = facts.get_shareholders_equity()
operating_income = facts.get_operating_income()
gross_profit = facts.get_gross_profit()
🔧 Key Features Implemented
-
Concept Priority Mapping: Handles various concept names (e.g.,
RevenueFromContractWithCustomerExcludingAssessedTax,SalesRevenueNet,Revenues) in priority order -
Namespace Handling: Automatically tries both
NetIncomeLossandus-gaap:NetIncomeLoss -
Intelligent Fallbacks: When primary concepts are missing, calculates from components:
# If Revenue concept missing: Revenue = Gross Profit + Cost of Revenue # If Gross Profit missing: Gross Profit = Revenue - Cost of Revenue -
Period-Specific Access:
current_revenue = facts.get_revenue(period="2024-FY") q4_revenue = facts.get_revenue(period="2024-Q4") -
Debugging Helper:
# Understand which concepts a company uses info = facts.get_concept_mapping_info(['Revenue', 'Revenues', 'NetSales']) print(f"Available: {info['available']}") # Shows what concepts exist
📊 Validation Results
Created a comprehensive testing framework using the company-subsets API and validated across diverse company groups:
🏆 Testing Results:
✅ FAANG: 5/5 (100.0%)
✅ Tech Giants: 10/10 (100.0%)
✅ Mega-Cap: 10/10 (100.0%)
✅ Diverse Sample: 15/15 (100.0%)
Overall: 40/40 companies (100.0% success rate)
💡 New Company Group Testing Framework
As a bonus, we developed an elegant testing approach that leverages the existing company-subsets API:
from edgar.reference.company_subsets import get_tech_giants, CompanySubset
# Test feature across curated company groups
def test_standardized_concepts_on_tech_giants():
tech_companies = get_tech_giants()
for _, company_info in tech_companies.iterrows():
company = Company(company_info['ticker'])
facts = company.get_facts()
revenue = facts.get_revenue()
assert revenue is not None
print(f"✅ {company_info['ticker']}: ${revenue/1e9:.1f}B")
# Create custom test groups
nasdaq_sample = (CompanySubset()
.from_exchange("Nasdaq")
.from_popular()
.sample(20, random_state=42)
.get())
This enables systematic validation across representative company samples instead of ad-hoc testing.
⚠️ Potential Issues & Edge Cases
While our implementation works excellently across major companies, we've identified several areas where users might encounter issues:
1. Unit Inconsistencies (High Priority)
- Some companies report in actual dollars, others in thousands/millions
- International companies may use different currencies
- No automatic unit normalization currently implemented
# Could return vastly different scales:
revenue_aapl = facts.get_revenue() # $383,000,000,000 (actual dollars)
revenue_other = facts.get_revenue() # $383,000 (thousands) - same company, wrong scale!
2. Industry-Specific Concepts (Medium Priority)
- Banks use
InterestIncomeinstead ofRevenue - REITs use
RealEstateRevenue - Insurance companies use
Premiums - Our current implementation is optimized for tech/manufacturing companies
3. Fiscal Year Complexity (Medium Priority)
- Many companies have non-calendar fiscal years (MSFT: June 30, AAPL: September 30)
- Period parameter
"2024-FY"might be ambiguous
4. Silent Failures (User Experience)
- Methods return
Nonefor missing data but don't explain why - Users can't distinguish between "no data exists" vs "concept not found" vs "unit mismatch"
5. Performance at Scale (Future Consideration)
- No batch processing for analyzing hundreds of companies
- Each company requires separate API calls
🤔 Questions for Community Feedback
-
Unit Handling Strategy: Should we:
- Auto-normalize all values to actual dollars?
- Provide a
unitsparameter (get_revenue(units="millions"))? - Return unit metadata alongside values?
-
Industry-Specific Methods: Should we add industry-specific variants like:
facts.get_bank_revenue() # Returns InterestIncome for banks facts.get_reit_revenue() # Returns RealEstateRevenue for REITs -
Error Handling Approach: Prefer:
- Current simple
Nonereturns - Rich result objects with error details
- Exception-based error handling
- Current simple
-
Fiscal Year Handling: How should we handle:
facts.get_revenue(fiscal_year=2024) # Company's fiscal 2024 facts.get_revenue(calendar_year=2024) # Calendar 2024 -
Batch Processing: Interest in batch operations like:
results = get_standardized_metrics_batch(["AAPL", "MSFT"], ["revenue", "net_income"])
🚀 Next Steps
The core implementation is ready and working well for the majority of companies. We'd love community feedback on:
- Which edge cases are most important to address first?
- Preferred API design for unit handling and error reporting?
- Interest in industry-specific method variants?
- Real-world use cases we should test against?
This feature solves the core problem described in the issue - providing consistent access to financial concepts across companies. The remaining work is about handling edge cases and optimizing the user experience for diverse scenarios.
Branch: feat/411-standardized-financial-concepts
Looking forward to your feedback! 🙏
Addressed in Release 4.13.0
Addressed in Release 4.13.0
Thanks again Dwight for this! I saw that TTM was introduced into the standard API as a period type, but the example documentation fails because the get_facts() method doesn't take period as a parameter.
Is this because get_facts() is still being worked on in a later minor point release?
I also noticed that the example code above to pull certain Q4 numbers returns empty. I would love to be able to isolate/pull Q4 numbers, which is why I'm so interested in the TTM view.
company = Company("GOOGL")
facts = company.get_facts()
q4 = facts.get_revenue(period="2023-Q4")
Addressed in Release 4.13.0
Thanks again Dwight for this! I saw that TTM was introduced into the standard API as a period type, but the example documentation fails because the
get_facts()method doesn't takeperiodas a parameter.Is this because `get_facts()` is still being worked on in a later minor point release?
I updated the documentation to be more accurate about the current functionality
The period parameter was missed during development. I added it as a feature for an upcoming release
Fixed in Release 4.15.0
Is this because `get_facts()` is still being worked on in a later minor point release?