From 610ea11e778a49ce5e0d3705b4e3bbcdfe120c5e Mon Sep 17 00:00:00 2001 From: tsugumi-sys Date: Wed, 24 Jul 2024 21:05:36 +0900 Subject: [PATCH 1/6] addinf net income loss fields --- polygon/rest/models/financials.py | 96 +++++++++++++++++++++++++++++++ test_rest/test_financials.py | 36 ++++++++++++ 2 files changed, 132 insertions(+) diff --git a/polygon/rest/models/financials.py b/polygon/rest/models/financials.py index 1a480c48..c4e4cbaa 100644 --- a/polygon/rest/models/financials.py +++ b/polygon/rest/models/financials.py @@ -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"] + ) + ), ) diff --git a/test_rest/test_financials.py b/test_rest/test_financials.py index f5196212..97a32a68 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 @@ -221,6 +225,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", From 95a28be1a6fceb6f623fa8ec56d3e715dee92766 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:42:32 -0700 Subject: [PATCH 2/6] Update financials.py --- polygon/rest/models/financials.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/polygon/rest/models/financials.py b/polygon/rest/models/financials.py index c4e4cbaa..76e514c2 100644 --- a/polygon/rest/models/financials.py +++ b/polygon/rest/models/financials.py @@ -429,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): @@ -445,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) ) From 9cbb84bc546b72a42f8a068d569e00adfae29aca Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:48:10 -0700 Subject: [PATCH 3/6] Update financials.py --- polygon/rest/models/financials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polygon/rest/models/financials.py b/polygon/rest/models/financials.py index 76e514c2..2358bebc 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 From b9a02d4c4f1424e43b754fce4c329b3f54e75370 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:51:16 -0700 Subject: [PATCH 4/6] Update financials.py --- polygon/rest/models/financials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polygon/rest/models/financials.py b/polygon/rest/models/financials.py index 2358bebc..f49abff7 100644 --- a/polygon/rest/models/financials.py +++ b/polygon/rest/models/financials.py @@ -448,5 +448,5 @@ def from_dict(d): 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) + tickers=d.get("tickers", None), ) From 304fee0a3cbe8f1603d22d2ed886afbc8e536f6c Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Tue, 27 Aug 2024 10:55:33 -0700 Subject: [PATCH 5/6] Update test_financials.py --- test_rest/test_financials.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test_rest/test_financials.py b/test_rest/test_financials.py index 97a32a68..d4c87203 100644 --- a/test_rest/test_financials.py +++ b/test_rest/test_financials.py @@ -33,6 +33,8 @@ def test_list_stock_financials(self): 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( From d7565de260779d169ed10c8a4bab96b28d2c9f13 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:01:03 -0700 Subject: [PATCH 6/6] Update test_financials.py with sic and tickers --- test_rest/test_financials.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test_rest/test_financials.py b/test_rest/test_financials.py index d4c87203..25aa4bb2 100644 --- a/test_rest/test_financials.py +++ b/test_rest/test_financials.py @@ -27,6 +27,11 @@ 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",