forked from asafravid/sss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsss.py
More file actions
2558 lines (2294 loc) · 310 KB
/
sss.py
File metadata and controls
2558 lines (2294 loc) · 310 KB
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.1.118 - Author: Asaf Ravid <asaf.rvd@gmail.com>
#
# 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. (Highest Priority:) Update yfinance and commit the pull requests from internaly-used/improved yfinance
# 0. Auto-Update Nasdaq (All, NSR) Indices as done with TASE
# 1. Check and multi dim and investigate eqg_min and rqg_min: Check why Yahoo Finance always gives QRG values of 0? Unusable if that is always so
# 2. Implement:
# 2.1. https://en.wikipedia.org/wiki/Piotroski_F-score
# 2.1.1. ROA: https://www.investopedia.com/ask/answers/031215/what-formula-calculating-return-assets-roa.asp
# 2.2. https://en.wikipedia.org/wiki/Magic_formula_investing
# 2.3. https://www.oldschoolvalue.com/investing-strategy/backtest-graham-nnwc-ncav-screen/
# 3. Take latest yfinance base.py (and other - compare the whole folder) and updates - maybe not required - but just stay up to date
# 5. Investigate and add: https://www.investopedia.com/terms/o/operatingmargin.asp - operating margin
# 6. Add Free Cash flow [FCF] (EV/FreeCashFlow): Inverse of the Free Cash Flow Yield (https://www.stockopedia.com/ratios/ev-free-cash-flow-336/#:~:text=What%20is%20the%20definition%20of,the%20Free%20Cash%20Flow%20Yield.)
# 7. 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
# 9. Which are the most effective parameters? Correlate the sorting of sss_value to the results and each of the sorted-by-parameter list.
# 10. Important: https://www.oldschoolvalue.com/investing-strategy/walter-schloss-investing-strategy-producing-towering-returns/#:~:text=Walter%20Schloss%20ran%20with%20the,to%20perform%20complex%20valuations%20either.
# 10.1. 3 years low, 5 years low
# 10.2. F-Score, M-Score, Z-Score
# 10.3. Multi-Dim scan over the distance from low, and over the Schloff Score - define a Walter-Schloss score
# 10.4. Remove the square root from DtoE ?
# 10.5. MktCapM is >= US$ 300 million (basis year 2000) adjusted yearly
# 10.6. Consider only stocks that are listed at least 10 years
# 10.7. Price 1 Day ago within 15% of the 52 week low
# 10.8. Take the top 1000 stocks with highest Number of Insiders owning shares# 11. Calculate share_price/52weekLow 0.1
# 10.9. Take the top 500 stocks with highest Current Dividend Yield %# 12. https://pyportfolioopt.readthedocs.io/en/latest/UserGuide.html -> Use
# 10.10. Take the top 250 stocks with lowest Latest Filing P/E ratio# 13. Calculate the ROE - Return on equity
# 10.11. Take the top 125 stocks with lowest Latest Filing P/B ratio# 14. Operating Cash Flow Growth - interesting: https://github.com/JerBouma/FundamentalAnalysis
# 10.12. Take the top 75 stocks with lowest Latest Filing Long Term Debt# 15. Quick Ratio - https://github.com/JerBouma/FinanceDatabase - interesting
#
# 11. [Building DB: thread_id 0 Sleeping for 0.0 sec] Checking AVCT ( 634/ 648/7231 [Diff: 0]):
# American Virtual Cloud Technolo :
# C:\Users\Administrator\Downloads\sss-master\venv\lib\site-packages\yfinance\base.py:519: UserWarning: DataFrame columns are not unique, some columns will be omitted.
# return data.to_dict()
# C:\Users\Administrator\Downloads\sss-master\venv\lib\site-packages\yfinance\base.py:509: UserWarning: DataFrame columns are not unique, some columns will be omitted.
# return data.to_dict()
# C:\Users\Administrator\Downloads\sss-master\venv\lib\site-packages\yfinance\base.py:502: UserWarning: DataFrame columns are not unique, some columns will be omitted.
# return data.to_dict()
import time
import random
import pandas as pd
import yfinance as yf
import csv
import os
import sss_filenames
import sss_indices
import sss_post_processing
import math
import json
from threading import Thread
from dataclasses import dataclass
# from forex_python.converter import CurrencyRates
# from currency_converter import CurrencyConverter
VERBOSE_LOGS = 0
SKIP_5LETTER_Y_STOCK_LISTINGS = False # Skip ADRs - American Depositary receipts (5 Letter Stocks)
NUM_ROUND_DECIMALS = 6
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
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
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.1 # the provided RQG (Actually Yahoo never provides it) is weighted less 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.01 # 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.02 # When the ROA is very low (units are ratio here), this damper shall limit the affect to x50 not more)
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)
# 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_CONTINUOUS_ANNUAL_INCREASE = 2.25 # Provide a "bonus" for companies whose profit margins have increased continuously annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE = 1.75 # Provide a "bonus" for companies whose profit margins have increased continuously quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_POSITIVE = 2.5 # Provide a "bonus" for companies whose profit margins have been continuously positive annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_POSITIVE = 2.5 # Provide a "bonus" for companies whose profit margins have been continuously positive quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_INCREASE_IN_EARNINGS = 2.75 # Provide a "bonus" for companies whose earnings have been continuously increasing annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_ANNUAL_INCREASE_IN_REVENUE = 2.25 # Provide a "bonus" for companies whose revenue has been continuously increasing annually
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE_IN_EARNINGS = 2.75 # Provide a "bonus" for companies whose earnings have been continuously increasing quarterly
PROFIT_MARGIN_BOOST_FOR_CONTINUOUS_QUARTERLY_INCREASE_IN_REVENUE = 2.5 # Provide a "bonus" for companies whose revenue has been continuously increasing quarterly
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 = 10000.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 = 10000.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)
@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
annualized_revenue: float = 0.0
annualized_earnings: float = 0.0
annualized_retained_earnings: float = 0.0
quarterized_revenue: float = 0.0
quarterized_earnings: float = 0.0
quarterized_retained_earnings: 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_net_income: float = 0.0
quarterized_total_revenue: float = 0.0
quarterized_net_income: 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
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
quarterized_cash_flow_from_operating_activities: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
quarterized_debt_to_equity: 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
quarterized_total_ratio: float = 0.0
annualized_other_current_ratio: float = 0.0
quarterized_other_current_ratio: float = 0.0
annualized_other_ratio: float = 0.0
quarterized_other_ratio: float = 0.0
annualized_total_current_ratio: float = 0.0
quarterized_total_current_ratio: 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
quarterized_total_assets: float = 0.0
effective_total_assets: float = 0.0
calculated_roa: 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
quarterized_total_liabilities: 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
annualized_revenue: float = 0.0
annualized_earnings: float = 0.0
annualized_retained_earnings: float = 0.0
quarterized_revenue: float = 0.0
quarterized_earnings: float = 0.0
quarterized_retained_earnings: 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_net_income: float = 0.0
quarterized_total_revenue: float = 0.0
quarterized_net_income: 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
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
quarterized_cash_flow_from_operating_activities: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
quarterized_debt_to_equity: 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
quarterized_total_ratio: float = 0.0
annualized_other_current_ratio: float = 0.0
quarterized_other_current_ratio: float = 0.0
annualized_other_ratio: float = 0.0
quarterized_other_ratio: float = 0.0
annualized_total_current_ratio: float = 0.0
quarterized_total_current_ratio: 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
quarterized_total_assets: float = 0.0
effective_total_assets: float = 0.0
calculated_roa: float = 0.0
calculated_roa_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
quarterized_total_liabilities: 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_header_row = ["Symbol", "Name", "Sector", "Country", "sss_value", "annualized_revenue", "annualized_earnings", "annualized_retained_earnings", "quarterized_revenue", "quarterized_earnings", "quarterized_retained_earnings", "effective_earnings", "effective_retained_earnings", "effective_revenue", "annualized_total_revenue", "annualized_net_income", "quarterized_total_revenue", "quarterized_net_income", "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", "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", "quarterized_cash_flow_from_operating_activities", "annualized_ev_to_cfo_ratio", "quarterized_ev_to_cfo_ratio", "ev_to_cfo_ratio_effective", "annualized_debt_to_equity", "quarterized_debt_to_equity", "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", "quarterized_total_ratio", "annualized_other_current_ratio", "quarterized_other_current_ratio", "annualized_other_ratio", "quarterized_other_ratio", "annualized_total_current_ratio", "quarterized_total_current_ratio", "total_ratio_effective", "other_current_ratio_effective", "other_ratio_effective", "total_current_ratio_effective", "effective_current_ratio", "annualized_total_assets", "quarterized_total_assets", "effective_total_assets", "calculated_roa", "annualized_working_capital", "quarterized_working_capital", "effective_working_capital", "annualized_total_liabilities", "quarterized_total_liabilities", "effective_total_liabilities", "altman_z_score_factor", "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_annualized_revenue_index = g_header_row.index("annualized_revenue")
g_annualized_earnings_index = g_header_row.index("annualized_earnings")
g_annualized_retained_earnings_index = g_header_row.index("annualized_retained_earnings")
g_quarterized_revenue_index = g_header_row.index("quarterized_revenue")
g_quarterized_earnings_index = g_header_row.index("quarterized_earnings")
g_quarterized_retained_earnings_index = g_header_row.index("quarterized_retained_earnings")
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_net_income_index = g_header_row.index("annualized_net_income")
g_quarterized_total_revenue_index = g_header_row.index("quarterized_total_revenue")
g_quarterized_net_income_index = g_header_row.index("quarterized_net_income")
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_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_quarterized_cash_flow_from_operating_activities_index = g_header_row.index("quarterized_cash_flow_from_operating_activities")
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_quarterized_debt_to_equity_index = g_header_row.index("quarterized_debt_to_equity")
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_quarterized_total_ratio_index = g_header_row.index("quarterized_total_ratio")
g_annualized_other_current_ratio_index = g_header_row.index("annualized_other_current_ratio")
g_quarterized_other_current_ratio_index = g_header_row.index("quarterized_other_current_ratio")
g_annualized_other_ratio_index = g_header_row.index("annualized_other_ratio")
g_quarterized_other_ratio_index = g_header_row.index("quarterized_other_ratio")
g_annualized_total_current_ratio_index = g_header_row.index("annualized_total_current_ratio")
g_quarterized_total_current_ratio_index = g_header_row.index("quarterized_total_current_ratio")
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_quarterized_total_assets_index = g_header_row.index("quarterized_total_assets")
g_effective_total_assets_index = g_header_row.index("effective_total_assets")
g_calculated_roa_index = g_header_row.index("calculated_roa")
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_quarterized_total_liabilities_index = g_header_row.index("quarterized_total_liabilities")
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_header_row_normalized = ["Symbol", "Name", "Sector", "Country", "sss_value", "sss_value_normalized", "annualized_revenue", "annualized_earnings", "annualized_retained_earnings", "quarterized_revenue", "quarterized_earnings", "quarterized_retained_earnings", "effective_earnings", "effective_retained_earnings", "effective_revenue", "annualized_total_revenue", "annualized_net_income", "quarterized_total_revenue", "quarterized_net_income", "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", "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", "quarterized_cash_flow_from_operating_activities", "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", "quarterized_debt_to_equity", "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", "quarterized_total_ratio", "annualized_other_current_ratio", "quarterized_other_current_ratio", "annualized_other_ratio", "quarterized_other_ratio", "annualized_total_current_ratio", "quarterized_total_current_ratio", "total_ratio_effective", "other_current_ratio_effective", "other_ratio_effective", "total_current_ratio_effective", "effective_current_ratio", "effective_current_ratio_normalized", "annualized_total_assets", "quarterized_total_assets", "effective_total_assets", "calculated_roa", "calculated_roa_normalized", "annualized_working_capital", "quarterized_working_capital", "effective_working_capital", "annualized_total_liabilities", "quarterized_total_liabilities", "effective_total_liabilities", "altman_z_score_factor", "altman_z_score_factor_normalized", "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_annualized_revenue_index_n = g_header_row_normalized.index("annualized_revenue")
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_quarterized_revenue_index_n = g_header_row_normalized.index("quarterized_revenue")
g_quarterized_earnings_index_n = g_header_row_normalized.index("quarterized_earnings")
g_quarterized_retained_earnings_index_n = g_header_row_normalized.index("quarterized_retained_earnings")
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_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_net_income_index_n = g_header_row_normalized.index("quarterized_net_income")
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_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_quarterized_cash_flow_from_operating_activities_index_n = g_header_row_normalized.index("quarterized_cash_flow_from_operating_activities")
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_quarterized_debt_to_equity_index_n = g_header_row_normalized.index("quarterized_debt_to_equity")
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_quarterized_total_ratio_index_n = g_header_row_normalized.index("quarterized_total_ratio")
g_annualized_other_current_ratio_index_n = g_header_row_normalized.index("annualized_other_current_ratio")
g_quarterized_other_current_ratio_index_n = g_header_row_normalized.index("quarterized_other_current_ratio")
g_annualized_other_ratio_index_n = g_header_row_normalized.index("annualized_other_ratio")
g_quarterized_other_ratio_index_n = g_header_row_normalized.index("quarterized_other_ratio")
g_annualized_total_current_ratio_index_n = g_header_row_normalized.index("annualized_total_current_ratio")
g_quarterized_total_current_ratio_index_n = g_header_row_normalized.index("quarterized_total_current_ratio")
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_quarterized_total_assets_index_n = g_header_row_normalized.index("quarterized_total_assets")
g_effective_total_assets_index_n = g_header_row_normalized.index("effective_total_assets")
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_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_quarterized_total_liabilities_index_n = g_header_row_normalized.index("quarterized_total_liabilities")
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: print("[{} weighted_average]".format(__name__))
return sum([values_list[i]*weights[i] for i in range(len(values_list))])/sum(weights)
def sss_core_equation_value_set(stock_data):
if VERBOSE_LOGS: print("[{} sss_core_equation_value_set]".format(__name__))
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 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 and stock_data.eqg_factor_effective > 0 != None and stock_data.rqg_factor_effective and stock_data.rqg_factor_effective > 0 != None 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 > 0 and stock_data.total_ratio_effective > 0 and stock_data.total_current_ratio_effective > 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.altman_z_score_factor != None and stock_data.altman_z_score_factor > 0:
stock_data.sss_value = float(stock_data.eff_dist_from_low_factor * ((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.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
else:
stock_data.sss_value = BAD_SSS
def get_used_parameters_names_in_core_equation():
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", "eqg_factor_effective", "rqg_factor_effective", "altman_z_score_factor" ] # 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_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.quarterized_revenue != None: stock_data.quarterized_revenue = round(stock_data.quarterized_revenue, 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_retained_earnings != None: stock_data.quarterized_retained_earnings = round(stock_data.quarterized_retained_earnings, 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_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_net_income != None: stock_data.quarterized_net_income = round(stock_data.quarterized_net_income, 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)
if stock_data.annualized_profit_margin_boost != None: stock_data.annualized_profit_margin_boost = round(stock_data.annualized_profit_margin_boost, NUM_ROUND_DECIMALS)
if stock_data.quarterized_profit_margin != None: stock_data.quarterized_profit_margin = round(stock_data.quarterized_profit_margin, NUM_ROUND_DECIMALS)
if stock_data.quarterized_profit_margin_boost != None: stock_data.quarterized_profit_margin_boost = round(stock_data.quarterized_profit_margin_boost, NUM_ROUND_DECIMALS)
if stock_data.effective_profit_margin != None: stock_data.effective_profit_margin = round(stock_data.effective_profit_margin, NUM_ROUND_DECIMALS)
if stock_data.held_percent_institutions != None: stock_data.held_percent_institutions = round(stock_data.held_percent_institutions, NUM_ROUND_DECIMALS)
if stock_data.forward_eps != None: stock_data.forward_eps = round(stock_data.forward_eps, NUM_ROUND_DECIMALS)
if stock_data.trailing_eps != None: stock_data.trailing_eps = round(stock_data.trailing_eps, NUM_ROUND_DECIMALS)
if stock_data.previous_close != None: stock_data.previous_close = round(stock_data.previous_close, NUM_ROUND_DECIMALS)
if stock_data.trailing_eps_percentage != None: stock_data.trailing_eps_percentage = round(stock_data.trailing_eps_percentage, NUM_ROUND_DECIMALS)
if stock_data.price_to_book != None: stock_data.price_to_book = round(stock_data.price_to_book, NUM_ROUND_DECIMALS)
if stock_data.shares_outstanding != None: stock_data.shares_outstanding = round(stock_data.shares_outstanding, NUM_ROUND_DECIMALS)
if stock_data.net_income_to_common_shareholders != None: stock_data.net_income_to_common_shareholders = round(stock_data.net_income_to_common_shareholders, NUM_ROUND_DECIMALS)
if stock_data.nitcsh_to_shares_outstanding != None: stock_data.nitcsh_to_shares_outstanding = round(stock_data.nitcsh_to_shares_outstanding, NUM_ROUND_DECIMALS)
if stock_data.employees != None: stock_data.employees = int( stock_data.employees )
if stock_data.enterprise_value != None: stock_data.enterprise_value = int( stock_data.enterprise_value )
if stock_data.market_cap != None: stock_data.market_cap = int( stock_data.market_cap )
if stock_data.nitcsh_to_num_employees != None: stock_data.nitcsh_to_num_employees = round(stock_data.nitcsh_to_num_employees, NUM_ROUND_DECIMALS)
if stock_data.eqg != None: stock_data.eqg = round(stock_data.eqg, NUM_ROUND_DECIMALS)
if stock_data.rqg != None: stock_data.rqg = round(stock_data.rqg, NUM_ROUND_DECIMALS)
if stock_data.eqg_yoy != None: stock_data.eqg_yoy = round(stock_data.eqg_yoy, NUM_ROUND_DECIMALS)
if stock_data.rqg_yoy != None: stock_data.rqg_yoy = round(stock_data.rqg_yoy, NUM_ROUND_DECIMALS)
if stock_data.niqg_yoy != None: stock_data.niqg_yoy = round(stock_data.niqg_yoy, NUM_ROUND_DECIMALS)
if stock_data.trqg_yoy != None: stock_data.trqg_yoy = round(stock_data.trqg_yoy, NUM_ROUND_DECIMALS)
if stock_data.eqg_effective != None: stock_data.eqg_effective = round(stock_data.eqg_effective, NUM_ROUND_DECIMALS)
if stock_data.eqg_factor_effective != None: stock_data.eqg_factor_effective = round(stock_data.eqg_factor_effective, NUM_ROUND_DECIMALS)
if stock_data.rqg_effective != None: stock_data.rqg_effective = round(stock_data.rqg_effective, NUM_ROUND_DECIMALS)
if stock_data.rqg_factor_effective != None: stock_data.rqg_factor_effective = round(stock_data.rqg_factor_effective, NUM_ROUND_DECIMALS)
if stock_data.price_to_earnings_to_growth_ratio != None: stock_data.price_to_earnings_to_growth_ratio = round(stock_data.price_to_earnings_to_growth_ratio, NUM_ROUND_DECIMALS)
if stock_data.effective_peg_ratio != None: stock_data.effective_peg_ratio = round(stock_data.effective_peg_ratio, NUM_ROUND_DECIMALS)
if stock_data.annualized_cash_flow_from_operating_activities != None: stock_data.annualized_cash_flow_from_operating_activities = round(stock_data.annualized_cash_flow_from_operating_activities, NUM_ROUND_DECIMALS)
if stock_data.quarterized_cash_flow_from_operating_activities != None: stock_data.quarterized_cash_flow_from_operating_activities = round(stock_data.quarterized_cash_flow_from_operating_activities, NUM_ROUND_DECIMALS)
if stock_data.annualized_ev_to_cfo_ratio != None: stock_data.annualized_ev_to_cfo_ratio = round(stock_data.annualized_ev_to_cfo_ratio, NUM_ROUND_DECIMALS)
if stock_data.quarterized_ev_to_cfo_ratio != None: stock_data.quarterized_ev_to_cfo_ratio = round(stock_data.quarterized_ev_to_cfo_ratio, NUM_ROUND_DECIMALS)
if stock_data.ev_to_cfo_ratio_effective != None: stock_data.ev_to_cfo_ratio_effective = round(stock_data.ev_to_cfo_ratio_effective, NUM_ROUND_DECIMALS)
if stock_data.annualized_debt_to_equity != None: stock_data.annualized_debt_to_equity = round(stock_data.annualized_debt_to_equity, NUM_ROUND_DECIMALS)
if stock_data.quarterized_debt_to_equity != None: stock_data.quarterized_debt_to_equity = round(stock_data.quarterized_debt_to_equity, NUM_ROUND_DECIMALS)
if stock_data.debt_to_equity_effective != None: stock_data.debt_to_equity_effective = round(stock_data.debt_to_equity_effective, NUM_ROUND_DECIMALS)
if stock_data.debt_to_equity_effective_used != None: stock_data.debt_to_equity_effective_used = round(stock_data.debt_to_equity_effective_used, NUM_ROUND_DECIMALS)
if stock_data.financial_currency_conversion_rate_mult_to_usd != None: stock_data.financial_currency_conversion_rate_mult_to_usd = round(stock_data.financial_currency_conversion_rate_mult_to_usd, NUM_ROUND_DECIMALS)
if stock_data.summary_currency_conversion_rate_mult_to_usd != None: stock_data.summary_currency_conversion_rate_mult_to_usd = round(stock_data.summary_currency_conversion_rate_mult_to_usd, NUM_ROUND_DECIMALS)
if stock_data.last_dividend_0 != None: stock_data.last_dividend_0 = round(stock_data.last_dividend_0, NUM_ROUND_DECIMALS)
if stock_data.last_dividend_1 != None: stock_data.last_dividend_1 = round(stock_data.last_dividend_1, NUM_ROUND_DECIMALS)
if stock_data.last_dividend_2 != None: stock_data.last_dividend_2 = round(stock_data.last_dividend_2, NUM_ROUND_DECIMALS)
if stock_data.last_dividend_3 != None: stock_data.last_dividend_3 = round(stock_data.last_dividend_3, NUM_ROUND_DECIMALS)
if stock_data.fifty_two_week_change != None: stock_data.fifty_two_week_change = round(stock_data.fifty_two_week_change, NUM_ROUND_DECIMALS)
if stock_data.fifty_two_week_low != None: stock_data.fifty_two_week_low = round(stock_data.fifty_two_week_low, NUM_ROUND_DECIMALS)
if stock_data.fifty_two_week_high != None: stock_data.fifty_two_week_high = round(stock_data.fifty_two_week_high, NUM_ROUND_DECIMALS)
if stock_data.two_hundred_day_average != None: stock_data.two_hundred_day_average = round(stock_data.two_hundred_day_average, NUM_ROUND_DECIMALS)
if stock_data.previous_close_percentage_from_200d_ma != None: stock_data.previous_close_percentage_from_200d_ma = round(stock_data.previous_close_percentage_from_200d_ma, NUM_ROUND_DECIMALS)
if stock_data.previous_close_percentage_from_52w_low != None: stock_data.previous_close_percentage_from_52w_low = round(stock_data.previous_close_percentage_from_52w_low, NUM_ROUND_DECIMALS)
if stock_data.previous_close_percentage_from_52w_high != None: stock_data.previous_close_percentage_from_52w_high = round(stock_data.previous_close_percentage_from_52w_high, NUM_ROUND_DECIMALS)
if stock_data.dist_from_low_factor != None: stock_data.dist_from_low_factor = round(stock_data.dist_from_low_factor, NUM_ROUND_DECIMALS)
if stock_data.eff_dist_from_low_factor != None: stock_data.eff_dist_from_low_factor = round(stock_data.eff_dist_from_low_factor, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_ratio != None: stock_data.annualized_total_ratio = round(stock_data.annualized_total_ratio, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_ratio != None: stock_data.quarterized_total_ratio = round(stock_data.quarterized_total_ratio, NUM_ROUND_DECIMALS)
if stock_data.annualized_other_current_ratio != None: stock_data.annualized_other_current_ratio = round(stock_data.annualized_other_current_ratio, NUM_ROUND_DECIMALS)
if stock_data.quarterized_other_current_ratio != None: stock_data.quarterized_other_current_ratio = round(stock_data.quarterized_other_current_ratio, NUM_ROUND_DECIMALS)
if stock_data.annualized_other_ratio != None: stock_data.annualized_other_ratio = round(stock_data.annualized_other_ratio, NUM_ROUND_DECIMALS)
if stock_data.quarterized_other_ratio != None: stock_data.quarterized_other_ratio = round(stock_data.quarterized_other_ratio, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_current_ratio != None: stock_data.annualized_total_current_ratio = round(stock_data.annualized_total_current_ratio, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_current_ratio != None: stock_data.quarterized_total_current_ratio = round(stock_data.quarterized_total_current_ratio, NUM_ROUND_DECIMALS)
if stock_data.total_ratio_effective != None: stock_data.total_ratio_effective = round(stock_data.total_ratio_effective, NUM_ROUND_DECIMALS)
if stock_data.other_current_ratio_effective != None: stock_data.other_current_ratio_effective = round(stock_data.other_current_ratio_effective, NUM_ROUND_DECIMALS)
if stock_data.other_ratio_effective != None: stock_data.other_ratio_effective = round(stock_data.other_ratio_effective, NUM_ROUND_DECIMALS)
if stock_data.total_current_ratio_effective != None: stock_data.total_current_ratio_effective = round(stock_data.total_current_ratio_effective, NUM_ROUND_DECIMALS)
if stock_data.effective_current_ratio != None: stock_data.effective_current_ratio = round(stock_data.effective_current_ratio, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_assets != None: stock_data.annualized_total_assets = round(stock_data.annualized_total_assets, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_assets != None: stock_data.quarterized_total_assets = round(stock_data.quarterized_total_assets, NUM_ROUND_DECIMALS)
if stock_data.effective_total_assets != None: stock_data.effective_total_assets = round(stock_data.effective_total_assets, NUM_ROUND_DECIMALS)
if stock_data.calculated_roa != None: stock_data.calculated_roa = round(stock_data.calculated_roa, NUM_ROUND_DECIMALS)
if stock_data.annualized_working_capital != None: stock_data.annualized_working_capital = round(stock_data.annualized_working_capital, NUM_ROUND_DECIMALS)
if stock_data.quarterized_working_capital != None: stock_data.quarterized_working_capital = round(stock_data.quarterized_working_capital, NUM_ROUND_DECIMALS)
if stock_data.effective_working_capital != None: stock_data.effective_working_capital = round(stock_data.effective_working_capital, NUM_ROUND_DECIMALS)
if stock_data.annualized_total_liabilities != None: stock_data.annualized_total_liabilities = round(stock_data.annualized_total_liabilities, NUM_ROUND_DECIMALS)
if stock_data.quarterized_total_liabilities != None: stock_data.quarterized_total_liabilities = round(stock_data.quarterized_total_liabilities, NUM_ROUND_DECIMALS)
if stock_data.effective_total_liabilities != None: stock_data.effective_total_liabilities = round(stock_data.effective_total_liabilities, NUM_ROUND_DECIMALS)
if stock_data.altman_z_score_factor != None: stock_data.altman_z_score_factor = round(stock_data.altman_z_score_factor, NUM_ROUND_DECIMALS)
# TODO: ASAFR: Unify below with above to single line for each parameter
if stock_data.sss_value is None: stock_data.sss_value = BAD_SSS
if stock_data.annualized_revenue is None: stock_data.annualized_revenue = 0
if stock_data.annualized_earnings is None: stock_data.annualized_earnings = 0
if stock_data.annualized_retained_earnings is None: stock_data.annualized_retained_earnings = 0
if stock_data.quarterized_revenue is None: stock_data.quarterized_revenue = 0
if stock_data.quarterized_earnings is None: stock_data.quarterized_earnings = 0
if stock_data.quarterized_retained_earnings is None: stock_data.quarterized_retained_earnings = 0
if stock_data.effective_earnings is None: stock_data.effective_earnings = 0
if stock_data.effective_retained_earnings is None: stock_data.effective_retained_earnings = 0
if stock_data.effective_revenue is None: stock_data.effective_revenue = 0
if stock_data.annualized_total_revenue is None: stock_data.annualized_total_revenue = 0
if stock_data.annualized_net_income is None: stock_data.annualized_net_income = 0
if stock_data.quarterized_total_revenue is None: stock_data.quarterized_total_revenue = 0
if stock_data.quarterized_net_income is None: stock_data.quarterized_net_income = 0
if stock_data.effective_net_income is None: stock_data.effective_net_income = 0
if stock_data.effective_total_revenue is None: stock_data.effective_total_revenue = 0
if stock_data.enterprise_value_to_revenue is None: stock_data.enterprise_value_to_revenue = 0
if stock_data.evr_effective is None: stock_data.evr_effective = 0
if stock_data.trailing_price_to_earnings is None: stock_data.trailing_price_to_earnings = 0
if stock_data.forward_price_to_earnings is None: stock_data.forward_price_to_earnings = 0
if stock_data.effective_price_to_earnings is None: stock_data.effective_price_to_earnings = 0
if stock_data.trailing_12months_price_to_sales is None: stock_data.trailing_12months_price_to_sales = 0
if stock_data.pe_effective is None: stock_data.pe_effective = 0
if stock_data.enterprise_value_to_ebitda is None: stock_data.enterprise_value_to_ebitda = 0
if stock_data.effective_ev_to_ebitda is None: stock_data.effective_ev_to_ebitda = 0
if stock_data.ebitda is None: stock_data.ebitda = 0
if stock_data.quarterized_ebitd is None: stock_data.quarterized_ebitd = 0
if stock_data.annualized_ebitd is None: stock_data.annualized_ebitd = 0
if stock_data.ebitd is None: stock_data.ebitd = 0
if stock_data.profit_margin is None: stock_data.profit_margin = 0
if stock_data.annualized_profit_margin is None: stock_data.annualized_profit_margin = 0
if stock_data.annualized_profit_margin_boost is None: stock_data.annualized_profit_margin_boost = 0
if stock_data.quarterized_profit_margin is None: stock_data.quarterized_profit_margin = 0
if stock_data.quarterized_profit_margin_boost is None: stock_data.quarterized_profit_margin_boost = 0
if stock_data.effective_profit_margin is None: stock_data.effective_profit_margin = 0
if stock_data.held_percent_institutions is None: stock_data.held_percent_institutions = 0
if stock_data.forward_eps is None: stock_data.forward_eps = 0
if stock_data.trailing_eps is None: stock_data.trailing_eps = 0
if stock_data.previous_close is None: stock_data.previous_close = 0
if stock_data.trailing_eps_percentage is None: stock_data.trailing_eps_percentage = 0
if stock_data.price_to_book is None: stock_data.price_to_book = 0
if stock_data.shares_outstanding is None: stock_data.shares_outstanding = 0
if stock_data.net_income_to_common_shareholders is None: stock_data.net_income_to_common_shareholders = 0
if stock_data.nitcsh_to_shares_outstanding is None: stock_data.nitcsh_to_shares_outstanding = 0
if stock_data.employees is None: stock_data.employees = 0
if stock_data.enterprise_value is None: stock_data.enterprise_value = 0
if stock_data.market_cap is None: stock_data.market_cap = 0
if stock_data.nitcsh_to_num_employees is None: stock_data.nitcsh_to_num_employees = 0
if stock_data.eqg is None: stock_data.eqg = 0
if stock_data.rqg is None: stock_data.rqg = 0
if stock_data.eqg_yoy is None: stock_data.eqg_yoy = 0
if stock_data.rqg_yoy is None: stock_data.rqg_yoy = 0
if stock_data.niqg_yoy is None: stock_data.niqg_yoy = 0
if stock_data.trqg_yoy is None: stock_data.trqg_yoy = 0
if stock_data.eqg_effective is None: stock_data.eqg_effective = 0
if stock_data.eqg_factor_effective is None: stock_data.eqg_factor_effective = 0
if stock_data.rqg_effective is None: stock_data.rqg_effective = 0
if stock_data.rqg_factor_effective is None: stock_data.rqg_factor_effective = 0
if stock_data.price_to_earnings_to_growth_ratio is None: stock_data.price_to_earnings_to_growth_ratio = 0
if stock_data.effective_peg_ratio is None: stock_data.effective_peg_ratio = 0
if stock_data.annualized_cash_flow_from_operating_activities is None: stock_data.annualized_cash_flow_from_operating_activities = 0
if stock_data.quarterized_cash_flow_from_operating_activities is None: stock_data.quarterized_cash_flow_from_operating_activities = 0
if stock_data.annualized_ev_to_cfo_ratio is None: stock_data.annualized_ev_to_cfo_ratio = 0
if stock_data.quarterized_ev_to_cfo_ratio is None: stock_data.quarterized_ev_to_cfo_ratio = 0
if stock_data.ev_to_cfo_ratio_effective is None: stock_data.ev_to_cfo_ratio_effective = 0
if stock_data.annualized_debt_to_equity is None: stock_data.annualized_debt_to_equity = 0
if stock_data.quarterized_debt_to_equity is None: stock_data.quarterized_debt_to_equity = 0
if stock_data.debt_to_equity_effective is None: stock_data.debt_to_equity_effective = 0
if stock_data.debt_to_equity_effective_used is None: stock_data.debt_to_equity_effective_used = 0
if stock_data.financial_currency_conversion_rate_mult_to_usd is None: stock_data.financial_currency_conversion_rate_mult_to_usd = 0
if stock_data.summary_currency_conversion_rate_mult_to_usd is None: stock_data.summary_currency_conversion_rate_mult_to_usd = 0
if stock_data.last_dividend_0 is None: stock_data.last_dividend_0 = 0
if stock_data.last_dividend_1 is None: stock_data.last_dividend_1 = 0
if stock_data.last_dividend_2 is None: stock_data.last_dividend_2 = 0
if stock_data.last_dividend_3 is None: stock_data.last_dividend_3 = 0
if stock_data.fifty_two_week_change is None: stock_data.fifty_two_week_change = 0
if stock_data.fifty_two_week_low is None: stock_data.fifty_two_week_low = 0
if stock_data.fifty_two_week_high is None: stock_data.fifty_two_week_high = 0
if stock_data.two_hundred_day_average is None: stock_data.two_hundred_day_average = 0
if stock_data.previous_close_percentage_from_200d_ma is None: stock_data.previous_close_percentage_from_200d_ma = 0
if stock_data.previous_close_percentage_from_52w_low is None: stock_data.previous_close_percentage_from_52w_low = 0
if stock_data.previous_close_percentage_from_52w_high is None: stock_data.previous_close_percentage_from_52w_high = 0
if stock_data.dist_from_low_factor is None: stock_data.dist_from_low_factor = 0
if stock_data.eff_dist_from_low_factor is None: stock_data.eff_dist_from_low_factor = 0
if stock_data.annualized_total_ratio is None: stock_data.annualized_total_ratio = 0
if stock_data.quarterized_total_ratio is None: stock_data.quarterized_total_ratio = 0
if stock_data.annualized_other_current_ratio is None: stock_data.annualized_other_current_ratio = 0
if stock_data.quarterized_other_current_ratio is None: stock_data.quarterized_other_current_ratio = 0
if stock_data.annualized_other_ratio is None: stock_data.annualized_other_ratio = 0
if stock_data.quarterized_other_ratio is None: stock_data.quarterized_other_ratio = 0
if stock_data.annualized_total_current_ratio is None: stock_data.annualized_total_current_ratio = 0
if stock_data.quarterized_total_current_ratio is None: stock_data.quarterized_total_current_ratio = 0
if stock_data.total_ratio_effective is None: stock_data.total_ratio_effective = 0
if stock_data.other_current_ratio_effective is None: stock_data.other_current_ratio_effective = 0
if stock_data.other_ratio_effective is None: stock_data.other_ratio_effective = 0
if stock_data.total_current_ratio_effective is None: stock_data.total_current_ratio_effective = 0
if stock_data.effective_current_ratio is None: stock_data.effective_current_ratio = 0
if stock_data.annualized_total_assets is None: stock_data.annualized_total_assets = 0
if stock_data.quarterized_total_assets is None: stock_data.quarterized_total_assets = 0
if stock_data.effective_total_assets is None: stock_data.effective_total_assets = 0
if stock_data.calculated_roa is None: stock_data.calculated_roa = 0
if stock_data.annualized_working_capital is None: stock_data.annualized_working_capital = 0
if stock_data.quarterized_working_capital is None: stock_data.quarterized_working_capital = 0
if stock_data.effective_working_capital is None: stock_data.effective_working_capital = 0
if stock_data.annualized_total_liabilities is None: stock_data.annualized_total_liabilities = 0
if stock_data.quarterized_total_liabilities is None: stock_data.quarterized_total_liabilities = 0
if stock_data.effective_total_liabilities is None: stock_data.effective_total_liabilities = 0
if stock_data.altman_z_score_factor is None: stock_data.altman_z_score_factor = 0
def calculate_weighted_stock_data_on_dict(dict_input, dict_name, str_in_dict, weights, stock_data, reverse_required, force_only_sum=False):
if VERBOSE_LOGS: print("[{} calculate_weighted_stock_data_on_dict]".format(__name__))
weight_index = 0
weighted_list = []
weights_sum = 0
try:
if str_in_dict is None:
for key in (reversed(list(dict_input)) if reverse_required else list(dict_input)):
weighted_list.append((float(dict_input[key])) * weights[weight_index])
weights_sum += weights[weight_index]
weight_index += 1
else:
for key in (reversed(list(dict_input)) if reverse_required else list(dict_input)): # The 1st element will be the oldest, receiving the lowest weight
if str_in_dict in dict_input[key] and not math.isnan(dict_input[key][str_in_dict]):
weighted_list.append(dict_input[key][str_in_dict] * weights[weight_index])
weights_sum += weights[weight_index]
weight_index += 1
if weights_sum > 0:
return_value = stock_data.financial_currency_conversion_rate_mult_to_usd * sum(weighted_list) / (1 if force_only_sum else weights_sum) # Multiplying by the factor to get the valu in USD.
else:
return_value = None
except Exception as e:
print("Exception in {} {}}: {}".format(stock_data.symbol, dict_name, e))
return_value = None
pass
return return_value
def calculate_weighted_ratio_from_dict(dict_input, dict_name, str_in_dict_numerator, str_in_dict_denominator, weights, stock_data, default_return_value, reverse_required):
if VERBOSE_LOGS: print("[{} calculate_weighted_ratio_from_dict]".format(__name__))
return_value = default_return_value
weighted_ratios_list = []
try: