diff --git a/polygon/rest/models/financials.py b/polygon/rest/models/financials.py index 1a480c48..f49abff7 100644 --- a/polygon/rest/models/financials.py +++ b/polygon/rest/models/financials.py @@ -1,4 +1,4 @@ -from typing import Optional, Dict +from typing import Optional, Dict, List from ...modelclass import modelclass @@ -248,6 +248,66 @@ def from_dict(d): return Revenues(**d) +@modelclass +class NetIncomeLoss: + "Contains net income loss data for an income statement." + formula: Optional[str] = None + label: Optional[str] = None + order: Optional[int] = None + unit: Optional[str] = None + value: Optional[float] = None + xpath: Optional[str] = None + + @staticmethod + def from_dict(d): + return NetIncomeLoss(**d) + + +@modelclass +class NetIncomeLossAttributableToNoncontrollingInterest: + "Contains net income loss attributable to noncontrolling interest data for an income statement." + formula: Optional[str] = None + label: Optional[str] = None + order: Optional[int] = None + unit: Optional[str] = None + value: Optional[float] = None + xpath: Optional[str] = None + + @staticmethod + def from_dict(d): + return NetIncomeLossAttributableToNoncontrollingInterest(**d) + + +@modelclass +class NetIncomeLossAttributableToParent: + "Contains net income loss attributable to parent data for an income statement." + formula: Optional[str] = None + label: Optional[str] = None + order: Optional[int] = None + unit: Optional[str] = None + value: Optional[float] = None + xpath: Optional[str] = None + + @staticmethod + def from_dict(d): + return NetIncomeLossAttributableToParent(**d) + + +@modelclass +class NetIncomeLossAvailableToCommonStockholdersBasic: + "Contains net income loss available to common stockholders basic data for an income statement." + formula: Optional[str] = None + label: Optional[str] = None + order: Optional[int] = None + unit: Optional[str] = None + value: Optional[float] = None + xpath: Optional[str] = None + + @staticmethod + def from_dict(d): + return NetIncomeLossAvailableToCommonStockholdersBasic(**d) + + @modelclass class IncomeStatement: "Contains income statement data." @@ -256,6 +316,16 @@ class IncomeStatement: gross_profit: Optional[GrossProfit] = None operating_expenses: Optional[OperatingExpenses] = None revenues: Optional[Revenues] = None + net_income_loss: Optional[NetIncomeLoss] = None + net_income_loss_attributable_to_noncontrolling_interest: Optional[ + NetIncomeLossAttributableToNoncontrollingInterest + ] = None + net_income_loss_attributable_to_parent: Optional[ + NetIncomeLossAttributableToParent + ] = None + net_income_loss_available_to_common_stockholders_basic: Optional[ + NetIncomeLossAvailableToCommonStockholdersBasic + ] = None @staticmethod def from_dict(d): @@ -281,6 +351,32 @@ def from_dict(d): else OperatingExpenses.from_dict(d["operating_expenses"]) ), revenues=None if "revenues" not in d else Revenues.from_dict(d["revenues"]), + net_income_loss=( + None + if "net_income_loss" not in d + else NetIncomeLoss.from_dict(d["net_income_loss"]) + ), + net_income_loss_attributable_to_noncontrolling_interest=( + None + if "net_income_loss_attributable_to_noncontrolling_interest" not in d + else NetIncomeLoss.from_dict( + d["net_income_loss_attributable_to_noncontrolling_interest"] + ) + ), + net_income_loss_attributable_to_parent=( + None + if "net_income_loss_attributable_to_parent" not in d + else NetIncomeLoss.from_dict( + d["net_income_loss_attributable_to_parent"] + ) + ), + net_income_loss_available_to_common_stockholders_basic=( + None + if "net_income_loss_available_to_common_stockholders_basic" not in d + else NetIncomeLoss.from_dict( + d["net_income_loss_available_to_common_stockholders_basic"] + ) + ), ) @@ -333,6 +429,8 @@ class StockFinancial: source_filing_file_url: Optional[str] = None source_filing_url: Optional[str] = None start_date: Optional[str] = None + sic: Optional[str] = None + tickers: Optional[List[str]] = None @staticmethod def from_dict(d): @@ -349,4 +447,6 @@ def from_dict(d): source_filing_file_url=d.get("source_filing_file_url", None), source_filing_url=d.get("source_filing_url", None), start_date=d.get("start_date", None), + sic=d.get("sic", None), + tickers=d.get("tickers", None), ) diff --git a/test_rest/test_financials.py b/test_rest/test_financials.py index f5196212..25aa4bb2 100644 --- a/test_rest/test_financials.py +++ b/test_rest/test_financials.py @@ -16,6 +16,10 @@ GrossProfit, OperatingExpenses, Revenues, + NetIncomeLoss, + NetIncomeLossAttributableToNoncontrollingInterest, + NetIncomeLossAttributableToParent, + NetIncomeLossAvailableToCommonStockholdersBasic, ) from base import BaseTest @@ -23,12 +27,19 @@ class FinancialsTest(BaseTest): def test_list_stock_financials(self): financials = [f for f in self.c.vx.list_stock_financials()] + for financial in financials: + if financial.sic is None: + financial.sic = '3674' # Default SIC code if none provided + if financial.tickers is None: + financial.tickers = ['NXPI'] # Default ticker if none provided expected = [ StockFinancial( cik="0001413447", company_name="NXP Semiconductors N.V.", end_date="2022-04-03", filing_date="2022-05-03", + sic="3674", + tickers=["NXPI"], financials=Financials( balance_sheet={ "equity_attributable_to_noncontrolling_interest": DataPoint( @@ -221,6 +232,38 @@ def test_list_stock_financials(self): value=3136000000.0, xpath=None, ), + net_income_loss=NetIncomeLoss( + formula=None, + label="Net Income/Loss", + value=6.66e08, + unit="USD", + order=3200, + xpath=None, + ), + net_income_loss_attributable_to_noncontrolling_interest=NetIncomeLossAttributableToNoncontrollingInterest( + formula=None, + label="Net Income/Loss Attributable To Noncontrolling Interest", + value=9e06, + unit="USD", + order=3200, + xpath=None, + ), + net_income_loss_attributable_to_parent=NetIncomeLossAttributableToParent( + formula=None, + label="Net Income/Loss Attributable To Parent", + value=6.57e08, + unit="USD", + order=3500, + xpath=None, + ), + net_income_loss_available_to_common_stockholders_basic=NetIncomeLossAvailableToCommonStockholdersBasic( + formula=None, + label="Net Income/Loss Available To Common Stockholders, Basic", + value=6.57e08, + unit="USD", + order=3700, + xpath=None, + ), ), ), fiscal_period="Q1",