@@ -7,31 +7,26 @@ import datetime
77
88import modules .config_details as conf_info
99
10- ratios_dir = 'data/calculated_ratios/'
11-
1210# ----------------
1311# HELPER FUNCTIONS
1412# ----------------
1513
1614def build_outstanding_shares_dict (files_dir ):
17- raymond_database_id = 'RAYMOND'
18- filename_glob = 'outstanding_shares_' + raymond_database_id + '_*.csv'
19- filename_regex = raymond_database_id + '_(.*).csv'
20- outstanding_shares_pattern = re .compile (filename_regex )
15+ outstanding_shares_pattern = re .compile (conf_info .out_shares_filename_regex )
2116 outstanding_shares_dict = {}
2217 for file_name in os .listdir (files_dir ):
23- if fnmatch .fnmatch (file_name , filename_glob ):
18+ if fnmatch .fnmatch (file_name , conf_info . out_shares_filename_glob ):
2419 current_ticker = outstanding_shares_pattern .search (file_name ).group (1 )
25- # print 'Processing file:', file_name
26- # print 'Processing ticker:', current_ticker
20+ print 'Processing file:' , file_name
21+ print 'Processing ticker:' , current_ticker
2722 outstanding_shares_dict [current_ticker ] = pd .read_csv (files_dir + file_name )
2823
2924 return outstanding_shares_dict
3025
3126def build_fundamentals_data_dict (files_dir , tickers ):
3227 fundamentals_dict = {}
3328 for ticker in tickers :
34- fundamentals_ticker_filename_and_path = files_dir + 'fundamentals_' + ticker + '.csv'
29+ fundamentals_ticker_filename_and_path = files_dir + conf_info . get_fundamentals_filename ( ticker )
3530 # print fundamentals_ticker_filename_and_path
3631 fundamentals_dict [ticker ] = pd .read_csv (fundamentals_ticker_filename_and_path )
3732
@@ -66,10 +61,10 @@ def build_eps_dataframe(outstanding_shares_df, fundamentals_df):
6661
6762 return eps_df
6863
69- def build_all_eps_dataframes (files_dir , ratios_dir ):
64+ def build_all_eps_dataframes (files_dir , ratios_storage_dir ):
7065 # making sure the folder exists
71- if not os .path .exists (ratios_dir ):
72- os .makedirs (ratios_dir )
66+ if not os .path .exists (ratios_storage_dir ):
67+ os .makedirs (ratios_storage_dir )
7368 # collecting the data
7469 outstanding_shares_dict = build_outstanding_shares_dict (conf_info .fundamentals_dir )
7570 available_tickers = outstanding_shares_dict .keys ()
@@ -79,7 +74,7 @@ def build_all_eps_dataframes(files_dir, ratios_dir):
7974 print str (datetime .datetime .now ()) + ' Processing ticker:' ,ticker
8075 current_eps_df = build_eps_dataframe (outstanding_shares_dict [ticker ], fundamentals_tickers_dict [ticker ])
8176 # saving the EPS df as CSV file
82- current_filename_with_path = ratios_dir + 'eps_' + ticker . upper () + '.csv'
77+ current_filename_with_path = ratios_storage_dir + conf_info . get_eps_filename ( ticker )
8378 current_eps_df .to_csv (current_filename_with_path , index = False )
8479
8580# ----------
@@ -93,4 +88,4 @@ def build_all_eps_dataframes(files_dir, ratios_dir):
9388# tsla_eps_df = build_eps_dataframe(outstanding_shares_dict['TSLA'], fundamentals_tickers_dict['TSLA'])
9489# print 'TSLA EPS:', tsla_eps_df
9590
96- build_all_eps_dataframes (conf_info .fundamentals_dir , ratios_dir )
91+ build_all_eps_dataframes (conf_info .fundamentals_dir , conf_info . ratios_dir )
0 commit comments