forked from asafravid/sss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sss_post_processing.py
66 lines (55 loc) · 3.58 KB
/
sss_post_processing.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
#############################################################################
#
# Version 0.2.10 - 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/>.
#
#############################################################################
import pandas as pd
import sss
import sss_config
import sss_filenames
SSS_VALUE_NORMALIZED_COLUMN_NAME = "sss_value_normalized"
SSS_VALUE_COLUMN_NAME = "sss_value"
def process_engine_csv(path) -> object:
filename_path = path+"/"+sss_filenames.ENGINE_FILENAME
data = pd.read_csv(filename_path+".csv", skiprows=[0]) # 1st row is a description row, irrelevant for the data processing
# max_2_nlargest = data.nlargest(2,numerator_parameters_list+denominator_parameters_list)
[numerator_parameters_list, denominator_parameters_list ] = sss.get_used_parameters_names_in_core_equation(False) # Take all values
[numerator_parameters_list_to_calculate, denominator_parameters_list_to_calculate] = sss.get_used_parameters_names_in_core_equation(sss_config.custom_sss_value_equation) # Take all values for calculation of the sss_value
max_numerator_values = data[numerator_parameters_list].max()
max_denominator_values = data[denominator_parameters_list].max()
# max_numerator_values_to_calculate = data[numerator_parameters_list_to_calculate].max()
# max_denominator_values_to_calculate = data[denominator_parameters_list_to_calculate].max()
for parameter in numerator_parameters_list:
new_column = data[parameter] / max_numerator_values[parameter]
new_column_index = data.columns.get_loc(parameter)
data.insert(new_column_index+1, parameter+"_normalized",new_column)
if SSS_VALUE_NORMALIZED_COLUMN_NAME in data:
if parameter in numerator_parameters_list_to_calculate: # and parameter != "effective_peg_ratio":
data[SSS_VALUE_NORMALIZED_COLUMN_NAME] = data[SSS_VALUE_NORMALIZED_COLUMN_NAME] + data[parameter+"_normalized"]
else:
new_column_index = data.columns.get_loc(SSS_VALUE_COLUMN_NAME)
data.insert(new_column_index + 1, SSS_VALUE_NORMALIZED_COLUMN_NAME, new_column)
for parameter in denominator_parameters_list:
new_column = data[parameter] / max_denominator_values[parameter]
new_column_index = data.columns.get_loc(parameter)
data.insert(new_column_index+1, parameter+"_normalized",new_column)
if parameter in denominator_parameters_list_to_calculate:
data[SSS_VALUE_NORMALIZED_COLUMN_NAME] = data[SSS_VALUE_NORMALIZED_COLUMN_NAME] - data[parameter+"_normalized"]
sorted_Data = data.sort_values(by=[SSS_VALUE_NORMALIZED_COLUMN_NAME])
sorted_Data.to_csv(filename_path+"_normalized.csv", index = False)