-
Notifications
You must be signed in to change notification settings - Fork 6
/
999_checks
executable file
·56 lines (44 loc) · 2.07 KB
/
999_checks
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
#!/usr/bin/env python2
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import modules.config_details as conf_info
dates_formatter = '%Y-%m-%d'
dateparse = lambda x: pd.datetime.strptime(x, dates_formatter)
def get_series_func(ticker):
eps_calculated_df = pd.read_csv(conf_info.ratios_dir + conf_info.get_eps_filename(ticker), parse_dates=['Date'], date_parser=dateparse)
eps_from_fundamentals_df = pd.read_csv(conf_info.fundamentals_dir + conf_info.get_fundamentals_filename(ticker), parse_dates=['end_date'], date_parser=dateparse)[['end_date','eps_basic']]
return eps_calculated_df, eps_from_fundamentals_df
def plot_axis_with_data(axis, calc_df, fund_df):
axis.yaxis.set_major_locator(mticker.MaxNLocator(nbins='5', prune='upper'))
axis.plot(calc_df['Date'], calc_df['EPS'], linestyle='--')
axis.plot(fund_df['end_date'], fund_df['eps_basic'], linestyle='-')
axis.grid(True)
# ax_legend = axis.legend(['calc','fund'], loc='best')#loc='upper right', bbox_to_anchor=(1.3, 0.5))
ax_legend = axis.legend(['calc','fund'], loc='center right', bbox_to_anchor=(1.15, 0.5))
def build_plot(tickers, series_func):
num_rows = len(tickers)
shared_ax = None
for idx, ticker in enumerate(tickers):
print 'idx', idx, 'ticker', ticker
ax = None
# sharing the x axis among plots
if (idx == 0):
ax = plt.subplot2grid((num_rows,1), (idx,0))
shared_ax = ax
else:
ax = plt.subplot2grid((num_rows,1), (idx,0), sharex=shared_ax)
# hiding the x values from the plot
if (idx == num_rows - 1):
plt.setp(ax.get_xticklabels(), visible=True)
else:
plt.setp(ax.get_xticklabels(), visible=False)
ax.set_ylabel(ticker)
calc_df, fund_df = series_func(ticker)
plot_axis_with_data(ax, calc_df, fund_df)
# store the plots
plt.subplots_adjust(left=.08,right=.88,hspace=0)
ticker_fig = plt.gcf() # for "get current figure"
ticker_fig.savefig(conf_info.graphs_dir + 'checks_eps.png', dpi=300, format='png')
plt.show()
build_plot(['AAPL','AMZN','EBAY','GOOG','NFLX','TSLA', 'G'],get_series_func)