git-svn-id: http://moon:8086/svn/projects/Stock@302 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-12-13 18:38:23 +00:00
parent ca3c143522
commit 03e36d74cc
4 changed files with 168 additions and 26 deletions
+64 -26
View File
@@ -101,9 +101,14 @@ titles.append('AAPL')
titles.append('XLNX')
titles.append('QCOM')
titles.append('DPW.DE')
titles.append('CSCO')
titles.append('AIR')
for title in titles:
show_title = 'QCOM'
show_range_days = 20
pd.DatetimeIndex
def fetch(title):
filename = title + '.h5'
fetch = False
today = dt.date.today()
@@ -111,11 +116,14 @@ for title in titles:
try:
hdf = pd.HDFStore(filename, 'r')
hdf.close()
except IOError as e:
except:
fetch = True
lastmodified = dt.datetime.fromtimestamp(os.stat(filename).st_mtime).date()
if lastmodified != today:
try:
lastmodified = dt.datetime.fromtimestamp(os.stat(filename).st_mtime).date()
if lastmodified != today:
fetch = True
except:
fetch = True
if fetch:
@@ -131,30 +139,60 @@ for title in titles:
data = hdf[title]
hdf.close()
def show(title):
data['ema'] = ema(data, key='close', alpha=0.75)
data['macd'] = macd(data, key='close')
data['sma'] = sma(data, key='close', window_days=30)
boll = bollinger(data, window_days=30)
k_euro = 1/1.11
plt.subplot(311)
plt.title(title)
data['close'].plot()
data['ema'].plot()
data['sma'].plot()
plt.legend()
plt.grid()
filename = title + '.h5'
plt.subplot(312)
boll['upper'].plot()
boll['mid'].plot()
boll['lower'].plot()
plt.legend()
plt.grid()
hdf = pd.HDFStore(filename, 'r')
data_full = hdf[title]*k_euro
plt.subplot(313)
data['macd'].plot()
plt.legend()
plt.grid()
data_full['ema'] = ema(data_full, key='close', alpha=0.75)
data_full['macd'] = macd(data_full, key='close')
data_full['sma'] = sma(data_full, key='close', window_days=30)
boll = bollinger(data_full, window_days=30)
hdf.close()
plt.show()
data = data_full[len(data_full)-1 - show_range_days:]
dates = data.index
fig = plt.figure(1)
ax = plt.subplot(311)
def hover(event):
if event.inaxes == ax:
x_idx = int(event.xdata)
ax.format_xdata = lambda x: dates[x_idx]
ax.format_ydata = lambda y: '{:.2f}'.format(data['close'][x_idx])
fig.canvas.mpl_connect("motion_notify_event", hover)
data['close'].plot()
data['ema'].plot()
data['sma'].plot()
plt.title(title)
plt.legend()
plt.grid()
plt.subplot(312)
boll['upper'].plot()
boll['mid'].plot()
boll['lower'].plot()
plt.legend()
plt.grid()
plt.subplot(313)
data['macd'].plot()
plt.legend()
plt.grid()
plt.show()
for title in titles:
fetch(title)
show(show_title)