- improved
git-svn-id: http://moon:8086/svn/projects/Stock@307 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
+19
-15
@@ -22,6 +22,7 @@ import os
|
|||||||
key = '0UO7Z2MVZ2YSQSVE'
|
key = '0UO7Z2MVZ2YSQSVE'
|
||||||
thresh_macd = 0.5
|
thresh_macd = 0.5
|
||||||
show_range_days = 20
|
show_range_days = 20
|
||||||
|
show_title = 'KEYS'
|
||||||
|
|
||||||
titles = [
|
titles = [
|
||||||
'AAPL',
|
'AAPL',
|
||||||
@@ -50,9 +51,8 @@ titles = [
|
|||||||
'WAF.DE',
|
'WAF.DE',
|
||||||
'EVT.DE',
|
'EVT.DE',
|
||||||
'VOW.DE',
|
'VOW.DE',
|
||||||
'AMS.SW',
|
'KEYS',
|
||||||
'I',
|
'I']
|
||||||
'OQ3.F']
|
|
||||||
|
|
||||||
|
|
||||||
def ema(data, key, alpha=0.5, ic=None):
|
def ema(data, key, alpha=0.5, ic=None):
|
||||||
@@ -129,7 +129,6 @@ def bollinger(data, window_days, f=2):
|
|||||||
result['mid'] = mid
|
result['mid'] = mid
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
class Symbol(object):
|
class Symbol(object):
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -141,7 +140,6 @@ class Symbol(object):
|
|||||||
filename = self.name.replace('.','_') + '.h5'
|
filename = self.name.replace('.','_') + '.h5'
|
||||||
fetch = False
|
fetch = False
|
||||||
today = dt.date.today()
|
today = dt.date.today()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hdf = pd.HDFStore(filename, 'r')
|
hdf = pd.HDFStore(filename, 'r')
|
||||||
except:
|
except:
|
||||||
@@ -157,7 +155,7 @@ class Symbol(object):
|
|||||||
if fetch:
|
if fetch:
|
||||||
print ("Fetching \"{}\"".format(self.name))
|
print ("Fetching \"{}\"".format(self.name))
|
||||||
# Get stock price via data reader
|
# Get stock price via data reader
|
||||||
start = dt.datetime(2019,1,1)
|
start = dt.datetime(today.year,1,1)
|
||||||
end = dt.date.today()
|
end = dt.date.today()
|
||||||
data = web.DataReader(self.name, "av-daily", start, end, api_key=key)
|
data = web.DataReader(self.name, "av-daily", start, end, api_key=key)
|
||||||
hdf = pd.HDFStore(filename)
|
hdf = pd.HDFStore(filename)
|
||||||
@@ -166,9 +164,13 @@ class Symbol(object):
|
|||||||
self.data_full = hdf[self.name]*self.k_euro
|
self.data_full = hdf[self.name]*self.k_euro
|
||||||
hdf.close()
|
hdf.close()
|
||||||
|
|
||||||
def __plot(self, data):
|
def __plot(self, d, keys):
|
||||||
dates = data.index
|
dates = d.index
|
||||||
|
|
||||||
|
for key in keys:
|
||||||
|
data = d[key]
|
||||||
data.plot()
|
data.plot()
|
||||||
|
|
||||||
def hover(event):
|
def hover(event):
|
||||||
if event.inaxes == self.ax:
|
if event.inaxes == self.ax:
|
||||||
x_idx = int(event.xdata)
|
x_idx = int(event.xdata)
|
||||||
@@ -193,9 +195,7 @@ class Symbol(object):
|
|||||||
|
|
||||||
self.fig = plt.figure(figNum)
|
self.fig = plt.figure(figNum)
|
||||||
self.ax = plt.subplot(311)
|
self.ax = plt.subplot(311)
|
||||||
self.__plot(data['close'])
|
self.__plot(data, ['ema', 'close', 'sma'])
|
||||||
self.__plot(data['ema'])
|
|
||||||
self.__plot(data['sma'])
|
|
||||||
plt.title(self.name)
|
plt.title(self.name)
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.grid()
|
plt.grid()
|
||||||
@@ -213,10 +213,15 @@ class Symbol(object):
|
|||||||
plt.grid()
|
plt.grid()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
figNum = 1
|
figNum = 1
|
||||||
for title in titles:
|
|
||||||
|
if '' != show_title:
|
||||||
|
sym = Symbol(show_title)
|
||||||
|
sym.fetch()
|
||||||
|
sym.analyze()
|
||||||
|
sym.show(figNum)
|
||||||
|
else:
|
||||||
|
for title in titles:
|
||||||
sym = Symbol(title)
|
sym = Symbol(title)
|
||||||
sym.fetch()
|
sym.fetch()
|
||||||
result = sym.analyze()
|
result = sym.analyze()
|
||||||
@@ -224,6 +229,5 @@ for title in titles:
|
|||||||
sym.show(figNum)
|
sym.show(figNum)
|
||||||
figNum += 1
|
figNum += 1
|
||||||
|
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user