-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathschema.sql
283 lines (265 loc) · 8.83 KB
/
schema.sql
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
CREATE SCHEMA zacks;
CREATE TYPE zacks.estimate_period AS ENUM
('Current Quarter', 'Next Quarter', 'Current Year', 'Next Year');
CREATE TYPE zacks.rank AS ENUM
('Strong Buy', 'Buy', 'Hold', 'Sell', 'Strong Sell');
CREATE TYPE zacks.score AS ENUM
('A', 'B', 'C', 'D', 'F');
CREATE TYPE zacks.statement_period AS ENUM
('Year', 'Quarter');
CREATE TYPE zacks."when" AS ENUM
('Before market open', 'After market close');
CREATE TABLE zacks.balance_sheet_assets
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.statement_period NOT NULL,
cash_and_equivalents numeric,
receivables numeric,
notes_receivable numeric,
inventories numeric,
other_current_assets numeric,
total_current_assets numeric,
net_property_and_equipment numeric,
investments_and_advances numeric,
other_non_current_assets numeric,
deferred_charges numeric,
intangibles numeric,
deposits_and_other_assets numeric,
total_assets numeric,
CONSTRAINT balance_sheet_assets_pkey PRIMARY KEY (act_symbol, date, period),
CONSTRAINT balance_sheet_assets_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.balance_sheet_equity
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.statement_period NOT NULL,
preferred_stock numeric,
common_stock numeric,
capital_surplus numeric,
retained_earnings numeric,
other_equity numeric,
treasury_stock numeric,
total_equity numeric,
total_liabilities_and_equity numeric,
shares_outstanding numeric,
book_value_per_share numeric,
CONSTRAINT balance_sheet_equity_pkey PRIMARY KEY (act_symbol, date, period),
CONSTRAINT balance_sheet_equity_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.balance_sheet_liabilities
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.statement_period NOT NULL,
notes_payable numeric,
accounts_payable numeric,
current_portion_long_term_debt numeric,
current_portion_capital_leases numeric,
accrued_expenses numeric,
income_taxes_payable numeric,
other_current_liabilities numeric,
total_current_liabilities numeric,
mortgages numeric,
deferred_taxes_or_income numeric,
convertible_debt numeric,
long_term_debt numeric,
non_current_capital_leases numeric,
other_non_current_liabilities numeric,
minority_interest numeric,
total_liabilities numeric,
CONSTRAINT balance_sheet_liabilities_pkey PRIMARY KEY (act_symbol, date, period),
CONSTRAINT balance_sheet_liabilities_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.cash_flow_statement
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.statement_period NOT NULL,
net_income numeric,
depreciation_amortization_and_depletion numeric,
net_change_from_assets numeric,
net_cash_from_discontinued_operations numeric,
other_operating_activities numeric,
net_cash_from_operating_activities numeric,
property_and_equipment numeric,
acquisition_of_subsidiaries numeric,
investments numeric,
other_investing_activities numeric,
net_cash_from_investing_activities numeric,
issuance_of_capital_stock numeric,
issuance_of_debt numeric,
increase_short_term_debt numeric,
payment_of_dividends_and_other_distributions numeric,
other_financing_activities numeric,
net_cash_from_financing_activities numeric,
effect_of_exchange_rate_changes numeric,
net_change_in_cash_and_equivalents numeric,
cash_at_beginning_of_period numeric,
cash_at_end_of_period numeric,
diluted_net_eps numeric,
CONSTRAINT cash_flow_statement_pkey PRIMARY KEY (act_symbol, date, period),
CONSTRAINT cash_flow_statement_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.eps_estimate
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.estimate_period NOT NULL,
period_end_date date NOT NULL,
consensus numeric,
recent numeric,
count smallint,
high numeric,
low numeric,
year_ago numeric,
CONSTRAINT eps_estimate_pkey PRIMARY KEY (date, act_symbol, period),
CONSTRAINT eps_estimate_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.eps_history
(
act_symbol text NOT NULL,
date date NOT NULL,
period_end_date date NOT NULL,
reported numeric,
estimate numeric,
CONSTRAINT eps_history_pkey PRIMARY KEY (date, act_symbol, period_end_date),
CONSTRAINT eps_history_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.eps_perception
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.estimate_period NOT NULL,
period_end_date date NOT NULL,
most_accurate numeric,
CONSTRAINT eps_perception_pkey PRIMARY KEY (date, act_symbol, period),
CONSTRAINT eps_perception_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.eps_revision
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.estimate_period NOT NULL,
period_end_date date NOT NULL,
up_7 smallint,
up_30 smallint,
up_60 smallint,
down_7 smallint,
down_30 smallint,
down_60 smallint,
CONSTRAINT eps_revision_pkey PRIMARY KEY (date, act_symbol, period),
CONSTRAINT eps_revision_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.income_statement
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.statement_period NOT NULL,
sales numeric,
cost_of_goods numeric,
gross_profit numeric,
selling_administrative_depreciation_amortization_expenses numeric,
income_after_depreciation_and_amortization numeric,
non_operating_income numeric,
interest_expense numeric,
pretax_income numeric,
income_taxes numeric,
minority_interest numeric,
investment_gains numeric,
other_income numeric,
income_from_continuing_operations numeric,
extras_and_discontinued_operations numeric,
net_income numeric,
income_before_depreciation_and_amortization numeric,
depreciation_and_amortization numeric,
average_shares numeric,
diluted_eps_before_non_recurring_items numeric,
diluted_net_eps numeric,
CONSTRAINT income_statement_pkey PRIMARY KEY (act_symbol, date, period),
CONSTRAINT income_statement_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.rank_score
(
act_symbol text NOT NULL,
date date NOT NULL,
rank zacks.rank NOT NULL,
value zacks.score NOT NULL,
growth zacks.score NOT NULL,
momentum zacks.score NOT NULL,
vgm zacks.score NOT NULL,
CONSTRAINT rank_score_pkey PRIMARY KEY (date, act_symbol),
CONSTRAINT rank_score_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.sales_estimate
(
act_symbol text NOT NULL,
date date NOT NULL,
period zacks.estimate_period NOT NULL,
period_end_date date NOT NULL,
consensus numeric,
count smallint,
high numeric,
low numeric,
year_ago numeric,
CONSTRAINT sales_estimate_pkey PRIMARY KEY (date, act_symbol, period),
CONSTRAINT sales_estimate_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE TABLE zacks.earnings_calendar
(
act_symbol text NOT NULL,
date date NOT NULL,
"when" zacks."when",
CONSTRAINT earnings_calendar_act_symbol_fkey FOREIGN KEY (act_symbol)
REFERENCES nasdaq.symbol (act_symbol) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
);
CREATE OR REPLACE FUNCTION zacks.to_integer_rank(
rank zacks.rank)
RETURNS integer
LANGUAGE 'sql'
AS $BODY$
select
case "rank"::text
when 'Strong Buy' then 1
when 'Buy' then 2
when 'Hold' then 3
when 'Sell' then 4
when 'Strong Sell' then 5
end;
$BODY$;