Ejemplo n.º 1
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     self.data.addDict({
         self.idx_key: index_value,
         self.ret_key: statistics.pstdev(self.buf),
     })
Ejemplo n.º 2
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     self.data.addDict({
         self.idx_key: index_value,
         self.ret_key: min(self.buf),
     })
Ejemplo n.º 3
0
    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])

        if len(self.data) > self.period:
            const_std = statistics.pstdev(self.buf[-self.period:])
            self.dynamic_n *= const_std / self.prev_std
            self.dynamic_n = max(self.min_n, self.dynamic_n)
            self.dynamic_n = min(self.max_n, self.dynamic_n)
            tmp_n = int(round(self.dynamic_n))

            mean = statistics.mean(self.buf[-tmp_n:])
            std = statistics.pstdev(self.buf[-tmp_n:])

            self.data.addRow(
                [index_value, mean + self.rate * std,
                 mean, mean - self.rate * std],
                self.keys
            )

            self.prev_std = const_std
        else:
            if len(self.data) == self.period:
                self.prev_std = statistics.pstdev(self.buf)

            self.data.addRow(
                [index_value, None, None, None],
                self.keys
            )
Ejemplo n.º 4
0
    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])

        if len(self.data) > self.period:
            const_std = statistics.pstdev(self.buf[-self.period:])
            self.dynamic_n *= const_std / self.prev_std
            self.dynamic_n = max(self.min_n, self.dynamic_n)
            self.dynamic_n = min(self.max_n, self.dynamic_n)
            tmp_n = int(round(self.dynamic_n))

            mean = statistics.mean(self.buf[-tmp_n:])
            std = statistics.pstdev(self.buf[-tmp_n:])

            self.data.addRow([
                index_value, mean + self.rate * std, mean,
                mean - self.rate * std
            ], self.keys)

            self.prev_std = const_std
        else:
            if len(self.data) == self.period:
                self.prev_std = statistics.pstdev(self.buf)

            self.data.addRow([index_value, None, None, None], self.keys)
Ejemplo n.º 5
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     mean = statistics.mean(self.buf)
     std = statistics.pstdev(self.buf, mu=mean)
     self.data.addRow([
         index_value, mean + self.rate * std, mean, mean - self.rate * std
     ], self.keys)
Ejemplo n.º 6
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     mean = statistics.mean(self.buf)
     std = statistics.pstdev(self.buf, mu=mean)
     self.data.addRow([
         index_value, mean + self.rate * std, mean, mean - self.rate * std
     ], self.keys)
Ejemplo n.º 7
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     if len(self.buf) == self.period:
         buf_list = list(self.buf)
         tmp = 0.0
         for a, b in zip(buf_list[:-1], buf_list[1:]):
             tmp += abs(b - a)
         self.data.addDict({
             self.idx_key: index_value,
             self.ret_key: (self.buf[-1] - self.buf[0]) / tmp,
         })
Ejemplo n.º 8
0
 def _addOne(self, _data_struct: DataStruct):
     index_value = _data_struct.index()[0]
     self.buf.append(_data_struct.getColumn(self.use_key)[0])
     if len(self.buf) == self.period:
         buf_list = list(self.buf)
         tmp = 0.0
         for a, b in zip(buf_list[:-1], buf_list[1:]):
             tmp += abs(b - a)
         self.data.addDict({
             self.idx_key: index_value,
             self.ret_key: (self.buf[-1] - self.buf[0]) / tmp,
         })