diff --git a/pandas_eval.py b/pandas_eval.py index 394810c..7ba2cc2 100644 --- a/pandas_eval.py +++ b/pandas_eval.py @@ -23,31 +23,32 @@ import os key = '0UO7Z2MVZ2YSQSVE' thresh_macd = 1.5 show_range_days = 20 -show_title = ['WDI.DE', 'QCOM', 'VAR1.DE', 'MOR.DE', 'CSCO', 'OHB.DE'] +show_symbols = ['ITMPF', 'PLUG', 'MOR.DE', 'CSCO', 'ERCA.DE', 'AVGO', 'DIS'] +#show_symbols = [] k_euro = 1 / 1.11 N_poly = 7 ema_alpha = 0.75 sma_days = 10 -titles = { - 'WDI.DE' : {'currency' : '€'}, - 'AAPL' : {'currency' : '$'}, - 'XLNX' : {'currency' : '$'}, - 'QCOM' : {'currency' : '$'}, - 'DPW.DE' : {'currency' : '€'}, - 'CSCO' : {'currency' : '$'}, - 'AIR' : {'currency' : '$'}, - 'BA' : {'currency' : '$'}, - 'NVDA' : {'currency' : '$'}, - 'MSFT' : {'currency' : '$'}, - 'DIS' : {'currency' : '$'}, - 'NFLX' : {'currency' : '$'}, - 'OHB.DE' : {'currency' : '€'}, - 'ERCA.DE' : {'currency' : '€'}, - 'VAR1.DE' : {'currency' : '€'}, - 'HD' : {'currency' : '$'}, - 'AMZN' : {'currency' : '$'}, - 'GOOGL' : {'currency' : '$'}, +symbols = { + 'WDI.DE' : {'name' : 'WireCard', 'currency' : '€'}, + 'AAPL' : {'name' : 'Apple', 'currency' : '$'}, + 'XLNX' : {'name' : 'Xilinx', 'currency' : '$'}, + 'QCOM' : {'name' : 'Qualcomm', 'currency' : '$'}, + 'DPW.DE' : {'name' : 'Deutsche Post', 'currency' : '€'}, + 'CSCO' : {'name' : 'Cisco', 'currency' : '$'}, + 'AIR' : {'name' : 'Airbus', 'currency' : '$'}, + 'BA' : {'name' : 'Boeing', 'currency' : '$'}, + 'NVDA' : {'name' : 'Nvidia', 'currency' : '$'}, + 'MSFT' : {'name' : 'Microsoft', 'currency' : '$'}, + 'DIS' : {'name' : 'Disney', 'currency' : '$'}, + 'NFLX' : {'name' : 'Netflix', 'currency' : '$'}, + 'OHB.DE' : {'name' : 'OHB', 'currency' : '€'}, + 'ERCA.DE' : {'name' : 'Ericsson', 'currency' : '€'}, + 'VAR1.DE' : {'name' : 'Varta', 'currency' : '€'}, + 'HD' : {'name' : 'Home Depot', 'currency' : '$'}, + 'AMZN' : {'name' : 'Amazon', 'currency' : '$'}, + 'GOOGL' : {'name' : 'Google', 'currency' : '$'}, 'FB2A.DE' : {'currency' : '€'}, 'ZIL2.DE' : {'currency' : '€'}, 'SIS.DE' : {'currency' : '€'}, @@ -67,7 +68,7 @@ titles = { 'DAI.DE' : {'currency' : '€'}, 'SHA.DE' : {'currency' : '€'}, 'CON.DE' : {'currency' : '€'}, - 'DHER.DE' : {'currency' : '€'}, + 'DHER.DE' : {'name' : 'Delivery Hero', 'currency' : '€'}, 'BSL.DE' : {'currency' : '€'}, 'D6H.DE' : {'currency' : '€'}, 'TC1.DE' : {'currency' : '€'}, @@ -86,7 +87,7 @@ titles = { 'ORCL' : {'currency' : '$'}, 'UBER' : {'currency' : '$'}, 'VMW' : {'currency' : '$'}, - 'AVGO' : {'currency' : '$'}, + 'AVGO' : {'name' : 'Avago', 'currency' : '$'}, 'CY' : {'currency' : '$'}, 'QABSY' : {'currency' : '$'}, 'BLDP' : {'currency' : '$'}, @@ -98,13 +99,13 @@ titles = { # 'SON1.DE' : {'currency' : '€'}, 'STM.DE' : {'currency' : '€'}, 'BC8.DE' : {'currency' : '€'}, - 'MOR.DE' : {'currency' : '€'}, + 'MOR.DE' : {'name' : 'Morphosys', 'currency' : '€'}, 'BAYN.DE' : {'currency' : '€'}, 'BEI.DE' : {'currency' : '€'}, 'EUZ.DE' : {'currency' : '€'}, 'SLAB' : {'currency' : '$'}, - 'SPLK' : {'currency' : '$'}, - 'IAG' : {'currency' : '$'}, + 'SPLK' : {'name' : 'Splunk', 'currency' : '$'}, + 'IAG' : {'name' : 'IAG', 'currency' : '$'}, 'INTC' : {'currency' : '$'}, 'I' : {'currency' : '$'}} @@ -182,20 +183,24 @@ def bollinger(data, window_days, f=2): result['mid'] = mid return result -class Symbol(object): - def __init__(self, title, params): - self.name = title +class Title(object): + def __init__(self, symbol, params): + self.symbol = symbol self.params = params + try: + self.name = params['name'] + except: + self.name = symbol self.ax = None self.fig = None self.currency = params['currency'] self.currency_corr = 1 - if '$' in self.currency : - self.currency_corr = 1/1.11 + if '$' in self.currency: + self.currency_corr = k_euro def fetch(self): - filename = self.name.replace('.','_') + '.h5' + filename = self.symbol.replace('.', '_') + '.h5' fetch = False today = dt.date.today() try: @@ -212,17 +217,17 @@ class Symbol(object): fetch = True if fetch: - print ("Fetching \"{}\"".format(self.name)) + print ("Fetching \"{}\"".format(self.symbol)) # Get stock price via data reader start = dt.datetime(today.year,1,1) end = dt.date.today() - data = web.DataReader(self.name, "av-daily", start, end, api_key=key) + data = web.DataReader(self.symbol, "av-daily", start, end, api_key=key) hdf = pd.HDFStore(filename) - hdf[self.name] = data + hdf[self.symbol] = data else: hdf = pd.HDFStore(filename, 'r') - self.data_full = hdf[self.name]*self.currency_corr + self.data_full = hdf[self.symbol] * self.currency_corr hdf.close() def __plot(self, d, keys): @@ -236,7 +241,7 @@ class Symbol(object): if event.inaxes == self.ax: x_idx = int(event.xdata) self.ax.format_xdata = lambda x: dates[x_idx] - self.ax.format_ydata = lambda y: '{}{:.2f}'.format(self.currency, data[x_idx]) + self.ax.format_ydata = lambda y: '€ {:.2f}'.format(data[x_idx]) self.fig.canvas.mpl_connect("motion_notify_event", hover) @@ -294,23 +299,22 @@ class Symbol(object): figNum = 1 -if len(show_title) > 0: - for title in show_title: - if title in titles: - sym = Symbol(title, titles[title]) - sym.fetch() - print(sym.analyze()) - sym.show(figNum) +if len(show_symbols) > 0: + for symbol in show_symbols: + if symbol in symbols: + title = Title(symbol, symbols[symbol]) + title.fetch() + print(title.analyze()) + title.show(figNum) figNum += 1 else: - for title in show_title: - if title in titles: - sym = Symbol(title, titles[title]) - sym.fetch() - result = sym.analyze() - if result['macd_f'] > thresh_macd and result['macd_fd'] > 0: - sym.show(figNum) - figNum += 1 + for symbol in symbols: + title = Title(symbol, symbols[symbol]) + title.fetch() + result = title.analyze() + if result['macd_f'] > thresh_macd and result['macd_fd'] > 0: + title.show(figNum) + figNum += 1 plt.show()