- use spline interpolation
git-svn-id: http://moon:8086/svn/projects/Stock@319 fda53097-d464-4ada-af97-ba876c37ca34
This commit is contained in:
+7
-7
@@ -3,6 +3,7 @@ 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
|
||||||
|
from scipy.interpolate import UnivariateSpline
|
||||||
import datetime as dt
|
import datetime as dt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ import os
|
|||||||
|
|
||||||
key = '0UO7Z2MVZ2YSQSVE'
|
key = '0UO7Z2MVZ2YSQSVE'
|
||||||
thresh_macd = 1.5
|
thresh_macd = 1.5
|
||||||
show_range_days = 40
|
show_range_days = 20
|
||||||
show_title = ['QCOM', 'VAR1.DE', 'MOR.DE', 'QIA.DE', 'MDG1.DE']
|
show_title = ['QCOM', 'VAR1.DE', 'MOR.DE', 'QIA.DE', 'MDG1.DE']
|
||||||
k_euro = 1 / 1.11
|
k_euro = 1 / 1.11
|
||||||
N_poly = 7
|
N_poly = 7
|
||||||
@@ -241,14 +242,13 @@ class Symbol(object):
|
|||||||
_macd_curr = self.data_full['macd'][len(self.data_full)-1]
|
_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:]
|
self._macd_data = self.data_full['macd'][len(self.data_full) - show_range_days:]
|
||||||
x_r = list(range(0, len(self._macd_data)+1))
|
x_r = np.linspace(0, len(self._macd_data), len(self._macd_data))
|
||||||
y_r = self._macd_data.to_numpy()
|
y_r = self._macd_data.to_numpy()
|
||||||
y_r = np.append(y_r, y_r[len(y_r)-1])
|
spl = UnivariateSpline(x_r, y_r)
|
||||||
poly = np.polyfit(x_r, y_r, N_poly)
|
spl.set_smoothing_factor(0.5)
|
||||||
poly_d = np.polyder(poly)
|
yf = spl(x_r)
|
||||||
|
yf_d = spl.derivative()(x_r)
|
||||||
|
|
||||||
yf = np.polyval(poly, x_r[:len(x_r)-1])
|
|
||||||
yf_d = np.polyval(poly_d, x_r[:len(x_r)-1])
|
|
||||||
self._macd_fitted = pd.DataFrame(np.transpose([yf,yf_d]), index=self._macd_data.index, columns=['macd_fitted', 'macd_fitted_d'])
|
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_f_curr = self._macd_fitted['macd_fitted'][len(self._macd_fitted)-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user