MCPcopy Index your code
hub / github.com/QuantFans/quantdigger / MA

Class MA

quantdigger/kernel/indicators/common.py:14–49  ·  view source on GitHub ↗

移动平均线指标。

Source from the content-addressed store, hash-verified

12from quantdigger.widgets.mplotwidgets.mplots import create_attributes
13
14class MA(IndicatorBase):
15 """ 移动平均线指标。 """
16 ## @todo assure name is unique, it there are same names,
17 # modify the repeat name.
18 @create_attributes
19 def __init__(self, tracker, prices, n, name='MA', color='y', lw=1, style="line"):
20 super(MA, self).__init__(tracker, name)
21 # self.value为任何支持index的数据结构。
22 # 在策略中,price变量可能为NumberSeries,需要用NUMBER_SERIES_SUPPORT处理,
23 # 转化为numpy.ndarray等能被指标函数处理的参数。
24 self.value = self._moving_average(prices, n)
25 self._algo = self._iter_moving_average
26 self._args = (n,)
27
28 def _iter_moving_average(self, price, n):
29 """ 逐步运行的均值函数。"""
30 pass
31
32 def _moving_average(self, data, n):
33 """ 向量化运行的均值函数。 """
34 data = transform2ndarray(data)
35 return talib.SMA(data, n)
36
37 def plot(self, widget):
38 """ 绘图,参数可由UI调整。 """
39 self.widget = widget
40 self.plot_line(self.value, self.color, self.lw, self.style)
41
42 #@override_attributes
43 #def plot(self, widget, color='y', lw=2, style="line"):
44 #""" 绘图,参数可由UI调整。
45 ### @note 构造函数中的绘图参数需与函数
46 #的绘图函数一致。这样函数参数可覆盖默认的属性参数。
47 #"""
48 #self.widget = widget
49 #self.plot_line(self.value, color, lw, style)
50
51
52class BOLL(IndicatorBase):

Callers 4

mplot_demo.pyFile · 0.90
__init__Method · 0.90
plotMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected