- check timestamp
git-svn-id: http://moon:8086/svn/projects/Stock@301 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
+16
-16
@@ -3,7 +3,8 @@ import pandas_datareader.data as web
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import datetime
|
import datetime as dt
|
||||||
|
import os
|
||||||
|
|
||||||
# Stock Investors Financial Math
|
# Stock Investors Financial Math
|
||||||
# https://www.fmlabs.com/reference/default.htm?url=SimpleMA.htm
|
# https://www.fmlabs.com/reference/default.htm?url=SimpleMA.htm
|
||||||
@@ -98,36 +99,37 @@ data = {}
|
|||||||
titles = []
|
titles = []
|
||||||
titles.append('AAPL')
|
titles.append('AAPL')
|
||||||
titles.append('XLNX')
|
titles.append('XLNX')
|
||||||
|
titles.append('QCOM')
|
||||||
|
titles.append('DPW.DE')
|
||||||
|
|
||||||
for title in titles:
|
for title in titles:
|
||||||
|
|
||||||
|
filename = title + '.h5'
|
||||||
fetch = False
|
fetch = False
|
||||||
today = datetime.date.today()
|
today = dt.date.today()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hdf = pd.HDFStore(title + '.h5', 'r')
|
hdf = pd.HDFStore(filename, 'r')
|
||||||
|
hdf.close()
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
fetch = True
|
fetch = True
|
||||||
print (e)
|
|
||||||
|
|
||||||
try:
|
lastmodified = dt.datetime.fromtimestamp(os.stat(filename).st_mtime).date()
|
||||||
data = hdf[title]
|
if lastmodified != today:
|
||||||
except Exception as e:
|
|
||||||
fetch = True
|
fetch = True
|
||||||
print (e)
|
|
||||||
|
|
||||||
if fetch:
|
if fetch:
|
||||||
print ("Fetching \"{}\"".format(title))
|
print ("Fetching \"{}\"".format(title))
|
||||||
hdf.close()
|
|
||||||
# Get stock price via data reader
|
# Get stock price via data reader
|
||||||
start = datetime.datetime(2016,1,1)
|
start = dt.datetime(2019,1,1)
|
||||||
end = datetime.date.today()
|
end = dt.date.today()
|
||||||
data = web.DataReader(title, "av-daily", start, end, api_key=key)
|
data = web.DataReader(title, "av-daily", start, end, api_key=key)
|
||||||
# data = web.DataReader(title, "stooq", start, end)
|
|
||||||
hdf = pd.HDFStore(title + '.h5')
|
hdf = pd.HDFStore(title + '.h5')
|
||||||
hdf[title] = data
|
hdf[title] = data
|
||||||
hdf.close()
|
else:
|
||||||
|
hdf = pd.HDFStore(filename, 'r')
|
||||||
|
data = hdf[title]
|
||||||
|
hdf.close()
|
||||||
|
|
||||||
|
|
||||||
data['ema'] = ema(data, key='close', alpha=0.75)
|
data['ema'] = ema(data, key='close', alpha=0.75)
|
||||||
@@ -156,5 +158,3 @@ plt.legend()
|
|||||||
plt.grid()
|
plt.grid()
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
hdf.close()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user