-
Notifications
You must be signed in to change notification settings - Fork 0
/
financial_statements.py
152 lines (114 loc) · 3.95 KB
/
financial_statements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import pandas as pd
from helpers import _get_attr_list
from settings import *
#from base import FinancialStatementsBase
from statement import *
"""
FinancialStatementsBase is a parent class for each financial statements class
such as
- StatementsOfIncome (P/L)
- BalanceSheets (B/S)
- StatementsOfCashFlows (in C/F)
This base class have to be in the same module as children classes
to make isinstance() in statements() method work.
See details in
- https://stackoverflow.com/questions/50478661/python-isinstance-not-working-as-id-expect
- https://stackoverflow.com/questions/10582774/python-why-can-isinstance-return-false-when-it-should-return-true
"""
class FinancialStatementsBase:
# def __init__(self,
# urls_df=None,
# edgar_urls=None):
# self.urls_df = urls_df
# self.edgar_urls = edgar_urls
# @property
# def settings(self):
# return self.settings
@property
def name(self):
return self.settings.name
@property
def shortnames(self):
return self.settings.shortnames
# def statements(self):
# #raise NotImplementedError
# d = self.__dict__
# l = []
# #print(d)
# for key, value in d.items():
# #print(value.__class__.__bases__)
# if issubclass(value.__class__, StatementBase):
# l.append(value)
#
# return l
def statements(self):
return _get_attr_list(self.__dict__, StatementBase)
def to_dataframe(self, urls_df):
l = []
for statement in self.statements():
l.append(statement.to_dataframe(urls_df[self.name]))
return pd.concat(l)
# pl
class StatementsOfIncome(FinancialStatementsBase):
def __init__(self):
self.settings = StatementsOfIncomeSettings()
self.revenue = Revenue()
self.income_from_operations = IncomeFromOperations()
self.net_income = NetIncome()
# @property
# def settings(self):
# return StatementsOfIncomeSettings()
#
# def statements(self):
# return [Revenue(),
# IncomeFromOperations()]
def operating_margin(self):
return OperatingMargin()
# def statements(self):
# #raise NotImplementedError
# d = self.__dict__
# l = []
# for key, value in d.items():
# if issubclass(value.__class__, StatementBase):
# l.append(value)
#
# return l
# def statements(self):
# return _statements(self.__dict__, StatementBase)
# bs
class BalanceSheets(FinancialStatementsBase):
def __init__(self):
self.settings = BalanceSheetsSettings()
self.total_stockholders_equity = TotalStockholdersEquity()
self.total_liabilities_and_stockholders_equity = TotalLiabilitiesAndStockholdersEquity()
# def settings(self):
# return BalanceSheetsSettings()
# @property
# def total_stockholders_equity(self):
# #return TotalStockholdersEquity()
# return self.total_stockholders_equity
#
#
# @property
# def total_liabilities_and_stockholders_equity(self):
# #return TotalLiabilitiesAndStockholdersEquity()
# return self.total_liabilities_and_stockholders_equity
# def statements(self):
# return [TotalStockholdersEquity(),
# TotalLiabilitiesAndStockholdersEquity()]
# def statements(self):
# return _statements(self.__dict__, StatementBase)
# cf
class StatementsOfCashFlows(FinancialStatementsBase):
def __init__(self):
self.settings = StatementsOfCashFlowsSettings()
self.net_cash_provided_by_operating_activities = NetCashProvidedByOperatingActiveties()
# @property
# def settings(self):
# return StatementsOfCashFlowsSettings()
#
#
# def statements(self):
# return [NetCashProvidedByOperatingActiveties()]
# def statements(self):
# return _statements(self.__dict__, StatementBase)