update metrics
This commit is contained in:
parent
5128ccb7aa
commit
b82672632f
@ -1,37 +1,72 @@
|
||||
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 = []
|
||||
facts = filing_xbrl.facts.data
|
||||
|
||||
latest_rows = facts.groupby('dimensions').head(1)
|
||||
|
||||
for index, row in latest_rows.iterrows():
|
||||
dimensions_str = row.get("dimensions", "{}")
|
||||
for i in range(0,17):
|
||||
try:
|
||||
dimensions_dict = ast.literal_eval(dimensions_str) if isinstance(dimensions_str, str) else dimensions_str
|
||||
except (ValueError, SyntaxError):
|
||||
dimensions_dict = {}
|
||||
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:
|
||||
dimensions_dict = ast.literal_eval(dimensions_str) if isinstance(dimensions_str, str) else dimensions_str
|
||||
except (ValueError, SyntaxError):
|
||||
dimensions_dict = {}
|
||||
|
||||
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"])
|
||||
|
||||
product_dimension = dimensions_dict.get("srt:ProductOrServiceAxis") if isinstance(dimensions_dict, dict) else None
|
||||
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"], "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"]
|
||||
})
|
||||
|
||||
|
||||
if row["namespace"] == "us-gaap" and row["fact"].startswith("Revenue") and product_dimension is not None and product_dimension.startswith(symbol.lower() + ":") :
|
||||
revenue_sources.append({
|
||||
"name": product_dimension.replace("Member", "").replace(f"{symbol.lower()}:", ""),
|
||||
"value": row["value"],
|
||||
})
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
|
||||
print(revenue_sources)
|
||||
print(geography_sources)
|
||||
|
||||
221
app/test.py
Normal file
221
app/test.py
Normal file
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user