diff --git a/pandas_eval.py b/pandas_eval.py index df43e0b..5ea4964 100644 --- a/pandas_eval.py +++ b/pandas_eval.py @@ -22,7 +22,7 @@ import os key = '0UO7Z2MVZ2YSQSVE' thresh_macd = 2.0 show_range_days = 20 -show_title = [] +show_title = ['QCOM', 'CSCO'] k_euro = 1 / 1.11 titles = [ @@ -89,7 +89,7 @@ titles = [ 'PLUG', 'PCELF', 'SU.PA', - 'SON1.DE', +# 'SON1.DE', 'STM.DE', 'BC8.DE', 'MOR.DE', @@ -231,13 +231,27 @@ class Symbol(object): self.data_full['sma'] = sma(self.data_full, key='close', window_days=30) self.boll_full = bollinger(self.data_full, window_days=30) - _macd = self.data_full['macd'][len(self.data_full)-1] - return {'macd' : _macd} + _macd_curr = self.data_full['macd'][len(self.data_full)-1] + + self._macd_data = self.data_full['macd'][len(self.data_full) - show_range_days:] + x_r = list(range(0, len(self._macd_data))) + y_r = self._macd_data.to_numpy() + poly = np.polyfit(x_r, y_r, 5) + poly_d = np.polyder(poly) + + yf = np.polyval(poly, x_r) + yf_d = np.polyval(poly_d, x_r) + self._macd_fitted = pd.DataFrame(np.transpose([yf,yf_d]), index=self._macd_data.index, columns=['macd_fitted', 'macd_fitted_d']) + + _macd_f_curr = self._macd_fitted['macd_fitted'][len(self._macd_fitted)-1] + _macd_fd_curr = self._macd_fitted['macd_fitted_d'][len(self._macd_fitted)-1] + + return {'macd' : _macd_curr, 'macd_f' : _macd_f_curr, 'macd_fd' : _macd_fd_curr} def show(self, figNum=1): - data = self.data_full[len(self.data_full)-1 - show_range_days:] - boll = self.boll_full[len(self.boll_full)-1 - show_range_days:] + data = self.data_full[len(self.data_full) - show_range_days:] + boll = self.boll_full[len(self.boll_full) - show_range_days:] self.fig = plt.figure(figNum) self.ax = plt.subplot(311) @@ -253,19 +267,21 @@ class Symbol(object): plt.legend() plt.grid() + plt.subplot(313) - data['macd'].plot() + self._macd_data.plot() + self._macd_fitted['macd_fitted'].plot() + self._macd_fitted['macd_fitted_d'].plot() plt.legend() plt.grid() - figNum = 1 if len(show_title) > 0: for title in show_title: sym = Symbol(title) sym.fetch() - sym.analyze() + print(sym.analyze()) sym.show(figNum) figNum += 1 else: @@ -273,7 +289,7 @@ else: sym = Symbol(title) sym.fetch() result = sym.analyze() - if result['macd'] > thresh_macd: + if result['macd_f'] > thresh_macd and result['macd_fd'] > 0: sym.show(figNum) figNum += 1