-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
sss.py
3726 lines (3336 loc) · 434 KB
/
sss.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
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#############################################################################
#
# Version 0.2.134 - Author: Asaf Ravid <[email protected]>
#
# Stock Screener and Scanner - based on yfinance
# Copyright (C) 2021 Asaf Ravid
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#############################################################################
# TODO: ASAFR: -1. In the re-run (reference_raw_data) - use the exact indices as used previously in the actual raw data creation - to avoid mishaps
# -2. In the reference raw data run - allow configurability to DO the scan of download values... for the sake of clarity
# -3. Add MorningStarFactor (even squared: adjustedSssValue = sssValue/MorningStarValue)
# -4. Add https://github.com/portfolioplus/pytickersymbols support/usage along with https://github.com/portfolioplus/pysymbolscanner
# -5. Add the relevant rising files to the PDF
# 0. Auto-Update Nasdaq (NSR) Indices as done with TASE
# 0.1. Add support for https://simfin.com/data/bulk
# 1.2. https://en.wikipedia.org/wiki/Magic_formula_investing
# 1.3. https://www.oldschoolvalue.com/investing-strategy/backtest-graham-nnwc-ncav-screen/
# 2. Back to Investpy to download all Japanese stocks and all swiss stocks (and all swedish stocks!)
# 3. Investigate and add: https://www.investopedia.com/terms/o/operatingmargin.asp - operating margin
# 4. Add Free Cash flow [FCF] (EV/FreeCashFlow): Inverse of the Free Cash Flow Yield (https://www.stockopedia.com/ratios/ev-free-cash-flow-336/
# 5. There is already an EV/CFO ratio.
# CFO - CapitalExpenditures = FCF
# EV/CFO * EV/FCF = EV^2 / (CFO * [CFO - CapitalExpenditures]) | EV/CFO + EV/FCF = EV*(1/CFO + 1/(CFO-CapitalExpenditures))
# Conclusion: EV/FCF is better as it provides moe information. But make this a lower priority for development
# Bonus: When there is no CFO, Use FCF, and Vice Versa - more information
# 6. Which are the most effective parameters? Correlate the sorting of sss_value to the results and each of the sorted-by-parameter list.
# 7. Important: https://www.oldschoolvalue.com/investing-strategy/walter-schloss-investing-strategy-producing-towering-returns/
# 7.1. 3 years low, 5 years low
# 7.2. F-Score, M-Score
# 7.3. Multi-Dim scan over the distance from low, and over the Schloff Score - define a Walter-Schloss score
# 7.4. Remove the square root from DtoE ?
# 7.5. MktCapM is >= US$ 300 million (basis year 2000) adjusted yearly
# 7.6. Consider only stocks that are listed at least 10 years
# 7.8. Calculate share_price/52weekLow 0.1
# 7.9. Take the top 500 stocks with highest Current Dividend Yield %# 12. https://pyportfolioopt.readthedocs.io/en/latest/UserGuide.html -> Use
# 7.10. Take the top 250 stocks with lowest Latest Filing P/E ratio# 13. Calculate the ROE - Return on equity
# 7.11. Take the top 125 stocks with lowest Latest Filing P/B ratio# 14. Operating Cash Flow Growth - interesting: https://github.com/JerBouma/FundamentalAnalysis
# 7.12. Take the top 75 stocks with lowest Latest Filing Long Term Debt# 15. Quick Ratio - https://github.com/JerBouma/FinanceDatabase - interesting
import time
import gc
import psutil
import shutil
import urllib.request as request
import pandas as pd
import yfinance as yf
import csv
import os
import sss_filenames
import sss_indices
import sss_config
import sss_post_processing
import math
import json
import traceback
from contextlib import closing
from dataclasses import dataclass
from forex_python.converter import CurrencyRates # pip install forex-python --> pip install git+https://github.com/MicroPyramid/forex-python.git
from currency_converter import CurrencyConverter # pip install CurrencyConverter currency.converter
from sys import platform
from datetime import datetime
from dateutil.relativedelta import *
from yahooquery import Ticker
import numpy as np
import matplotlib.pyplot as plt
VERBOSE_LOGS = 0
SKIP_5LETTER_Y_STOCK_LISTINGS = False # Skip ADRs - American Depositary receipts (5 Letter Stocks)
NUM_ROUND_DECIMALS = 7
NUM_EMPLOYEES_UNKNOWN = 10000000 # This will make the company very inefficient in terms of number of employees
PROFIT_MARGIN_UNKNOWN = 0.00001 # This will make the company almost not profitable terms of profit margins, thus less attractive
PRICE_TO_BOOK_UNKNOWN = 1000.0
PERCENT_HELD_INSTITUTIONS_LOW = 0.01 # low, to make less relevant
PERCENT_HELD_INSIDERS_UNKNOWN = 0.0000123 # Temporary check, TODO: ASAFR: Take some unknown value (low) instead for the actual usage in Schloss factor
PEG_UNKNOWN = 10000 # Use a non-attractive value
QEG_MAX = 10000
REG_MAX = 10000
SHARES_OUTSTANDING_UNKNOWN = 100000000 # 100 Million Shares - just a value for calculation of a currently unused vaue
BAD_SSS = 10.0 ** 50.0
PROFIT_MARGIN_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
PROFIT_MARGIN_YEARLY_WEIGHTS = [1.0, 4.0, 16, 64, 256, 1024, 4096, 16384, 4*16384, 16*16384] # from oldest to newest
PROFIT_MARGIN_QUARTERLY_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
CASH_FLOW_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
REVENUES_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
NO_WEIGHTS = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] # from oldest to newest
EARNINGS_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
BALANCE_SHEETS_WEIGHTS = [1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0] # from oldest to newest
EQG_UNKNOWN = -0.9 # -90% TODO: ASAFR: 1. Scan (like pm and ever) values of eqg for big data research better recommendations
RQG_UNKNOWN = -0.9 # -90% TODO: ASAFR: 1. Scan (like pm and ever) values of rqg for big data research better recommendations
EQG_POSITIVE_FACTOR = 10.0 # When positive, it will have a 5x factor on the 1 + function
RQG_POSITIVE_FACTOR = 10.0 # When positive, it will have a 5x factor on the 1 + function
EQG_WEIGHT_VS_YOY = 0.75 # the provided EQG is weighted more than the manually calculated one
RQG_WEIGHT_VS_YOY = 0.75 # the provided RQG (yfinance now provides it) is weighted more than the manually calculated one
EQG_DAMPER = 0.25
RQG_DAMPER = 0.25
TRAILING_EPS_PERCENTAGE_DAMP_FACTOR = 0.01 # When the trailing_eps_percentage is very low (units are ratio here), this damper shall limit the affect to x100 not more)
PROFIT_MARGIN_DAMPER = 0.001 # When the profit_margin is very low (units are ratio here), this damper shall limit the affect to x100 not more)
RATIO_DAMPER = 0.01 # When the total/current_other_other ratio is very low (units are ratio here), this damper shall limit the affect to x100 not more)
ROA_DAMPER = 0.1 # When the ROA is very low (units are ratio here), this damper shall limit the affect to x50 not more)
ROA_NEG_FACTOR = 0.000001
ROE_DAMPER = 0.1 # When the ROE is very low (units are ratio here), this damper shall limit the affect to x50 not more)
ROE_NEG_FACTOR = 0.000001
REFERENCE_DB_MAX_VALUE_DIFF_FACTOR_THRESHOLD = 0.9 # if there is a parameter difference from reference db, in which the difference of values is higher than 0.75*abs(max_value) then something went wrong with the fetch of values from yfinance. Compensate smartly from reference database
QUARTERLY_YEARLY_MISSING_FACTOR = 0.25 # if either yearly or quarterly values are missing - compensate by other with bad factor (less information means less attractive)
NEGATIVE_ALTMAN_Z_FACTOR = 0.00001
MIN_REVENUE_FOR_0_REVENUE_DIV_BY_0_AVOIDANCE = 0.001
MAX_UNKNOWN_PE = 100000
MAX_UNKNOWN_EVR = 100000
# TODO: ASAFR: All below boosters should be calibrated by:
# 1. The rarety (statistically comapred to all the stocks in scan) - proportionaly to it (the rarest the case - the more boost)
# 2. The ascent (slope) of the increase and the positive value -> the higher - the more boost
# 3. Add similar boosters for other annual and quarterly weighted-averaged parameters
PROFIT_MARGIN_BOOST_FOR_PRESENCE_OF_ANNUAL_NEGATIVE_EARNINGS = 0.025 if sss_config.custom_sss_value_equation else 0.1
PROFIT_MARGIN_BOOST_FOR_PRESENCE_OF_QUARTERLY_NEGATIVE_EARNINGS = 0.025 if sss_config.custom_sss_value_equation else 0.1
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_INCREASE = 10.0 if sss_config.custom_sss_value_equation else 3.75 # Provide a "bonus" for companies whose profit margins have increased continuously annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE = 10.0 if sss_config.custom_sss_value_equation else 2.25 # Provide a "bonus" for companies whose profit margins have increased continuously quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_POSITIVE = 10.0 if sss_config.custom_sss_value_equation else 4.75 # Provide a "bonus" for companies whose profit margins have been continuously positive annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_POSITIVE = 10.0 if sss_config.custom_sss_value_equation else 2.75 # Provide a "bonus" for companies whose profit margins have been continuously positive quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_INCREASE_IN_EARNINGS = 10.0 if sss_config.custom_sss_value_equation else 4.25 # Provide a "bonus" for companies whose earnings have been continuously increasing annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_INCREASE_IN_REVENUE = 14.0 if sss_config.custom_sss_value_equation else 7.77 # Provide a "bonus" for companies whose revenue has been continuously increasing annually - TODO: ASAFR: This is a very good indicator for stock value growth
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE_IN_EARNINGS = 10.0 if sss_config.custom_sss_value_equation else 3.25 # Provide a "bonus" for companies whose earnings have been continuously increasing quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE_IN_REVENUE = 25.0 if sss_config.custom_sss_value_equation else 9.99 # Provide a "bonus" for companies whose revenue has been continuously increasing quarterly - TODO: ASAFR: This is a very good indicator for stock value growth
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_DECREASE = 0.05 if sss_config.custom_sss_value_equation else 0.25 # Provide a "bonus" for companies whose profit margins have decreased continuously annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_DECREASE = 0.05 if sss_config.custom_sss_value_equation else 0.25 # Provide a "bonus" for companies whose profit margins have decreased continuously quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_DECREASE_IN_EARNINGS = 0.05 if sss_config.custom_sss_value_equation else 0.25 # Provide a "bonus" for companies whose earnings have been continuously decreasing annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_DECREASE_IN_REVENUE = 0.05 if sss_config.custom_sss_value_equation else 0.2 # Provide a "bonus" for companies whose revenue has been continuously decreasing annually - TODO: ASAFR: This is a very good indicator for stock value growth
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_DECREASE_IN_EARNINGS = 0.05 if sss_config.custom_sss_value_equation else 0.25 # Provide a "bonus" for companies whose earnings have been continuously decreasing quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_DECREASE_IN_REVENUE = 0.05 if sss_config.custom_sss_value_equation else 0.1 # Provide a "bonus" for companies whose revenue has been continuously decreasing quarterly - TODO: ASAFR: This is a very good indicator for stock value growth
PROFIT_MARGIN_DUPLICATION_FACTOR = 8.0 # When copying profit margin (if either quarterized/annualized/profit_margin is missing) - devide by this factor
NEGATIVE_CFO_FACTOR = 100000.0 #
NEGATIVE_PEG_RATIO_FACTOR = 100000.0
NEGATIVE_DEBT_TO_EQUITY_FACTOR = 100.0 # -0.5 -> 50, and -0.001 -> 0.1
NEGATIVE_EARNINGS_FACTOR = 100000.0
DEBT_TO_EQUITY_MIN_BASE = 0.001 # Clearing from 0 values for companies without debt
FORWARD_PRICE_TO_EARNINGS_WEIGHT = 0.125 # Give less weight to forward (estimation)
TRAILING_PRICE_TO_EARNINGS_WEIGHT = 1-FORWARD_PRICE_TO_EARNINGS_WEIGHT
DIST_FROM_LOW_FACTOR_DAMPER = 0.001
DIST_FROM_LOW_FACTOR_HIGHER_THAN_ONE_POWER = 6
EV_TO_EBITDA_MAX_UNKNOWN = 100000
#
# TODO: ASAFR: (https://www.gurufocus.com/letter.php)
# 1. Add Free Cash Flow
# 2. Lower Market Cap - Give more weight (in multi-dimensional scan)
# 3. Start adjusting the normalized sss_value flow - those companies which are "deceiving" -> fix according to them
@dataclass
class StockData:
symbol: str = 'None'
short_name: str = 'None'
quote_type: str = 'None'
sector: str = 'None'
country: str = 'Unknown'
sss_value: float = BAD_SSS
ma: str = 'None'
annualized_revenue: float = 0.0
annualized_revenue_bonus: float = 0.0
annualized_earnings: float = 0.0 # TODO: ASAFR: Add the bonus calculations (pos, neg, mon_inc, mon_dec, etc)
annualized_retained_earnings: float = 0.0
annualized_retained_earnings_bonus: float = 0.0
quarterized_revenue: float = 0.0
quarterized_revenue_bonus: float = 0.0
quarterized_earnings: float = 0.0
quarterized_earnings_bonus: float = 0.0
quarterized_retained_earnings: float = 0.0
quarterized_retained_earnings_bonus: float = 0.0
effective_earnings: float = 0.0
effective_retained_earnings: float = 0.0
effective_revenue: float = 0.0
annualized_total_revenue: float = 0.0
annualized_total_revenue_bonus: float = 0.0
annualized_net_income: float = 0.0 # TODO: ASAFR: Add the bonus calculations (pos, neg, mon_inc, mon_dec, etc)
quarterized_total_revenue: float = 0.0
quarterized_total_revenue_bonus: float = 0.0
quarterized_net_income: float = 0.0
quarterized_net_income_bonus: float = 0.0
effective_net_income: float = 0.0
effective_total_revenue: float = 0.0
enterprise_value_to_revenue: float = 0.0
evr_effective: float = 0.0
trailing_price_to_earnings: float = 0.0
forward_price_to_earnings: float = 0.0
effective_price_to_earnings: float = 0.0
trailing_12months_price_to_sales: float = 0.0
pe_effective: float = 0.0
enterprise_value_to_ebitda: float = 0.0
effective_ev_to_ebitda: float = 0.0
ebitda: float = 0.0
quarterized_ebitd: float = 0.0
annualized_ebitd: float = 0.0
ebitd: float = 0.0
profit_margin: float = 0.0
annualized_profit_margin: float = 0.0
annualized_profit_margin_boost: float = 0.0
quarterized_profit_margin: float = 0.0
quarterized_profit_margin_boost: float = 0.0
effective_profit_margin: float = 0.0
held_percent_institutions: float = 0.0
held_percent_insiders: float = 0.0
forward_eps: float = 0.0
trailing_eps: float = 0.0
previous_close: float = 0.0
trailing_eps_percentage: float = 0.0 # trailing_eps / previousClose
price_to_book: float = 0.0
shares_outstanding: float = 0.0
net_income_to_common_shareholders: float = 0.0
nitcsh_to_shares_outstanding: float = 0.0
employees: int = 0
enterprise_value: int = 0
market_cap: int = 0
nitcsh_to_num_employees: float = 0.0
eqg: float = 0.0 # Value is a ratio, such that when multiplied by 100, yields percentage (%) units
rqg: float = 0.0 # Value is a ratio, such that when multiplied by 100, yields percentage (%) units
eqg_yoy: float = 0.0 # calculated from the yearly earnings - if available
rqg_yoy: float = 0.0 # calculated from the yearly Revenues - if available
niqg_yoy: float = 0.0 # Net Income Quarterly Growth: calculated from the yearly net income - if available
trqg_yoy: float = 0.0 # Total Revenue Quarterly Growth: calculated from the yearly net income - if available
eqg_effective: float = 0.0 # average of eqg_yoy and eqg
eqg_factor_effective: float = 0.0 # function with positive factor and damper
rqg_effective: float = 0.0 # average of rqg_yoy and rqg
rqg_factor_effective: float = 0.0 # function with positive factor and damper
price_to_earnings_to_growth_ratio: float = 0.0
effective_peg_ratio: float = 0.0
annualized_cash_flow_from_operating_activities: float = 0.0
annualized_cash_flow_from_operating_activities_bonus: float = 0.0
quarterized_cash_flow_from_operating_activities: float = 0.0
quarterized_cash_flow_from_operating_activities_bonus:float = 0.0
annualized_ev_to_cfo_ratio: float = 0.0 # https://investinganswers.com/dictionary/e/enterprise-value-cash-flow-operations-evcfo
quarterized_ev_to_cfo_ratio: float = 0.0 # https://investinganswers.com/dictionary/e/enterprise-value-cash-flow-operations-evcfo
ev_to_cfo_ratio_effective: float = 0.0
annualized_debt_to_equity: float = 0.0
annualized_debt_to_equity_bonus: float = 0.0
quarterized_debt_to_equity: float = 0.0
quarterized_debt_to_equity_bonus: float = 0.0
debt_to_equity_effective: float = 0.0
debt_to_equity_effective_used: float = 0.0
financial_currency: str = 'None'
summary_currency: str = 'None'
financial_currency_conversion_rate_mult_to_usd: float = 0.0
summary_currency_conversion_rate_mult_to_usd: float = 0.0
last_dividend_0: float = 0.0
last_dividend_1: float = 0.0
last_dividend_2: float = 0.0
last_dividend_3: float = 0.0
fifty_two_week_change: float = 0.0
fifty_two_week_low: float = 0.0
fifty_two_week_high: float = 0.0
two_hundred_day_average: float = 0.0
previous_close_percentage_from_200d_ma: float = 0.0
previous_close_percentage_from_52w_low: float = 0.0
previous_close_percentage_from_52w_high: float = 0.0
dist_from_low_factor: float = 0.0
eff_dist_from_low_factor: float = 0.0
annualized_total_ratio: float = 0.0
annualized_total_ratio_bonus: float = 0.0
quarterized_total_ratio: float = 0.0
quarterized_total_ratio_bonus: float = 0.0
annualized_other_current_ratio: float = 0.0
annualized_other_current_ratio_bonus: float = 0.0
quarterized_other_current_ratio: float = 0.0
quarterized_other_current_ratio_bonus: float = 0.0
annualized_other_ratio: float = 0.0
annualized_other_ratio_bonus: float = 0.0
quarterized_other_ratio: float = 0.0
quarterized_other_ratio_bonus: float = 0.0
annualized_total_current_ratio: float = 0.0
annualized_total_current_ratio_bonus: float = 0.0
quarterized_total_current_ratio: float = 0.0
quarterized_total_current_ratio_bonus: float = 0.0
total_ratio_effective: float = 0.0
other_current_ratio_effective: float = 0.0
other_ratio_effective: float = 0.0
total_current_ratio_effective: float = 0.0
effective_current_ratio: float = 0.0
annualized_total_assets: float = 0.0
annualized_total_assets_bonus: float = 0.0
quarterized_total_assets: float = 0.0
quarterized_total_assets_bonus: float = 0.0
effective_total_assets: float = 0.0
annualized_total_stockholder_equity: float = 0.0
annualized_total_stockholder_equity_bonus: float = 0.0
quarterized_total_stockholder_equity: float = 0.0
quarterized_total_stockholder_equity_bonus: float = 0.0
effective_total_stockholder_equity: float = 0.0
calculated_roa: float = 0.0
calculated_roe: float = 0.0
annualized_working_capital: float = 0.0
quarterized_working_capital: float = 0.0
effective_working_capital: float = 0.0
annualized_total_liabilities: float = 0.0
annualized_total_liabilities_bonus: float = 0.0
quarterized_total_liabilities: float = 0.0
quarterized_total_liabilities_bonus: float = 0.0
effective_total_liabilities: float = 0.0
altman_z_score_factor: float = 0.0
skip_reason: str = 'None'
@dataclass
class StockDataNormalized:
symbol: str = 'None'
short_name: str = 'None'
quote_type: str = 'None'
sector: str = 'None'
country: str = 'Unknown'
sss_value: float = BAD_SSS
sss_value_normalized: float = BAD_SSS
ma: str = 'None'
annualized_revenue: float = 0.0
annualized_revenue_bonus: float = 0.0
annualized_earnings: float = 0.0 # TODO: ASAFR: Add the bonus calculations (pos, neg, mon_inc, mon_dec, etc)
annualized_retained_earnings: float = 0.0
annualized_retained_earnings_bonus: float = 0.0
quarterized_revenue: float = 0.0
quarterized_revenue_bonus: float = 0.0
quarterized_earnings: float = 0.0
quarterized_earnings_bonus: float = 0.0
quarterized_retained_earnings: float = 0.0
quarterized_retained_earnings_bonus: float = 0.0
effective_earnings: float = 0.0
effective_retained_earnings: float = 0.0
effective_revenue: float = 0.0
annualized_total_revenue: float = 0.0
annualized_total_revenue_bonus: float = 0.0
annualized_net_income: float = 0.0 # TODO: ASAFR: Add the bonus calculations (pos, neg, mon_inc, mon_dec, etc)
quarterized_total_revenue: float = 0.0
quarterized_total_revenue_bonus: float = 0.0
quarterized_net_income: float = 0.0
quarterized_net_income_bonus: float = 0.0
effective_net_income: float = 0.0
effective_total_revenue: float = 0.0
enterprise_value_to_revenue: float = 0.0
evr_effective: float = 0.0
evr_effective_normalized: float = 0.0
trailing_price_to_earnings: float = 0.0
forward_price_to_earnings: float = 0.0
effective_price_to_earnings: float = 0.0
trailing_12months_price_to_sales: float = 0.0
trailing_12months_price_to_sales_normalized: float = 0.0
pe_effective: float = 0.0
pe_effective_normalized: float = 0.0
enterprise_value_to_ebitda: float = 0.0
effective_ev_to_ebitda: float = 0.0
effective_ev_to_ebitda_normalized: float = 0.0
ebitda: float = 0.0
quarterized_ebitd: float = 0.0
annualized_ebitd: float = 0.0
ebitd: float = 0.0
profit_margin: float = 0.0
annualized_profit_margin: float = 0.0
annualized_profit_margin_boost: float = 0.0
quarterized_profit_margin: float = 0.0
quarterized_profit_margin_boost: float = 0.0
effective_profit_margin: float = 0.0
effective_profit_margin_normalized: float = 0.0
held_percent_institutions: float = 0.0
held_percent_insiders: float = 0.0
held_percent_insiders_normalized: float = 0.0
forward_eps: float = 0.0
trailing_eps: float = 0.0
previous_close: float = 0.0
trailing_eps_percentage: float = 0.0 # trailing_eps / previousClose
price_to_book: float = 0.0
price_to_book_normalized: float = 0.0
shares_outstanding: float = 0.0
net_income_to_common_shareholders: float = 0.0
nitcsh_to_shares_outstanding: float = 0.0
employees: int = 0
enterprise_value: int = 0
market_cap: int = 0
nitcsh_to_num_employees: float = 0.0
eqg: float = 0.0 # Value is a ratio, such that when multiplied by 100, yields percentage (%) units
rqg: float = 0.0 # Value is a ratio, such that when multiplied by 100, yields percentage (%) units
eqg_yoy: float = 0.0 # calculated from the yearly earnings - if available
rqg_yoy: float = 0.0 # calculated from the yearly Revenues - if available
niqg_yoy: float = 0.0 # Net Income Quarterly Growth: calculated from the yearly net income - if available
trqg_yoy: float = 0.0 # Total Revenue Quarterly Growth: calculated from the yearly net income - if available
eqg_effective: float = 0.0 # average of eqg_yoy and eqg
eqg_factor_effective: float = 0.0 # function with positive factor and damper
eqg_factor_effective_normalized: float = 0.0 # function with positive factor and damper
rqg_effective: float = 0.0 # average of rqg_yoy and rqg
rqg_factor_effective: float = 0.0 # function with positive factor and damper
rqg_factor_effective_normalized: float = 0.0 # function with positive factor and damper
price_to_earnings_to_growth_ratio: float = 0.0
effective_peg_ratio: float = 0.0
effective_peg_ratio_normalized: float = 0.0
annualized_cash_flow_from_operating_activities: float = 0.0
annualized_cash_flow_from_operating_activities_bonus: float = 0.0
quarterized_cash_flow_from_operating_activities: float = 0.0
quarterized_cash_flow_from_operating_activities_bonus:float = 0.0
annualized_ev_to_cfo_ratio: float = 0.0 # https://investinganswers.com/dictionary/e/enterprise-value-cash-flow-operations-evcfo
quarterized_ev_to_cfo_ratio: float = 0.0 # https://investinganswers.com/dictionary/e/enterprise-value-cash-flow-operations-evcfo
ev_to_cfo_ratio_effective: float = 0.0
ev_to_cfo_ratio_effective_normalized: float = 0.0
annualized_debt_to_equity: float = 0.0
annualized_debt_to_equity_bonus: float = 0.0
quarterized_debt_to_equity: float = 0.0
quarterized_debt_to_equity_bonus: float = 0.0
debt_to_equity_effective: float = 0.0
debt_to_equity_effective_used: float = 0.0
debt_to_equity_effective_used_normalized: float = 0.0
financial_currency: str = 'None'
summary_currency: str = 'None'
financial_currency_conversion_rate_mult_to_usd: float = 0.0
summary_currency_conversion_rate_mult_to_usd: float = 0.0
last_dividend_0: float = 0.0
last_dividend_1: float = 0.0
last_dividend_2: float = 0.0
last_dividend_3: float = 0.0
fifty_two_week_change: float = 0.0
fifty_two_week_low: float = 0.0
fifty_two_week_high: float = 0.0
two_hundred_day_average: float = 0.0
previous_close_percentage_from_200d_ma: float = 0.0
previous_close_percentage_from_52w_low: float = 0.0
previous_close_percentage_from_52w_high: float = 0.0
dist_from_low_factor: float = 0.0
eff_dist_from_low_factor: float = 0.0
eff_dist_from_low_factor_normalized: float = 0.0
annualized_total_ratio: float = 0.0
annualized_total_ratio_bonus: float = 0.0
quarterized_total_ratio: float = 0.0
quarterized_total_ratio_bonus: float = 0.0
annualized_other_current_ratio: float = 0.0
annualized_other_current_ratio_bonus: float = 0.0
quarterized_other_current_ratio: float = 0.0
quarterized_other_current_ratio_bonus: float = 0.0
annualized_other_ratio: float = 0.0
annualized_other_ratio_bonus: float = 0.0
quarterized_other_ratio: float = 0.0
quarterized_other_ratio_bonus: float = 0.0
annualized_total_current_ratio: float = 0.0
annualized_total_current_ratio_bonus: float = 0.0
quarterized_total_current_ratio: float = 0.0
quarterized_total_current_ratio_bonus: float = 0.0
total_ratio_effective: float = 0.0
other_current_ratio_effective: float = 0.0
other_ratio_effective: float = 0.0
total_current_ratio_effective: float = 0.0
effective_current_ratio: float = 0.0
effective_current_ratio_normalized: float = 0.0
annualized_total_assets: float = 0.0
annualized_total_assets_bonus: float = 0.0
quarterized_total_assets: float = 0.0
quarterized_total_assets_bonus: float = 0.0
effective_total_assets: float = 0.0
annualized_total_stockholder_equity: float = 0.0
annualized_total_stockholder_equity_bonus: float = 0.0
quarterized_total_stockholder_equity: float = 0.0
quarterized_total_stockholder_equity_bonus: float = 0.0
effective_total_stockholder_equity: float = 0.0
calculated_roa: float = 0.0
calculated_roa_normalized: float = 0.0
calculated_roe: float = 0.0
calculated_roe_normalized: float = 0.0
annualized_working_capital: float = 0.0
quarterized_working_capital: float = 0.0
effective_working_capital: float = 0.0
annualized_total_liabilities: float = 0.0
annualized_total_liabilities_bonus: float = 0.0
quarterized_total_liabilities: float = 0.0
quarterized_total_liabilities_bonus: float = 0.0
effective_total_liabilities: float = 0.0
altman_z_score_factor: float = 0.0
altman_z_score_factor_normalized: float = 0.0
skip_reason: str = 'None'
g_symbols_tase_duals = []
g_header_row = ["Symbol", "Name", "Sector", "Country", "sss_value", "ma", "annualized_revenue", "annualized_revenue_bonus", "annualized_earnings", "annualized_retained_earnings", "annualized_retained_earnings_bonus", "quarterized_revenue", "quarterized_revenue_bonus", "quarterized_earnings", "quarterized_earnings_bonus", "quarterized_retained_earnings", "quarterized_retained_earnings_bonus", "effective_earnings", "effective_retained_earnings", "effective_revenue", "annualized_total_revenue", "annualized_total_revenue_bonus", "annualized_net_income", "quarterized_total_revenue", "quarterized_total_revenue_bonus", "quarterized_net_income", "quarterized_net_income_bonus", "effective_net_income", "effective_total_revenue", "enterprise_value_to_revenue", "evr_effective", "trailing_price_to_earnings", "forward_price_to_earnings", "effective_price_to_earnings", "trailing_12months_price_to_sales", "pe_effective", "enterprise_value_to_ebitda", "effective_ev_to_ebitda", "ebitda", "quarterized_ebitd", "annualized_ebitd", "ebitd", "profit_margin", "annualized_profit_margin", "annualized_profit_margin_boost", "quarterized_profit_margin", "quarterized_profit_margin_boost", "effective_profit_margin", "held_percent_institutions", "held_percent_insiders", "forward_eps", "trailing_eps", "previous_close", "trailing_eps_percentage", "price_to_book", "shares_outstanding", "net_income_to_common_shareholders", "nitcsh_to_shares_outstanding", "employees", "enterprise_value", "market_cap", "nitcsh_to_num_employees", "eqg", "rqg", "eqg_yoy", "rqg_yoy", "niqg_yoy", "trqg_yoy", "eqg_effective", "eqg_factor_effective", "rqg_effective", "rqg_factor_effective", "price_to_earnings_to_growth_ratio", "effective_peg_ratio", "annualized_cash_flow_from_operating_activities", "annualized_cash_flow_from_operating_activities_bonus", "quarterized_cash_flow_from_operating_activities", "quarterized_cash_flow_from_operating_activities_bonus", "annualized_ev_to_cfo_ratio", "quarterized_ev_to_cfo_ratio", "ev_to_cfo_ratio_effective", "annualized_debt_to_equity", "annualized_debt_to_equity_bonus", "quarterized_debt_to_equity", "quarterized_debt_to_equity_bonus", "debt_to_equity_effective", "debt_to_equity_effective_used", "financial_currency", "summary_currency", "financial_currency_conversion_rate_mult_to_usd", "summary_currency_conversion_rate_mult_to_usd", "last_dividend_0", "last_dividend_1", "last_dividend_2", "last_dividend_3", "fifty_two_week_change", "fifty_two_week_low", "fifty_two_week_high", "two_hundred_day_average", "previous_close_percentage_from_200d_ma", "previous_close_percentage_from_52w_low", "previous_close_percentage_from_52w_high", "dist_from_low_factor", "eff_dist_from_low_factor", "annualized_total_ratio", "annualized_total_ratio_bonus", "quarterized_total_ratio", "quarterized_total_ratio_bonus", "annualized_other_current_ratio", "annualized_other_current_ratio_bonus", "quarterized_other_current_ratio", "quarterized_other_current_ratio_bonus", "annualized_other_ratio", "annualized_other_ratio_bonus", "quarterized_other_ratio", "quarterized_other_ratio_bonus", "annualized_total_current_ratio", "annualized_total_current_ratio_bonus", "quarterized_total_current_ratio", "quarterized_total_current_ratio_bonus", "total_ratio_effective", "other_current_ratio_effective", "other_ratio_effective", "total_current_ratio_effective", "effective_current_ratio", "annualized_total_assets", "annualized_total_assets_bonus", "quarterized_total_assets", "quarterized_total_assets_bonus", "effective_total_assets", "annualized_total_stockholder_equity", "annualized_total_stockholder_equity_bonus", "quarterized_total_stockholder_equity", "quarterized_total_stockholder_equity_bonus", "effective_total_stockholder_equity", "calculated_roa", "calculated_roe", "annualized_working_capital", "quarterized_working_capital", "effective_working_capital", "annualized_total_liabilities", "annualized_total_liabilities_bonus", "quarterized_total_liabilities", "quarterized_total_liabilities_bonus", "effective_total_liabilities", "altman_z_score_factor", "skip_reason" ]
g_header_row_normalized = ["Symbol", "Name", "Sector", "Country", "sss_value", "sss_value_normalized", "ma", "annualized_revenue", "annualized_revenue_bonus", "annualized_earnings", "annualized_retained_earnings", "annualized_retained_earnings_bonus", "quarterized_revenue", "quarterized_revenue_bonus", "quarterized_earnings", "quarterized_earnings_bonus", "quarterized_retained_earnings", "quarterized_retained_earnings_bonus", "effective_earnings", "effective_retained_earnings", "effective_revenue", "annualized_total_revenue", "annualized_total_revenue_bonus", "annualized_net_income", "quarterized_total_revenue", "quarterized_total_revenue_bonus", "quarterized_net_income", "quarterized_net_income_bonus", "effective_net_income", "effective_total_revenue", "enterprise_value_to_revenue", "evr_effective", "evr_effective_normalized", "trailing_price_to_earnings", "forward_price_to_earnings", "effective_price_to_earnings", "trailing_12months_price_to_sales", "trailing_12months_price_to_sales_normalized", "pe_effective", "pe_effective_normalized", "enterprise_value_to_ebitda", "effective_ev_to_ebitda", "effective_ev_to_ebitda_normalized", "ebitda", "quarterized_ebitd", "annualized_ebitd", "ebitd", "profit_margin", "annualized_profit_margin", "annualized_profit_margin_boost", "quarterized_profit_margin", "quarterized_profit_margin_boost", "effective_profit_margin", "effective_profit_margin_normalized", "held_percent_institutions", "held_percent_insiders", "held_percent_insiders_normalized", "forward_eps", "trailing_eps", "previous_close", "trailing_eps_percentage", "price_to_book", "price_to_book_normalized", "shares_outstanding", "net_income_to_common_shareholders", "nitcsh_to_shares_outstanding", "employees", "enterprise_value", "market_cap", "nitcsh_to_num_employees", "eqg", "rqg", "eqg_yoy", "rqg_yoy", "niqg_yoy", "trqg_yoy", "eqg_effective", "eqg_factor_effective", "eqg_factor_effective_normalized", "rqg_effective", "rqg_factor_effective", "rqg_factor_effective_normalized", "price_to_earnings_to_growth_ratio", "effective_peg_ratio", "effective_peg_ratio_normalized", "annualized_cash_flow_from_operating_activities", "annualized_cash_flow_from_operating_activities_bonus", "quarterized_cash_flow_from_operating_activities", "quarterized_cash_flow_from_operating_activities_bonus", "annualized_ev_to_cfo_ratio", "quarterized_ev_to_cfo_ratio", "ev_to_cfo_ratio_effective", "ev_to_cfo_ratio_effective_normalized", "annualized_debt_to_equity", "annualized_debt_to_equity_bonus", "quarterized_debt_to_equity", "quarterized_debt_to_equity_bonus", "debt_to_equity_effective", "debt_to_equity_effective_used", "debt_to_equity_effective_used_normalized", "financial_currency", "summary_currency", "financial_currency_conversion_rate_mult_to_usd", "summary_currency_conversion_rate_mult_to_usd", "last_dividend_0", "last_dividend_1", "last_dividend_2", "last_dividend_3", "fifty_two_week_change", "fifty_two_week_low", "fifty_two_week_high", "two_hundred_day_average", "previous_close_percentage_from_200d_ma", "previous_close_percentage_from_52w_low", "previous_close_percentage_from_52w_high", "dist_from_low_factor", "eff_dist_from_low_factor", "eff_dist_from_low_factor_normalized", "annualized_total_ratio", "annualized_total_ratio_bonus", "quarterized_total_ratio", "quarterized_total_ratio_bonus", "annualized_other_current_ratio", "annualized_other_current_ratio_bonus", "quarterized_other_current_ratio", "quarterized_other_current_ratio_bonus", "annualized_other_ratio", "annualized_other_ratio_bonus", "quarterized_other_ratio", "quarterized_other_ratio_bonus", "annualized_total_current_ratio", "annualized_total_current_ratio_bonus", "quarterized_total_current_ratio", "quarterized_total_current_ratio_bonus", "total_ratio_effective", "other_current_ratio_effective", "other_ratio_effective", "total_current_ratio_effective", "effective_current_ratio", "effective_current_ratio_normalized", "annualized_total_assets", "annualized_total_assets_bonus", "quarterized_total_assets", "quarterized_total_assets_bonus", "effective_total_assets", "annualized_total_stockholder_equity", "annualized_total_stockholder_equity_bonus", "quarterized_total_stockholder_equity", "quarterized_total_stockholder_equity_bonus", "effective_total_stockholder_equity", "calculated_roa", "calculated_roa_normalized", "calculated_roe", "calculated_roe_normalized", "annualized_working_capital", "quarterized_working_capital", "effective_working_capital", "annualized_total_liabilities", "annualized_total_liabilities_bonus", "quarterized_total_liabilities", "quarterized_total_liabilities_bonus", "effective_total_liabilities", "altman_z_score_factor", "altman_z_score_factor_normalized", "skip_reason" ]
g_symbol_index = g_header_row.index("Symbol")
g_name_index = g_header_row.index("Name")
g_sector_index = g_header_row.index("Sector")
g_country_index = g_header_row.index("Country")
g_sss_value_index = g_header_row.index("sss_value")
g_ma_index = g_header_row.index("ma")
g_annualized_revenue_index = g_header_row.index("annualized_revenue")
g_annualized_revenue_bonus_index = g_header_row.index("annualized_revenue_bonus")
g_annualized_earnings_index = g_header_row.index("annualized_earnings")
g_annualized_retained_earnings_index = g_header_row.index("annualized_retained_earnings")
g_annualized_retained_earnings_bonus_index = g_header_row.index("annualized_retained_earnings_bonus")
g_quarterized_revenue_index = g_header_row.index("quarterized_revenue")
g_quarterized_revenue_bonus_index = g_header_row.index("quarterized_revenue_bonus")
g_quarterized_earnings_index = g_header_row.index("quarterized_earnings")
g_quarterized_earnings_bonus_index = g_header_row.index("quarterized_earnings_bonus")
g_quarterized_retained_earnings_index = g_header_row.index("quarterized_retained_earnings")
g_quarterized_retained_earnings_bonus_index = g_header_row.index("quarterized_retained_earnings_bonus")
g_effective_earnings_index = g_header_row.index("effective_earnings")
g_effective_retained_earnings_index = g_header_row.index("effective_retained_earnings")
g_effective_revenue_index = g_header_row.index("effective_revenue")
g_annualized_total_revenue_index = g_header_row.index("annualized_total_revenue")
g_annualized_total_revenue_bonus_index = g_header_row.index("annualized_total_revenue_bonus")
g_annualized_net_income_index = g_header_row.index("annualized_net_income")
g_quarterized_total_revenue_index = g_header_row.index("quarterized_total_revenue")
g_quarterized_total_revenue_bonus_index = g_header_row.index("quarterized_total_revenue_bonus")
g_quarterized_net_income_index = g_header_row.index("quarterized_net_income")
g_quarterized_net_income_bonus_index = g_header_row.index("quarterized_net_income_bonus")
g_effective_net_income_index = g_header_row.index("effective_net_income")
g_effective_total_revenue_index = g_header_row.index("effective_total_revenue")
g_enterprise_value_to_revenue_index = g_header_row.index("enterprise_value_to_revenue")
g_evr_effective_index = g_header_row.index("evr_effective")
g_trailing_price_to_earnings_index = g_header_row.index("trailing_price_to_earnings")
g_forward_price_to_earnings_index = g_header_row.index("forward_price_to_earnings")
g_effective_price_to_earnings_index = g_header_row.index("effective_price_to_earnings")
g_trailing_12months_price_to_sales_index = g_header_row.index("trailing_12months_price_to_sales")
g_pe_effective_index = g_header_row.index("pe_effective")
g_enterprise_value_to_ebitda_index = g_header_row.index("enterprise_value_to_ebitda")
g_effective_ev_to_ebitda_index = g_header_row.index("effective_ev_to_ebitda")
g_ebitda_index = g_header_row.index("ebitda")
g_quarterized_ebitd_index = g_header_row.index("quarterized_ebitd")
g_annualized_ebitd_index = g_header_row.index("annualized_ebitd")
g_ebitd_index = g_header_row.index("ebitd")
g_profit_margin_index = g_header_row.index("profit_margin")
g_annualized_profit_margin_index = g_header_row.index("annualized_profit_margin")
g_annualized_profit_margin_boost_index = g_header_row.index("annualized_profit_margin_boost")
g_quarterized_profit_margin_index = g_header_row.index("quarterized_profit_margin")
g_quarterized_profit_margin_boost_index = g_header_row.index("quarterized_profit_margin_boost")
g_effective_profit_margin_index = g_header_row.index("effective_profit_margin")
g_held_percent_institutions_index = g_header_row.index("held_percent_institutions")
g_held_percent_insiders_index = g_header_row.index("held_percent_insiders")
g_forward_eps_index = g_header_row.index("forward_eps")
g_trailing_eps_index = g_header_row.index("trailing_eps")
g_previous_close_index = g_header_row.index("previous_close")
g_trailing_eps_percentage_index = g_header_row.index("trailing_eps_percentage")
g_price_to_book_index = g_header_row.index("price_to_book")
g_shares_outstanding_index = g_header_row.index("shares_outstanding")
g_net_income_to_common_shareholders_index = g_header_row.index("net_income_to_common_shareholders")
g_nitcsh_to_shares_outstanding_index = g_header_row.index("nitcsh_to_shares_outstanding")
g_employees_index = g_header_row.index("employees")
g_enterprise_value_index = g_header_row.index("enterprise_value")
g_market_cap_index = g_header_row.index("market_cap")
g_nitcsh_to_num_employees_index = g_header_row.index("nitcsh_to_num_employees")
g_eqg_index = g_header_row.index("eqg")
g_rqg_index = g_header_row.index("rqg")
g_eqg_yoy_index = g_header_row.index("eqg_yoy")
g_rqg_yoy_index = g_header_row.index("rqg_yoy")
g_niqg_yoy_index = g_header_row.index("niqg_yoy")
g_trqg_yoy_index = g_header_row.index("trqg_yoy")
g_eqg_effective_index = g_header_row.index("eqg_effective")
g_eqg_factor_effective_index = g_header_row.index("eqg_factor_effective")
g_rqg_effective_index = g_header_row.index("rqg_effective")
g_rqg_factor_effective_index = g_header_row.index("rqg_factor_effective")
g_price_to_earnings_to_growth_ratio_index = g_header_row.index("price_to_earnings_to_growth_ratio")
g_effective_peg_ratio_index = g_header_row.index("effective_peg_ratio")
g_annualized_cash_flow_from_operating_activities_index = g_header_row.index("annualized_cash_flow_from_operating_activities")
g_annualized_cash_flow_from_operating_activities_bonus_index = g_header_row.index("annualized_cash_flow_from_operating_activities_bonus")
g_quarterized_cash_flow_from_operating_activities_index = g_header_row.index("quarterized_cash_flow_from_operating_activities")
g_quarterized_cash_flow_from_operating_activities_bonus_index = g_header_row.index("quarterized_cash_flow_from_operating_activities_bonus")
g_annualized_ev_to_cfo_ratio_index = g_header_row.index("annualized_ev_to_cfo_ratio")
g_quarterized_ev_to_cfo_ratio_index = g_header_row.index("quarterized_ev_to_cfo_ratio")
g_ev_to_cfo_ratio_effective_index = g_header_row.index("ev_to_cfo_ratio_effective")
g_annualized_debt_to_equity_index = g_header_row.index("annualized_debt_to_equity")
g_annualized_debt_to_equity_bonus_index = g_header_row.index("annualized_debt_to_equity_bonus")
g_quarterized_debt_to_equity_index = g_header_row.index("quarterized_debt_to_equity")
g_quarterized_debt_to_equity_bonus_index = g_header_row.index("quarterized_debt_to_equity_bonus")
g_debt_to_equity_effective_index = g_header_row.index("debt_to_equity_effective")
g_debt_to_equity_effective_used_index = g_header_row.index("debt_to_equity_effective_used")
g_financial_currency_index = g_header_row.index("financial_currency")
g_summary_currency_index = g_header_row.index("summary_currency")
g_financial_currency_conversion_rate_mult_to_usd_index = g_header_row.index("financial_currency_conversion_rate_mult_to_usd")
g_summary_currency_conversion_rate_mult_to_usd_index = g_header_row.index("summary_currency_conversion_rate_mult_to_usd")
g_last_dividend_0_index = g_header_row.index("last_dividend_0")
g_last_dividend_1_index = g_header_row.index("last_dividend_1")
g_last_dividend_2_index = g_header_row.index("last_dividend_2")
g_last_dividend_3_index = g_header_row.index("last_dividend_3")
g_fifty_two_week_change_index = g_header_row.index("fifty_two_week_change")
g_fifty_two_week_low_index = g_header_row.index("fifty_two_week_low")
g_fifty_two_week_high_index = g_header_row.index("fifty_two_week_high")
g_two_hundred_day_average_index = g_header_row.index("two_hundred_day_average")
g_previous_close_percentage_from_200d_ma_index = g_header_row.index("previous_close_percentage_from_200d_ma")
g_previous_close_percentage_from_52w_low_index = g_header_row.index("previous_close_percentage_from_52w_low")
g_previous_close_percentage_from_52w_high_index = g_header_row.index("previous_close_percentage_from_52w_high")
g_dist_from_low_factor_index = g_header_row.index("dist_from_low_factor")
g_eff_dist_from_low_factor_index = g_header_row.index("eff_dist_from_low_factor")
g_annualized_total_ratio_index = g_header_row.index("annualized_total_ratio")
g_annualized_total_ratio_bonus_index = g_header_row.index("annualized_total_ratio_bonus")
g_quarterized_total_ratio_index = g_header_row.index("quarterized_total_ratio")
g_quarterized_total_ratio_bonus_index = g_header_row.index("quarterized_total_ratio_bonus")
g_annualized_other_current_ratio_index = g_header_row.index("annualized_other_current_ratio")
g_annualized_other_current_ratio_bonus_index = g_header_row.index("annualized_other_current_ratio_bonus")
g_quarterized_other_current_ratio_index = g_header_row.index("quarterized_other_current_ratio")
g_quarterized_other_current_ratio_bonus_index = g_header_row.index("quarterized_other_current_ratio_bonus")
g_annualized_other_ratio_index = g_header_row.index("annualized_other_ratio")
g_annualized_other_ratio_bonus_index = g_header_row.index("annualized_other_ratio_bonus")
g_quarterized_other_ratio_index = g_header_row.index("quarterized_other_ratio")
g_quarterized_other_ratio_bonus_index = g_header_row.index("quarterized_other_ratio_bonus")
g_annualized_total_current_ratio_index = g_header_row.index("annualized_total_current_ratio")
g_annualized_total_current_ratio_bonus_index = g_header_row.index("annualized_total_current_ratio_bonus")
g_quarterized_total_current_ratio_index = g_header_row.index("quarterized_total_current_ratio")
g_quarterized_total_current_ratio_bonus_index = g_header_row.index("quarterized_total_current_ratio_bonus")
g_total_ratio_effective_index = g_header_row.index("total_ratio_effective")
g_other_current_ratio_effective_index = g_header_row.index("other_current_ratio_effective")
g_other_ratio_effective_index = g_header_row.index("other_ratio_effective")
g_total_current_ratio_effective_index = g_header_row.index("total_current_ratio_effective")
g_effective_current_ratio_index = g_header_row.index("effective_current_ratio")
g_annualized_total_assets_index = g_header_row.index("annualized_total_assets")
g_annualized_total_assets_bonus_index = g_header_row.index("annualized_total_assets_bonus")
g_quarterized_total_assets_index = g_header_row.index("quarterized_total_assets")
g_quarterized_total_assets_bonus_index = g_header_row.index("quarterized_total_assets_bonus")
g_effective_total_assets_index = g_header_row.index("effective_total_assets")
g_annualized_total_stockholder_equity_index = g_header_row.index("annualized_total_stockholder_equity")
g_annualized_total_stockholder_equity_bonus_index = g_header_row.index("annualized_total_stockholder_equity_bonus")
g_quarterized_total_stockholder_equity_index = g_header_row.index("quarterized_total_stockholder_equity")
g_quarterized_total_stockholder_equity_bonus_index = g_header_row.index("quarterized_total_stockholder_equity_bonus")
g_effective_total_stockholder_equity_index = g_header_row.index("effective_total_stockholder_equity")
g_calculated_roa_index = g_header_row.index("calculated_roa")
g_calculated_roe_index = g_header_row.index("calculated_roe")
g_annualized_working_capital_index = g_header_row.index("annualized_working_capital")
g_quarterized_working_capital_index = g_header_row.index("quarterized_working_capital")
g_effective_working_capital_index = g_header_row.index("effective_working_capital")
g_annualized_total_liabilities_index = g_header_row.index("annualized_total_liabilities")
g_annualized_total_liabilities_bonus_index = g_header_row.index("annualized_total_liabilities_bonus")
g_quarterized_total_liabilities_index = g_header_row.index("quarterized_total_liabilities")
g_quarterized_total_liabilities_bonus_index = g_header_row.index("quarterized_total_liabilities_bonus")
g_effective_total_liabilities_index = g_header_row.index("effective_total_liabilities")
g_altman_z_score_factor_index = g_header_row.index("altman_z_score_factor")
g_skip_reason_index = g_header_row.index("skip_reason")
g_symbol_index_n = g_header_row_normalized.index("Symbol")
g_name_index_n = g_header_row_normalized.index("Name")
g_sector_index_n = g_header_row_normalized.index("Sector")
g_country_index_n = g_header_row_normalized.index("Country")
g_sss_value_index_n = g_header_row_normalized.index("sss_value")
g_sss_value_normalized_index_n = g_header_row_normalized.index("sss_value_normalized")
g_ma_index_n = g_header_row_normalized.index("ma")
g_annualized_revenue_index_n = g_header_row_normalized.index("annualized_revenue")
g_annualized_revenue_bonus_index_n = g_header_row_normalized.index("annualized_revenue_bonus")
g_annualized_earnings_index_n = g_header_row_normalized.index("annualized_earnings")
g_annualized_retained_earnings_index_n = g_header_row_normalized.index("annualized_retained_earnings")
g_annualized_retained_earnings_bonus_index_n = g_header_row_normalized.index("annualized_retained_earnings_bonus")
g_quarterized_revenue_index_n = g_header_row_normalized.index("quarterized_revenue")
g_quarterized_revenue_bonus_index_n = g_header_row_normalized.index("quarterized_revenue_bonus")
g_quarterized_earnings_index_n = g_header_row_normalized.index("quarterized_earnings")
g_quarterized_earnings_bonus_index_n = g_header_row_normalized.index("quarterized_earnings_bonus")
g_quarterized_retained_earnings_index_n = g_header_row_normalized.index("quarterized_retained_earnings")
g_quarterized_retained_earnings_bonus_index_n = g_header_row_normalized.index("quarterized_retained_earnings_bonus")
g_effective_earnings_index_n = g_header_row_normalized.index("effective_earnings")
g_effective_retained_earnings_index_n = g_header_row_normalized.index("effective_retained_earnings")
g_effective_revenue_index_n = g_header_row_normalized.index("effective_revenue")
g_annualized_total_revenue_index_n = g_header_row_normalized.index("annualized_total_revenue")
g_annualized_total_revenue_bonus_index_n = g_header_row_normalized.index("annualized_total_revenue_bonus")
g_annualized_net_income_index_n = g_header_row_normalized.index("annualized_net_income")
g_quarterized_total_revenue_index_n = g_header_row_normalized.index("quarterized_total_revenue")
g_quarterized_total_revenue_bonus_index_n = g_header_row_normalized.index("quarterized_total_revenue_bonus")
g_quarterized_net_income_index_n = g_header_row_normalized.index("quarterized_net_income")
g_quarterized_net_income_bonus_index_n = g_header_row_normalized.index("quarterized_net_income_bonus")
g_effective_net_income_index_n = g_header_row_normalized.index("effective_net_income")
g_effective_total_revenue_index_n = g_header_row_normalized.index("effective_total_revenue")
g_enterprise_value_to_revenue_index_n = g_header_row_normalized.index("enterprise_value_to_revenue")
g_evr_effective_index_n = g_header_row_normalized.index("evr_effective")
g_evr_effective_normalized_index_n = g_header_row_normalized.index("evr_effective_normalized")
g_trailing_price_to_earnings_index_n = g_header_row_normalized.index("trailing_price_to_earnings")
g_forward_price_to_earnings_index_n = g_header_row_normalized.index("forward_price_to_earnings")
g_effective_price_to_earnings_index_n = g_header_row_normalized.index("effective_price_to_earnings")
g_trailing_12months_price_to_sales_index_n = g_header_row_normalized.index("trailing_12months_price_to_sales")
g_trailing_12months_price_to_sales_normalized_index_n = g_header_row_normalized.index("trailing_12months_price_to_sales_normalized")
g_pe_effective_index_n = g_header_row_normalized.index("pe_effective")
g_pe_effective_normalized_index_n = g_header_row_normalized.index("pe_effective_normalized")
g_enterprise_value_to_ebitda_index_n = g_header_row_normalized.index("enterprise_value_to_ebitda")
g_effective_ev_to_ebitda_index_n = g_header_row_normalized.index("effective_ev_to_ebitda")
g_effective_ev_to_ebitda_normalized_index_n = g_header_row_normalized.index("effective_ev_to_ebitda_normalized")
g_ebitda_index_n = g_header_row_normalized.index("ebitda")
g_quarterized_ebitd_index_n = g_header_row_normalized.index("quarterized_ebitd")
g_annualized_ebitd_index_n = g_header_row_normalized.index("annualized_ebitd")
g_ebitd_index_n = g_header_row_normalized.index("ebitd")
g_profit_margin_index_n = g_header_row_normalized.index("profit_margin")
g_annualized_profit_margin_index_n = g_header_row_normalized.index("annualized_profit_margin")
g_annualized_profit_margin_boost_index_n = g_header_row_normalized.index("annualized_profit_margin_boost")
g_quarterized_profit_margin_index_n = g_header_row_normalized.index("quarterized_profit_margin")
g_quarterized_profit_margin_boost_index_n = g_header_row_normalized.index("quarterized_profit_margin_boost")
g_effective_profit_margin_index_n = g_header_row_normalized.index("effective_profit_margin")
g_effective_profit_margin_normalized_index_n = g_header_row_normalized.index("effective_profit_margin_normalized")
g_held_percent_institutions_index_n = g_header_row_normalized.index("held_percent_institutions")
g_held_percent_insiders_index_n = g_header_row_normalized.index("held_percent_insiders")
g_held_percent_insiders_normalized_index_n = g_header_row_normalized.index("held_percent_insiders_normalized")
g_forward_eps_index_n = g_header_row_normalized.index("forward_eps")
g_trailing_eps_index_n = g_header_row_normalized.index("trailing_eps")
g_previous_close_index_n = g_header_row_normalized.index("previous_close")
g_trailing_eps_percentage_index_n = g_header_row_normalized.index("trailing_eps_percentage")
g_price_to_book_index_n = g_header_row_normalized.index("price_to_book")
g_price_to_book_normalized_index_n = g_header_row_normalized.index("price_to_book_normalized")
g_shares_outstanding_index_n = g_header_row_normalized.index("shares_outstanding")
g_net_income_to_common_shareholders_index_n = g_header_row_normalized.index("net_income_to_common_shareholders")
g_nitcsh_to_shares_outstanding_index_n = g_header_row_normalized.index("nitcsh_to_shares_outstanding")
g_employees_index_n = g_header_row_normalized.index("employees")
g_enterprise_value_index_n = g_header_row_normalized.index("enterprise_value")
g_market_cap_index_n = g_header_row_normalized.index("market_cap")
g_nitcsh_to_num_employees_index_n = g_header_row_normalized.index("nitcsh_to_num_employees")
g_eqg_index_n = g_header_row_normalized.index("eqg")
g_rqg_index_n = g_header_row_normalized.index("rqg")
g_eqg_yoy_index_n = g_header_row_normalized.index("eqg_yoy")
g_rqg_yoy_index_n = g_header_row_normalized.index("rqg_yoy")
g_niqg_yoy_index_n = g_header_row_normalized.index("niqg_yoy")
g_trqg_yoy_index_n = g_header_row_normalized.index("trqg_yoy")
g_eqg_effective_index_n = g_header_row_normalized.index("eqg_effective")
g_eqg_factor_effective_index_n = g_header_row_normalized.index("eqg_factor_effective")
g_eqg_factor_effective_normalized_index_n = g_header_row_normalized.index("eqg_factor_effective_normalized")
g_rqg_effective_index_n = g_header_row_normalized.index("rqg_effective")
g_rqg_factor_effective_index_n = g_header_row_normalized.index("rqg_factor_effective")
g_rqg_factor_effective_normalized_index_n = g_header_row_normalized.index("rqg_factor_effective_normalized")
g_price_to_earnings_to_growth_ratio_index_n = g_header_row_normalized.index("price_to_earnings_to_growth_ratio")
g_effective_peg_ratio_index_n = g_header_row_normalized.index("effective_peg_ratio")
g_effective_peg_ratio_normalized_index_n = g_header_row_normalized.index("effective_peg_ratio_normalized")
g_annualized_cash_flow_from_operating_activities_index_n = g_header_row_normalized.index("annualized_cash_flow_from_operating_activities")
g_annualized_cash_flow_from_operating_activities_bonus_index_n = g_header_row_normalized.index("annualized_cash_flow_from_operating_activities_bonus")
g_quarterized_cash_flow_from_operating_activities_index_n = g_header_row_normalized.index("quarterized_cash_flow_from_operating_activities")
g_quarterized_cash_flow_from_operating_activities_bonus_index_n = g_header_row_normalized.index("quarterized_cash_flow_from_operating_activities_bonus")
g_annualized_ev_to_cfo_ratio_index_n = g_header_row_normalized.index("annualized_ev_to_cfo_ratio")
g_quarterized_ev_to_cfo_ratio_index_n = g_header_row_normalized.index("quarterized_ev_to_cfo_ratio")
g_ev_to_cfo_ratio_effective_index_n = g_header_row_normalized.index("ev_to_cfo_ratio_effective")
g_ev_to_cfo_ratio_effective_normalized_index_n = g_header_row_normalized.index("ev_to_cfo_ratio_effective_normalized")
g_annualized_debt_to_equity_index_n = g_header_row_normalized.index("annualized_debt_to_equity")
g_annualized_debt_to_equity_bonus_index_n = g_header_row_normalized.index("annualized_debt_to_equity_bonus")
g_quarterized_debt_to_equity_index_n = g_header_row_normalized.index("quarterized_debt_to_equity")
g_quarterized_debt_to_equity_bonus_index_n = g_header_row_normalized.index("quarterized_debt_to_equity_bonus")
g_debt_to_equity_effective_index_n = g_header_row_normalized.index("debt_to_equity_effective")
g_debt_to_equity_effective_used_index_n = g_header_row_normalized.index("debt_to_equity_effective_used")
g_debt_to_equity_effective_used_normalized_index_n = g_header_row_normalized.index("debt_to_equity_effective_used_normalized")
g_financial_currency_index_n = g_header_row_normalized.index("financial_currency")
g_summary_currency_index_n = g_header_row_normalized.index("summary_currency")
g_financial_currency_conversion_rate_mult_to_usd_index_n = g_header_row_normalized.index("financial_currency_conversion_rate_mult_to_usd")
g_summary_currency_conversion_rate_mult_to_usd_index_n = g_header_row_normalized.index("summary_currency_conversion_rate_mult_to_usd")
g_last_dividend_0_index_n = g_header_row_normalized.index("last_dividend_0")
g_last_dividend_1_index_n = g_header_row_normalized.index("last_dividend_1")
g_last_dividend_2_index_n = g_header_row_normalized.index("last_dividend_2")
g_last_dividend_3_index_n = g_header_row_normalized.index("last_dividend_3")
g_fifty_two_week_change_index_n = g_header_row_normalized.index("fifty_two_week_change")
g_fifty_two_week_low_index_n = g_header_row_normalized.index("fifty_two_week_low")
g_fifty_two_week_high_index_n = g_header_row_normalized.index("fifty_two_week_high")
g_two_hundred_day_average_index_n = g_header_row_normalized.index("two_hundred_day_average")
g_previous_close_percentage_from_200d_ma_index_n = g_header_row_normalized.index("previous_close_percentage_from_200d_ma")
g_previous_close_percentage_from_52w_low_index_n = g_header_row_normalized.index("previous_close_percentage_from_52w_low")
g_previous_close_percentage_from_52w_high_index_n = g_header_row_normalized.index("previous_close_percentage_from_52w_high")
g_dist_from_low_factor_index_n = g_header_row_normalized.index("dist_from_low_factor")
g_eff_dist_from_low_factor_index_n = g_header_row_normalized.index("eff_dist_from_low_factor")
g_eff_dist_from_low_factor_normalized_index_n = g_header_row_normalized.index("eff_dist_from_low_factor_normalized")
g_annualized_total_ratio_index_n = g_header_row_normalized.index("annualized_total_ratio")
g_annualized_total_ratio_bonus_index_n = g_header_row_normalized.index("annualized_total_ratio_bonus")
g_quarterized_total_ratio_index_n = g_header_row_normalized.index("quarterized_total_ratio")
g_quarterized_total_ratio_bonus_index_n = g_header_row_normalized.index("quarterized_total_ratio_bonus")
g_annualized_other_current_ratio_index_n = g_header_row_normalized.index("annualized_other_current_ratio")
g_annualized_other_current_ratio_bonus_index_n = g_header_row_normalized.index("annualized_other_current_ratio_bonus")
g_quarterized_other_current_ratio_index_n = g_header_row_normalized.index("quarterized_other_current_ratio")
g_quarterized_other_current_ratio_bonus_index_n = g_header_row_normalized.index("quarterized_other_current_ratio_bonus")
g_annualized_other_ratio_index_n = g_header_row_normalized.index("annualized_other_ratio")
g_annualized_other_ratio_bonus_index_n = g_header_row_normalized.index("annualized_other_ratio_bonus")
g_quarterized_other_ratio_index_n = g_header_row_normalized.index("quarterized_other_ratio")
g_quarterized_other_ratio_bonus_index_n = g_header_row_normalized.index("quarterized_other_ratio_bonus")
g_annualized_total_current_ratio_index_n = g_header_row_normalized.index("annualized_total_current_ratio")
g_annualized_total_current_ratio_bonus_index_n = g_header_row_normalized.index("annualized_total_current_ratio_bonus")
g_quarterized_total_current_ratio_index_n = g_header_row_normalized.index("quarterized_total_current_ratio")
g_quarterized_total_current_ratio_bonus_index_n = g_header_row_normalized.index("quarterized_total_current_ratio_bonus")
g_total_ratio_effective_index_n = g_header_row_normalized.index("total_ratio_effective")
g_other_current_ratio_effective_index_n = g_header_row_normalized.index("other_current_ratio_effective")
g_other_ratio_effective_index_n = g_header_row_normalized.index("other_ratio_effective")
g_total_current_ratio_effective_index_n = g_header_row_normalized.index("total_current_ratio_effective")
g_effective_current_ratio_index_n = g_header_row_normalized.index("effective_current_ratio")
g_effective_current_ratio_normalized_index_n = g_header_row_normalized.index("effective_current_ratio_normalized")
g_annualized_total_assets_index_n = g_header_row_normalized.index("annualized_total_assets")
g_annualized_total_assets_bonus_index_n = g_header_row_normalized.index("annualized_total_assets_bonus")
g_quarterized_total_assets_index_n = g_header_row_normalized.index("quarterized_total_assets")
g_quarterized_total_assets_bonus_index_n = g_header_row_normalized.index("quarterized_total_assets_bonus")
g_effective_total_assets_index_n = g_header_row_normalized.index("effective_total_assets")
g_annualized_total_stockholder_equity_index_n = g_header_row_normalized.index("annualized_total_stockholder_equity")
g_annualized_total_stockholder_equity_bonus_index_n = g_header_row_normalized.index("annualized_total_stockholder_equity_bonus")
g_quarterized_total_stockholder_equity_index_n = g_header_row_normalized.index("quarterized_total_stockholder_equity")
g_quarterized_total_stockholder_equity_bonus_index_n = g_header_row_normalized.index("quarterized_total_stockholder_equity_bonus")
g_effective_total_stockholder_equity_index_n = g_header_row_normalized.index("effective_total_stockholder_equity")
g_calculated_roa_index_n = g_header_row_normalized.index("calculated_roa")
g_calculated_roa_normalized_index_n = g_header_row_normalized.index("calculated_roa_normalized")
g_calculated_roe_index_n = g_header_row_normalized.index("calculated_roe")
g_calculated_roe_normalized_index_n = g_header_row_normalized.index("calculated_roe_normalized")
g_annualized_working_capital_index_n = g_header_row_normalized.index("annualized_working_capital")
g_quarterized_working_capital_index_n = g_header_row_normalized.index("quarterized_working_capital")
g_effective_working_capital_index_n = g_header_row_normalized.index("effective_working_capital")
g_annualized_total_liabilities_index_n = g_header_row_normalized.index("annualized_total_liabilities")
g_annualized_total_liabilities_bonus_index_n = g_header_row_normalized.index("annualized_total_liabilities_bonus")
g_quarterized_total_liabilities_index_n = g_header_row_normalized.index("quarterized_total_liabilities")
g_quarterized_total_liabilities_bonus_index_n = g_header_row_normalized.index("quarterized_total_liabilities_bonus")
g_effective_total_liabilities_index_n = g_header_row_normalized.index("effective_total_liabilities")
g_altman_z_score_factor_index_n = g_header_row_normalized.index("altman_z_score_factor")
g_altman_z_score_factor_normalized_index_n = g_header_row_normalized.index("altman_z_score_factor_normalized")
g_skip_reason_index_n = g_header_row_normalized.index("skip_reason")
def check_quote_type(stock_data, research_mode):
if stock_data.quote_type == 'MUTUALFUND' and not research_mode: # Definition of a mutual fund 'quoteType' field in base.py, those are not interesting
print('Mutual Fund: Skip')
return False # Not interested in those and they lack all the below info[] properties so nothing to do with them anyways
if stock_data.quote_type == 'ETF' and not research_mode: # Definition of a mutual fund 'quoteType' field in base.py, those are not interesting
print('ETF: Skip')
return False # Not interested in those and they lack all the below info[] properties so nothing to do with them anyways
return True
def check_sector(stock_data, sectors_list):
# Fix stocks' Sectors to Correct Sector. yfinance sometimes has those mistaken
if stock_data.symbol in ['BRMG.TA', 'RLCO.TA', 'DELT.TA', 'TDRN.TA', 'ECP.TA' ]: stock_data.sector = 'Consumer Cyclical'
elif stock_data.symbol in ['EFNC.TA', 'GIBUI.TA', 'KMNK-M.TA' ]: stock_data.sector = 'Financial Services'
elif stock_data.symbol in ['DEDR-L.TA', 'GLEX-L', 'RPAC.TA', 'CDEV.TA', 'GNRS.TA' ]: stock_data.sector = 'Energy'
elif stock_data.symbol in ['GLRS.TA', 'WILC.TA', 'MEDN.TA' ]: stock_data.sector = 'Consumer Defensive'
elif stock_data.symbol in ['POLY.TA', 'WTS.TA', 'YBOX.TA', 'PLAZ-L.TA', 'TIGBUR.TA',
'ROTS.TA', 'AZRT.TA', 'SKBN.TA', 'DUNI.TA', 'DNYA.TA',
'HGG.TA', 'YAAC.TA', 'LZNR.TA', 'LSCO.TA', 'MGRT.TA',
'ALMA.TA', 'RTSN.TA', 'AVIV.TA', 'KRNV.TA', 'LAHAV.TA',
'NERZ.TA', 'SNEL.TA' ]: stock_data.sector = 'Real Estate'
elif stock_data.symbol in ['XTLB.TA', 'UNVO.TA', 'BONS.TA', 'CSURE.TA', 'GODM-M.TA',
'ILX.TA', 'LCTX.TA', 'ORMP.TA' ]: stock_data.sector = 'Healthcare'
elif stock_data.symbol in ['BIRM.TA' ]: stock_data.sector = 'Industrials'
elif stock_data.symbol in ['IGLD-M.TA' ]: stock_data.sector = 'Communication Services'
elif stock_data.symbol in ['UNCT-L.TA', 'ROBO.TA', 'SONO.TA', 'SMAG-L.TA', 'STG.TA',
'BIGT-L.TA', 'BIMT-L.TA', 'BVC.TA', 'ECPA.TA', 'ELLO.TA',
'FLYS.TA', 'FORTY.TA', 'GFC-L.TA', 'IARG-L.TA', 'IBITEC-F.TA',
'MBMX-M.TA', 'MITC.TA', 'SMAG-L.TA','ORBI.TA', 'ARYT.TA',
'ORTC.TA', 'PERI.TA', 'PAYT.TA', 'TUZA.TA', 'ENLT.TA',
'ESLT.TA', 'ORA.TA', 'ENRG.TA', 'RADA.TA', 'DORL.TA',
'AUGN.TA', 'FRSX.TA', 'SLGN.TA', 'AQUA.TA', 'PNRG.TA',
'BMLK.TA', 'MSKE.TA', 'HMGS.TA', 'HICN.TA', 'ARDM.TA',
'ENOG.TA', 'BLND.TA', 'ARTS.TA', 'BNRG.TA', 'MIFT.TA',
'SNFL.TA', 'KVSR.TA', 'SNEL.TA', 'SVRT.TA', 'GIX.TA',
'NXFR.TA', 'FEAT-L.TA' ]: stock_data.sector = 'Technology'
if len(sectors_list) and stock_data.sector not in sectors_list:
return False
return True
def check_country(stock_data, countries_list):
if len(countries_list) and stock_data.country not in countries_list:
return False
return True
def text_to_num(text):
d = {
'K': 1000,
'M': 1000000,
'B': 1000000000,
'T': 1000000000000
}
if not isinstance(text, str):
# Non-strings are bad are missing data in poster's submission
return 0
text = text.replace(' ','')
if text[-1] in d: # separate out the K, M, B or T
num, magnitude = text[:-1], text[-1]
return int(float(num) * d[magnitude])
else:
return float(text)
def weighted_average(values_list, weights):
if VERBOSE_LOGS > 2: print("[{} weighted_average]".format(__name__), end='')
return sum([float(values_list[i])*float(weights[i]) for i in range(len(values_list))])/float(sum(weights))
def set_skip_reason(stock_data):
stock_data.skip_reason = ''
if stock_data.trailing_12months_price_to_sales is None: stock_data.skip_reason += 'trailing_12months_price_to_sales is None|'
elif stock_data.trailing_12months_price_to_sales <= 0: stock_data.skip_reason += 'trailing_12months_price_to_sales <= 0 |'
if stock_data.effective_profit_margin is None: stock_data.skip_reason += 'effective_profit_margin is None|'
elif stock_data.effective_profit_margin <= 0: stock_data.skip_reason += 'effective_profit_margin <= 0 |'
if stock_data.eqg_factor_effective is None: stock_data.skip_reason += 'eqg_factor_effective is None|'
elif stock_data.eqg_factor_effective <= 0: stock_data.skip_reason += 'eqg_factor_effective <= 0 |'
if stock_data.rqg_factor_effective is None: stock_data.skip_reason += 'rqg_factor_effective is None|'
elif stock_data.rqg_factor_effective <= 0: stock_data.skip_reason += 'rqg_factor_effective <= 0 |'
if stock_data.pe_effective is None: stock_data.skip_reason += 'pe_effective is None|'
elif stock_data.pe_effective <= 0: stock_data.skip_reason += 'pe_effective <= 0 |'
if stock_data.effective_ev_to_ebitda is None: stock_data.skip_reason += 'effective_ev_to_ebitda is None|'
elif stock_data.effective_ev_to_ebitda <= 0: stock_data.skip_reason += 'effective_ev_to_ebitda <= 0 |'
if stock_data.ev_to_cfo_ratio_effective is None: stock_data.skip_reason += 'ev_to_cfo_ratio_effective is None|'
elif stock_data.ev_to_cfo_ratio_effective <= 0: stock_data.skip_reason += 'ev_to_cfo_ratio_effective <= 0 |'
if stock_data.effective_peg_ratio is None: stock_data.skip_reason += 'effective_peg_ratio is None|'
elif stock_data.effective_peg_ratio <= 0: stock_data.skip_reason += 'effective_peg_ratio <= 0 |'
if stock_data.price_to_book is None: stock_data.skip_reason += 'price_to_book is None|'
elif stock_data.price_to_book <= 0: stock_data.skip_reason += 'price_to_book <= 0 |'
if stock_data.debt_to_equity_effective_used is None: stock_data.skip_reason += 'debt_to_equity_effective_used is None|'
elif stock_data.debt_to_equity_effective_used <= 0: stock_data.skip_reason += 'debt_to_equity_effective_used <= 0 |'
if stock_data.total_current_ratio_effective is None: stock_data.skip_reason += 'total_current_ratio_effective is None|'
elif stock_data.total_current_ratio_effective <= 0: stock_data.skip_reason += 'total_current_ratio_effective <= 0 |'
if stock_data.evr_effective is None: stock_data.skip_reason += 'evr_effective is None|'
elif stock_data.evr_effective <= 0: stock_data.skip_reason += 'evr_effective <= 0 |'
if stock_data.calculated_roa is None: stock_data.skip_reason += 'calculated_roa is None|'
elif stock_data.calculated_roa <= 0: stock_data.skip_reason += 'calculated_roa <= 0 |'
if stock_data.calculated_roe is None: stock_data.skip_reason += 'calculated_roe is None|'
elif stock_data.calculated_roe <= 0: stock_data.skip_reason += 'calculated_roe <= 0 |'
if stock_data.altman_z_score_factor is None: stock_data.skip_reason += 'altman_z_score_factor is None|'
elif stock_data.altman_z_score_factor <= 0: stock_data.skip_reason += 'altman_z_score_factor <= 0 |'
if stock_data.held_percent_insiders is None: stock_data.skip_reason += 'held_percent_insiders is None|'
elif stock_data.held_percent_insiders <= 0: stock_data.skip_reason += 'held_percent_insiders <= 0 |'
def get_list_of_csv_row_indices_which_affect_core_equation():
return [g_eff_dist_from_low_factor_index, g_held_percent_insiders_index, g_evr_effective_index, g_pe_effective_index, g_effective_ev_to_ebitda_index, g_trailing_12months_price_to_sales_index, g_price_to_book_index, g_effective_profit_margin_index, g_effective_current_ratio_index, g_calculated_roa_index, g_calculated_roe_index, g_effective_peg_ratio_index, g_ev_to_cfo_ratio_effective_index, g_debt_to_equity_effective_used_index, g_eqg_factor_effective_index, g_rqg_factor_effective_index, g_altman_z_score_factor_index]
def sss_core_equation_value_set(stock_data):
if VERBOSE_LOGS > 2: print("[{} sss_core_equation_value_set]".format(__name__), end='')
if stock_data.shares_outstanding and stock_data.net_income_to_common_shareholders != None: stock_data.nitcsh_to_shares_outstanding = float(stock_data.net_income_to_common_shareholders) / float(stock_data.shares_outstanding)
if stock_data.employees and stock_data.net_income_to_common_shareholders != None: stock_data.nitcsh_to_num_employees = float(stock_data.net_income_to_common_shareholders) / float(stock_data.employees)
if sss_config.custom_sss_value_equation and stock_data.trailing_12months_price_to_sales != None and stock_data.trailing_12months_price_to_sales > 0 and stock_data.effective_profit_margin != None and stock_data.effective_profit_margin > 0 and stock_data.pe_effective != None and stock_data.pe_effective > 0 and stock_data.evr_effective != None and stock_data.evr_effective > 0.0:
stock_data.sss_value = float(float(stock_data.evr_effective) * stock_data.pe_effective * stock_data.trailing_12months_price_to_sales / stock_data.effective_profit_margin) # The lower the better
min_sss_value = round(10 ** (-NUM_ROUND_DECIMALS), NUM_ROUND_DECIMALS)
stock_data.sss_value = max(stock_data.sss_value, min_sss_value)
elif stock_data.trailing_12months_price_to_sales != None and stock_data.trailing_12months_price_to_sales > 0 and stock_data.effective_profit_margin != None and stock_data.effective_profit_margin > 0 and stock_data.eqg_factor_effective != None and stock_data.eqg_factor_effective > 0 and stock_data.rqg_factor_effective != None and stock_data.rqg_factor_effective > 0 and stock_data.pe_effective != None and stock_data.pe_effective > 0 and stock_data.effective_ev_to_ebitda != None and stock_data.effective_ev_to_ebitda > 0 and stock_data.ev_to_cfo_ratio_effective != None and stock_data.ev_to_cfo_ratio_effective > 0 and stock_data.effective_peg_ratio != None and stock_data.effective_peg_ratio > 0 and stock_data.price_to_book != None and stock_data.price_to_book > 0 and stock_data.debt_to_equity_effective_used != None and stock_data.debt_to_equity_effective_used > 0 and stock_data.effective_current_ratio != None and stock_data.effective_current_ratio > 0 and stock_data.evr_effective != None and stock_data.evr_effective > 0.0 and stock_data.calculated_roa != None and stock_data.calculated_roa > 0 and stock_data.calculated_roe != None and stock_data.calculated_roe > 0 and stock_data.altman_z_score_factor != None and stock_data.altman_z_score_factor > 0 and stock_data.held_percent_insiders != None and stock_data.held_percent_insiders > 0:
stock_data.sss_value = float((stock_data.eff_dist_from_low_factor/stock_data.held_percent_insiders) * ((float(stock_data.evr_effective) * stock_data.pe_effective * stock_data.effective_ev_to_ebitda * stock_data.trailing_12months_price_to_sales * stock_data.price_to_book) / (stock_data.effective_profit_margin * stock_data.effective_current_ratio * stock_data.calculated_roa * stock_data.calculated_roe)) * ((stock_data.effective_peg_ratio * stock_data.ev_to_cfo_ratio_effective * stock_data.debt_to_equity_effective_used) / (stock_data.eqg_factor_effective * stock_data.rqg_factor_effective * stock_data.altman_z_score_factor))) # The lower the better
min_sss_value = round(10**(-NUM_ROUND_DECIMALS), NUM_ROUND_DECIMALS)
stock_data.sss_value = max(stock_data.sss_value, min_sss_value)
# As of https://github.com/ranaroussi/yfinance/issues/903, peg ratio seems incorrect by yfinance - TODO: ASAFR: follow-up on that
# elif stock_data.trailing_12months_price_to_sales != None and stock_data.trailing_12months_price_to_sales > 0 and stock_data.effective_profit_margin != None and stock_data.effective_profit_margin > 0 and stock_data.eqg_factor_effective != None and stock_data.eqg_factor_effective > 0 and stock_data.rqg_factor_effective != None and stock_data.rqg_factor_effective > 0 and stock_data.pe_effective != None and stock_data.pe_effective > 0 and stock_data.effective_ev_to_ebitda != None and stock_data.effective_ev_to_ebitda > 0 and stock_data.ev_to_cfo_ratio_effective != None and stock_data.ev_to_cfo_ratio_effective > 0 and stock_data.price_to_book != None and stock_data.price_to_book > 0 and stock_data.debt_to_equity_effective_used != None and stock_data.debt_to_equity_effective_used > 0 and stock_data.effective_current_ratio != None and stock_data.effective_current_ratio > 0 and stock_data.evr_effective != None and stock_data.evr_effective > 0.0 and stock_data.calculated_roa != None and stock_data.calculated_roa > 0 and stock_data.calculated_roe != None and stock_data.calculated_roe > 0 and stock_data.altman_z_score_factor != None and stock_data.altman_z_score_factor > 0 and stock_data.held_percent_insiders != None and stock_data.held_percent_insiders > 0:
# stock_data.sss_value = float((stock_data.eff_dist_from_low_factor/stock_data.held_percent_insiders) * ((float(stock_data.evr_effective) * stock_data.pe_effective * stock_data.effective_ev_to_ebitda * stock_data.trailing_12months_price_to_sales * stock_data.price_to_book) / (stock_data.effective_profit_margin * stock_data.effective_current_ratio * stock_data.calculated_roa * stock_data.calculated_roe)) * (( stock_data.ev_to_cfo_ratio_effective * stock_data.debt_to_equity_effective_used) / (stock_data.eqg_factor_effective * stock_data.rqg_factor_effective * stock_data.altman_z_score_factor))) # The lower the better
# min_sss_value = round(10**(-NUM_ROUND_DECIMALS), NUM_ROUND_DECIMALS)
# stock_data.sss_value = max(stock_data.sss_value, min_sss_value)
else:
stock_data.sss_value = BAD_SSS
set_skip_reason(stock_data)
def get_used_parameters_names_in_core_equation(custom_sss_value_equation):
if custom_sss_value_equation:
numerator_parameters_list = ["evr_effective", "pe_effective", "trailing_12months_price_to_sales"] # The lower the better
denominator_parameters_list = ["effective_profit_margin", ] # The higher the better
else:
numerator_parameters_list = ["eff_dist_from_low_factor", "evr_effective", "pe_effective", "effective_ev_to_ebitda", "trailing_12months_price_to_sales", "price_to_book", "effective_peg_ratio", "ev_to_cfo_ratio_effective", "debt_to_equity_effective_used"] # The lower the better
denominator_parameters_list = ["effective_profit_margin", "effective_current_ratio", "calculated_roa", "calculated_roe", "eqg_factor_effective", "rqg_factor_effective", "altman_z_score_factor", "held_percent_insiders" ] # The higher the better
return [numerator_parameters_list, denominator_parameters_list]
# Rounding to non-None values + set None values to 0 for simplicity:
def round_and_avoid_none_values(stock_data):
if stock_data.sss_value != None: stock_data.sss_value = round(stock_data.sss_value, NUM_ROUND_DECIMALS)
if stock_data.annualized_revenue != None: stock_data.annualized_revenue = round(stock_data.annualized_revenue, NUM_ROUND_DECIMALS)
if stock_data.annualized_revenue_bonus != None: stock_data.annualized_revenue_bonus = round(stock_data.annualized_revenue_bonus, NUM_ROUND_DECIMALS)
if stock_data.annualized_earnings != None: stock_data.annualized_earnings = round(stock_data.annualized_earnings, NUM_ROUND_DECIMALS)
if stock_data.annualized_retained_earnings != None: stock_data.annualized_retained_earnings = round(stock_data.annualized_retained_earnings, NUM_ROUND_DECIMALS)
if stock_data.annualized_retained_earnings_bonus != None: stock_data.annualized_retained_earnings_bonus = round(stock_data.annualized_retained_earnings_bonus, NUM_ROUND_DECIMALS)
if stock_data.quarterized_revenue != None: stock_data.quarterized_revenue = round(stock_data.quarterized_revenue, NUM_ROUND_DECIMALS)
if stock_data.quarterized_revenue_bonus != None: stock_data.quarterized_revenue_bonus = round(stock_data.quarterized_revenue_bonus, NUM_ROUND_DECIMALS)
if stock_data.quarterized_earnings != None: stock_data.quarterized_earnings = round(stock_data.quarterized_earnings, NUM_ROUND_DECIMALS)
if stock_data.quarterized_earnings_bonus != None: stock_data.quarterized_earnings_bonus = round(stock_data.quarterized_earnings_bonus, NUM_ROUND_DECIMALS)
if stock_data.quarterized_retained_earnings != None: stock_data.quarterized_retained_earnings = round(stock_data.quarterized_retained_earnings, NUM_ROUND_DECIMALS)
if stock_data.quarterized_retained_earnings_bonus != None: stock_data.quarterized_retained_earnings_bonus = round(stock_data.quarterized_retained_earnings_bonus, NUM_ROUND_DECIMALS)
if stock_data.effective_earnings != None: stock_data.effective_earnings = round(stock_data.effective_earnings, NUM_ROUND_DECIMALS)
if stock_data.effective_retained_earnings != None: stock_data.effective_retained_earnings = round(stock_data.effective_retained_earnings, NUM_ROUND_DECIMALS)
if stock_data.effective_revenue != None: stock_data.effective_revenue = round(stock_data.effective_revenue, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_revenue != None: stock_data.annualized_total_revenue = round(stock_data.annualized_total_revenue, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_revenue_bonus != None: stock_data.annualized_total_revenue_bonus = round(stock_data.annualized_total_revenue_bonus, NUM_ROUND_DECIMALS)
if stock_data.annualized_net_income != None: stock_data.annualized_net_income = round(stock_data.annualized_net_income, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_revenue != None: stock_data.quarterized_total_revenue = round(stock_data.quarterized_total_revenue, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_revenue_bonus != None: stock_data.quarterized_total_revenue_bonus = round(stock_data.quarterized_total_revenue_bonus, NUM_ROUND_DECIMALS)
if stock_data.quarterized_net_income != None: stock_data.quarterized_net_income = round(stock_data.quarterized_net_income, NUM_ROUND_DECIMALS)
if stock_data.quarterized_net_income_bonus != None: stock_data.quarterized_net_income_bonus = round(stock_data.quarterized_net_income_bonus, NUM_ROUND_DECIMALS)
if stock_data.effective_net_income != None: stock_data.effective_net_income = round(stock_data.effective_net_income, NUM_ROUND_DECIMALS)
if stock_data.effective_total_revenue != None: stock_data.effective_total_revenue = round(stock_data.effective_total_revenue, NUM_ROUND_DECIMALS)
if stock_data.enterprise_value_to_revenue != None: stock_data.enterprise_value_to_revenue = round(stock_data.enterprise_value_to_revenue, NUM_ROUND_DECIMALS)
if stock_data.evr_effective != None: stock_data.evr_effective = round(stock_data.evr_effective, NUM_ROUND_DECIMALS)
if stock_data.trailing_price_to_earnings != None: stock_data.trailing_price_to_earnings = round(stock_data.trailing_price_to_earnings, NUM_ROUND_DECIMALS)
if stock_data.forward_price_to_earnings != None: stock_data.forward_price_to_earnings = round(stock_data.forward_price_to_earnings, NUM_ROUND_DECIMALS)
if stock_data.effective_price_to_earnings != None: stock_data.effective_price_to_earnings = round(stock_data.effective_price_to_earnings, NUM_ROUND_DECIMALS)
if stock_data.trailing_12months_price_to_sales != None: stock_data.trailing_12months_price_to_sales = round(stock_data.trailing_12months_price_to_sales, NUM_ROUND_DECIMALS)
if stock_data.pe_effective != None: stock_data.pe_effective = round(stock_data.pe_effective, NUM_ROUND_DECIMALS)
if stock_data.enterprise_value_to_ebitda != None: stock_data.enterprise_value_to_ebitda = round(stock_data.enterprise_value_to_ebitda, NUM_ROUND_DECIMALS)
if stock_data.effective_ev_to_ebitda != None: stock_data.effective_ev_to_ebitda = round(stock_data.effective_ev_to_ebitda, NUM_ROUND_DECIMALS)
if stock_data.ebitda != None: stock_data.ebitda = round(stock_data.ebitda, NUM_ROUND_DECIMALS)
if stock_data.quarterized_ebitd != None: stock_data.quarterized_ebitd = round(stock_data.quarterized_ebitd, NUM_ROUND_DECIMALS)
if stock_data.annualized_ebitd != None: stock_data.annualized_ebitd = round(stock_data.annualized_ebitd, NUM_ROUND_DECIMALS)
if stock_data.ebitd != None: stock_data.ebitd = round(stock_data.ebitd, NUM_ROUND_DECIMALS)
if stock_data.profit_margin != None: stock_data.profit_margin = round(stock_data.profit_margin, NUM_ROUND_DECIMALS)
if stock_data.annualized_profit_margin != None: stock_data.annualized_profit_margin = round(stock_data.annualized_profit_margin, NUM_ROUND_DECIMALS)