- improved

git-svn-id: http://moon:8086/svn/projects/Stock@333 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
2019-12-27 11:34:00 +00:00
parent fe706dead2
commit a739314378
3 changed files with 54 additions and 48 deletions
+11 -9
View File
@@ -12,6 +12,8 @@ import matplotlib as mpl
mpl.rc('figure', max_open_warning = 0)
key = '0UO7Z2MVZ2YSQSVE'
class Stock(object):
def __init__(self, params, symbol, symbol_params):
self.symbol_params = symbol_params
@@ -84,26 +86,26 @@ class Stock(object):
def statistics(self):
N = len(self.data['index'])
self.data['ema'] = exponential_moving_average(self.data, key='close', alpha=self.params['ema_alpha'])
self.data['sma'] = moving_average(self.data, key='close', window_days=self.params['sma_days'])
self.data['close_n'] = normalize(self.data, key='close')
self.data['macd'] = macd(self.data, key='close_n')
self.data['min'] = moving_min(self.data, key='close_n', window_days=self.params['q_days'])
self.data['max'] = moving_max(self.data, key='close_n', window_days=self.params['q_days'])
self.data['ema'] = exponential_moving_average(self.data['close'], alpha=self.params['ema_alpha'])
self.data['sma'] = moving_average(self.data['close'], window_days=self.params['sma_days'])
self.data['close_n'] = normalize(self.data['close'])
self.data['macd'] = macd(self.data['close_n'])
self.data['min'] = moving_min(self.data['close_n'], window_days=self.params['q_days'])
self.data['max'] = moving_max(self.data['close_n'], window_days=self.params['q_days'])
self.data['Qmin'] = self.data['close_n'] - self.data['min']
self.data['Qmax'] = self.data['close_n'] - self.data['max']
self.boll = bollinger(self.data, window_days=30)
x_r = np.linspace(0, N, N)
y_r = self.data['macd']
y_r = np.append(self.data['macd'], self.data['macd'][N-1])
x_r = np.linspace(1, N, N+1)
spl = UnivariateSpline(x=x_r, y=y_r, k=5)
spl.set_smoothing_factor(0.25)
spl_d = spl.derivative()
spl_dd = spl.derivative().derivative()
yf = spl(x_r)
yf_d = spl_d(x_r)
x_r2 = np.linspace(-1, N-1, N)
x_r2 = np.linspace(1, N, N+1)
yf_dd = spl_dd(x_r2)
self.data['macd_f'] = np.transpose(yf)