update metrics
This commit is contained in:
parent
5128ccb7aa
commit
b82672632f
@ -1,23 +1,41 @@
|
|||||||
from edgar import *
|
from edgar import *
|
||||||
import ast
|
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
|
# Tell the SEC who you are
|
||||||
set_identity("Michael Mccallum mike.mccalum@indigo.com")
|
set_identity("Michael Mccallum mike.mccalum@indigo.com")
|
||||||
|
|
||||||
symbol = 'AAPL'
|
symbol = 'NVDA'
|
||||||
filings = Company(symbol).get_filings(form="10-Q").latest(10)
|
revenue_sources = []
|
||||||
|
geography_sources = []
|
||||||
|
filings = Company(symbol).get_filings(form="10-Q").latest(50)
|
||||||
#print(filings[0].xbrl())
|
#print(filings[0].xbrl())
|
||||||
|
|
||||||
filing_xbrl = filings[0].xbrl()
|
for i in range(0,17):
|
||||||
|
try:
|
||||||
# ----
|
filing_xbrl = filings[i].xbrl()
|
||||||
# Extract detailed revenue items
|
|
||||||
# ----
|
|
||||||
revenue_sources = []
|
|
||||||
facts = filing_xbrl.facts.data
|
facts = filing_xbrl.facts.data
|
||||||
|
|
||||||
latest_rows = facts.groupby('dimensions').head(1)
|
latest_rows = facts.groupby('dimensions').head(1)
|
||||||
|
|
||||||
|
|
||||||
for index, row in latest_rows.iterrows():
|
for index, row in latest_rows.iterrows():
|
||||||
dimensions_str = row.get("dimensions", "{}")
|
dimensions_str = row.get("dimensions", "{}")
|
||||||
try:
|
try:
|
||||||
@ -25,13 +43,30 @@ for index, row in latest_rows.iterrows():
|
|||||||
except (ValueError, SyntaxError):
|
except (ValueError, SyntaxError):
|
||||||
dimensions_dict = {}
|
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({
|
revenue_sources.append({
|
||||||
"name": product_dimension.replace("Member", "").replace(f"{symbol.lower()}:", ""),
|
"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(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