- improved

git-svn-id: http://moon:8086/svn/projects/Stock@300 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-12-10 19:39:43 +00:00
parent f6b3ed673c
commit 2568f96851
+26 -7
View File
@@ -95,22 +95,40 @@ def bollinger(data, window_days, f=2):
return result
data = {}
title = 'AAPL'
titles = []
titles.append('AAPL')
titles.append('XLNX')
if 0:
for title in titles:
fetch = False
today = datetime.date.today()
try:
hdf = pd.HDFStore(title + '.h5', 'r')
except IOError as e:
fetch = True
print (e)
try:
data = hdf[title]
except Exception as e:
fetch = True
print (e)
if fetch:
print ("Fetching \"{}\"".format(title))
hdf.close()
# Get stock price via data reader
start = datetime.datetime(2016,1,1)
end = datetime.date.today()
data = web.DataReader(title, "av-daily", start, end, api_key=key)
# data = web.DataReader(title, "stooq", start, end)
print(data)
hdf = pd.HDFStore(title + '.h5')
hdf[title] = data
hdf.close()
else:
hdf = pd.HDFStore(title + '.h5', 'r')
data = hdf[title]
data['ema'] = ema(data, key='close', alpha=0.75)
data['macd'] = macd(data, key='close')
@@ -118,6 +136,7 @@ data['sma'] = sma(data, key='close', window_days=30)
boll = bollinger(data, window_days=30)
plt.subplot(311)
plt.title(title)
data['close'].plot()
data['ema'].plot()
data['sma'].plot()