update metrics

This commit is contained in:
MuslemRahimi 2024-10-20 01:54:39 +02:00
parent 5128ccb7aa
commit b82672632f
2 changed files with 279 additions and 23 deletions

View File

@ -1,23 +1,41 @@
from edgar import *
import ast
from tqdm import tqdm
from datetime import datetime
# Define quarter-end dates for a given year
def closest_quarter_end(date_str):
date = datetime.strptime(date_str, "%Y-%m-%d")
year = date.year
# Define quarter end dates for the year
q1 = datetime(year, 3, 31)
q2 = datetime(year, 6, 30)
q3 = datetime(year, 9, 30)
q4 = datetime(year, 12, 31)
# Find the closest quarter date
closest = min([q1, q2, q3, q4], key=lambda d: abs(d - date))
# Return the closest quarter date in 'YYYY-MM-DD' format
return closest.strftime("%Y-%m-%d")
# Tell the SEC who you are
set_identity("Michael Mccallum mike.mccalum@indigo.com")
symbol = 'AAPL'
filings = Company(symbol).get_filings(form="10-Q").latest(10)
symbol = 'NVDA'
revenue_sources = []
geography_sources = []
filings = Company(symbol).get_filings(form="10-Q").latest(50)
#print(filings[0].xbrl())
filing_xbrl = filings[0].xbrl()
# ----
# Extract detailed revenue items
# ----
revenue_sources = []
for i in range(0,17):
try:
filing_xbrl = filings[i].xbrl()
facts = filing_xbrl.facts.data
latest_rows = facts.groupby('dimensions').head(1)
for index, row in latest_rows.iterrows():
dimensions_str = row.get("dimensions", "{}")
try:
@ -25,13 +43,30 @@ for index, row in latest_rows.iterrows():
except (ValueError, SyntaxError):
dimensions_dict = {}
product_dimension = dimensions_dict.get("srt:ProductOrServiceAxis") if isinstance(dimensions_dict, dict) else None
for column_name in ["srt:StatementGeographicalAxis","srt:ProductOrServiceAxis"]:
product_dimension = dimensions_dict.get(column_name) if isinstance(dimensions_dict, dict) else None
#print(product_dimension)
#print(row["namespace"], row["fact"], product_dimension, row["value"])
if row["namespace"] == "us-gaap" and row["fact"].startswith("Revenue") and product_dimension is not None and product_dimension.startswith(symbol.lower() + ":") :
if column_name == "srt:ProductOrServiceAxis":
if row["namespace"] == "us-gaap" and product_dimension is not None and (product_dimension.startswith(symbol.lower() + ":") or product_dimension.startswith('country' + ":")):
revenue_sources.append({
"name": product_dimension.replace("Member", "").replace(f"{symbol.lower()}:", ""),
"value": row["value"],
"value": row["value"], "date": row["end_date"]
})
else:
if row["namespace"] == "us-gaap" and product_dimension is not None and (product_dimension.startswith(symbol.lower() + ":") or product_dimension.startswith('country' + ":")):
geography_sources.append({
"name": product_dimension.replace("Member", "").replace(f"{symbol.lower()}:", ""),
"value": row["value"], "date": row["end_date"]
})
except Exception as e:
print(e)
print(revenue_sources)
print(geography_sources)

221
app/test.py Normal file

File diff suppressed because one or more lines are too long