Skip to content

Commit f818517

Browse files
committed
WIP Calculation of EPS
1 parent fc155ef commit f818517

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

030_ratios_eps

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,26 @@ import datetime
77

88
import modules.config_details as conf_info
99

10-
ratios_dir = 'data/calculated_ratios/'
11-
1210
# ----------------
1311
# HELPER FUNCTIONS
1412
# ----------------
1513

1614
def 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

3126
def 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)

data/calculated_ratios/eps_TSLA.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ Date,EPS
1818
2015-03-31,-1.22015028485
1919
2015-06-30,-1.45792689454
2020
2015-09-30,-1.81903933802
21+
2015-12-31,-7.03265909929

modules/__init__.pyc

14 Bytes
Binary file not shown.

modules/config_details.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
1+
# FUNDAMENTALS DATA RETRIEVAL
12

23
fundamentals_dir = './data/fundamentals/'
34
fundamentals_filename_glob = 'fundamentals_*.csv'
45
fundamentals_filename_regex = 'fundamentals_(.*).csv'
6+
def get_fundamentals_filename(ticker):
7+
return 'fundamentals_' + ticker.upper() + '.csv'
8+
9+
# STOCKS DATA RETRIEVAL
510

611
stock_prices_dir = './data/stock_prices/'
712
stock_prices_ticker_pre_filename_prefix = 'close_prices_pre_2016_02_'
813
stock_prices_ticker_post_filename_prefix = 'close_prices_post_2016_02_'
9-
1014
def get_stock_prices_pre_2016_02_filename(ticker):
1115
return stock_prices_ticker_pre_filename_prefix + ticker.upper() + '.csv'
1216
def get_stock_prices_post_2016_02_filename(ticker):
1317
return stock_prices_ticker_post_filename_prefix + ticker.upper() + '.csv'
1418

1519
quandl_out_shares_db_id = 'RAYMOND'
16-
1720
def get_quandle_outstanding_shares_filename(ticker):
1821
return 'outstanding_shares_' + quandl_out_shares_db_id + '_' + ticker.upper() + '.csv'
22+
out_shares_filename_glob = 'outstanding_shares_' + quandl_out_shares_db_id + '_*.csv'
23+
out_shares_filename_regex = 'outstanding_shares_' + quandl_out_shares_db_id + '_(.*).csv'
24+
25+
# RATIOS CALCULATION
26+
27+
ratios_dir = 'data/calculated_ratios/'
28+
def get_eps_filename(ticker):
29+
return 'eps_' + ticker.upper() + '.csv'
1930

0 commit comments

Comments
 (0)