Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Diluted EPS(Earnings-Per-Share) #801

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions polygon/rest/models/financials.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Optional, Dict
from ...modelclass import modelclass


@modelclass
class DataPoint:
"An individual financial data point."
Expand All @@ -16,7 +15,6 @@ class DataPoint:
def from_dict(d):
return DataPoint(**d)


@modelclass
class ExchangeGainsLosses:
"Contains exchange gains losses data for a cash flow statement."
Expand All @@ -31,7 +29,6 @@ class ExchangeGainsLosses:
def from_dict(d):
return ExchangeGainsLosses(**d)


@modelclass
class NetCashFlow:
"Contains net cash flow data for a cash flow statement."
Expand All @@ -46,7 +43,6 @@ class NetCashFlow:
def from_dict(d):
return NetCashFlow(**d)


@modelclass
class NetCashFlowFromFinancingActivities:
"Contains net cash flow from financing activities data for a cash flow statement."
Expand All @@ -61,7 +57,6 @@ class NetCashFlowFromFinancingActivities:
def from_dict(d):
return NetCashFlowFromFinancingActivities(**d)


@modelclass
class CashFlowStatement:
"Contains cash flow statement data."
Expand Down Expand Up @@ -93,7 +88,6 @@ def from_dict(d):
),
)


@modelclass
class ComprehensiveIncomeLoss:
"Contains comprehensive income loss data for comprehensive income."
Expand All @@ -108,7 +102,6 @@ class ComprehensiveIncomeLoss:
def from_dict(d):
return ComprehensiveIncomeLoss(**d)


@modelclass
class ComprehensiveIncomeLossAttributableToParent:
"Contains comprehensive income loss attributable to parent data for comprehensive income."
Expand All @@ -123,7 +116,6 @@ class ComprehensiveIncomeLossAttributableToParent:
def from_dict(d):
return ComprehensiveIncomeLossAttributableToParent(**d)


@modelclass
class OtherComprehensiveIncomeLoss:
"Contains other comprehensive income loss data for comprehensive income."
Expand All @@ -138,7 +130,6 @@ class OtherComprehensiveIncomeLoss:
def from_dict(d):
return OtherComprehensiveIncomeLoss(**d)


@modelclass
class ComprehensiveIncome:
"Contains comprehensive income data."
Expand Down Expand Up @@ -172,7 +163,6 @@ def from_dict(d):
),
)


@modelclass
class BasicEarningsPerShare:
"Contains basic earning per share data for an income statement."
Expand All @@ -187,6 +177,19 @@ class BasicEarningsPerShare:
def from_dict(d):
return BasicEarningsPerShare(**d)

@modelclass
class DilutedEarningsPerShare:
"Contains diluted earnings per share 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 DilutedEarningsPerShare(**d)

@modelclass
class CostOfRevenue:
Expand All @@ -202,7 +205,6 @@ class CostOfRevenue:
def from_dict(d):
return CostOfRevenue(**d)


@modelclass
class GrossProfit:
"Contains gross profit data for an income statement."
Expand All @@ -217,7 +219,6 @@ class GrossProfit:
def from_dict(d):
return GrossProfit(**d)


@modelclass
class OperatingExpenses:
"Contains operating expenses data for an income statement."
Expand All @@ -232,7 +233,6 @@ class OperatingExpenses:
def from_dict(d):
return OperatingExpenses(**d)


@modelclass
class Revenues:
"Contains revenues data for an income statement."
Expand All @@ -247,11 +247,11 @@ class Revenues:
def from_dict(d):
return Revenues(**d)


@modelclass
class IncomeStatement:
"Contains income statement data."
basic_earnings_per_share: Optional[BasicEarningsPerShare] = None
diluted_earnings_per_share: Optional[DilutedEarningsPerShare] = None
cost_of_revenue: Optional[CostOfRevenue] = None
gross_profit: Optional[GrossProfit] = None
operating_expenses: Optional[OperatingExpenses] = None
Expand All @@ -265,6 +265,11 @@ def from_dict(d):
if "basic_earnings_per_share" not in d
else BasicEarningsPerShare.from_dict(d["basic_earnings_per_share"])
),
diluted_earnings_per_share=(
None
if "diluted_earnings_per_share" not in d
else DilutedEarningsPerShare.from_dict(d["diluted_earnings_per_share"])
),
cost_of_revenue=(
None
if "cost_of_revenue" not in d
Expand All @@ -283,7 +288,6 @@ def from_dict(d):
revenues=None if "revenues" not in d else Revenues.from_dict(d["revenues"]),
)


@modelclass
class Financials:
"Contains financial data."
Expand Down Expand Up @@ -319,7 +323,6 @@ def from_dict(d):
),
)


@modelclass
class StockFinancial:
"StockFinancial contains historical financial data for a stock ticker."
Expand Down Expand Up @@ -349,4 +352,4 @@ 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),
)
)
9 changes: 9 additions & 0 deletions test_rest/test_financials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
OtherComprehensiveIncomeLoss,
IncomeStatement,
BasicEarningsPerShare,
DilutedEarningsPerShare,
CostOfRevenue,
GrossProfit,
OperatingExpenses,
Expand Down Expand Up @@ -189,6 +190,14 @@ def test_list_stock_financials(self):
value=2.5,
xpath=None,
),
diluted_earnings_per_share=DilutedEarningsPerShare(
formula=None,
label="Diluted Earnings Per Share",
order=4300,
unit="USD / shares",
value=2.3,
xpath=None,
),
cost_of_revenue=CostOfRevenue(
formula=None,
label="Cost Of Revenue",
Expand Down