当前位置: 首页>>代码示例>>Python>>正文


Python Utils.DataStruct类代码示例

本文整理汇总了Python中ParadoxTrading.Utils.DataStruct的典型用法代码示例。如果您正苦于以下问题:Python DataStruct类的具体用法?Python DataStruct怎么用?Python DataStruct使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataStruct类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LogReturn

class LogReturn(IndicatorAbstract):
    def __init__(
            self,
            _skip_period: int = 1,
            _use_key: str = 'closeprice',
            _idx_key: str = 'time',
            _ret_key: str = 'logreturn'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.skip_period = _skip_period
        self.buf = deque(maxlen=self.skip_period)

    def _addOne(self, _data_struct: DataStruct):
        index = _data_struct.index()[0]
        value = _data_struct[self.use_key][0]
        if len(self.buf) >= self.skip_period:
            last_value = self.buf.popleft()
            chg_rate = math.log(value / last_value)
            self.data.addDict({
                self.idx_key: index,
                self.ret_key: chg_rate,
            })
        self.buf.append(value)
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:32,代码来源:LogReturn.py

示例2: EMA

class EMA(IndicatorAbstract):
    def __init__(
            self, _period: int, _use_key: str='closeprice',
            _idx_key: str = 'time', _ret_key: str = 'ema'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.period = _period

    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        tmp_value = _data_struct[self.use_key][0]
        if len(self) > 0:
            last_ret = self.getLastData().toDict()[self.ret_key]
            tmp_value = (tmp_value - last_ret) / self.period + last_ret
        self.data.addDict({
            self.idx_key: index_value,
            self.ret_key: tmp_value,
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:27,代码来源:EMA.py

示例3: _addOne

    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
            )
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:29,代码来源:AdaBBands.py

示例4: __init__

    def __init__(
            self,
            _data: DataStruct,
            _stop_type: int,
            _stop_rate: float = 0.05,
            _use_key: str = 'closeprice',
            _idx_key: str = 'time',
            _ret_key: str = 'stopprice',
    ):
        super().__init__()

        assert len(_data) == 1

        self.stop_type = _stop_type
        self.stop_rate = _stop_rate
        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key

        price = _data[self.use_key][0]
        if self.stop_type == SignalType.LONG:
            stop_price = price * (1 - self.stop_rate)
        elif self.stop_type == SignalType.SHORT:
            stop_price = price * (1 + self.stop_rate)
        else:
            raise Exception('unknown type')
        time = _data.index()[0]

        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key,
            [[time, stop_price]]
        )
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:33,代码来源:RateConstStop.py

示例5: BBands

class BBands(IndicatorAbstract):
    def __init__(
            self, _period: int = 26, _use_key: str = 'closeprice',
            _rate: float = 2.0, _idx_key: str = 'time',
            _ret_key=('upband', 'midband', 'downband')
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.keys = [self.idx_key] + list(_ret_key)

        self.data = DataStruct(
            self.keys, self.idx_key
        )

        self.period = _period
        self.rate = _rate
        self.buf = deque(maxlen=self.period)

    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)
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:28,代码来源:BBands.py

示例6: __init__

    def __init__(
            self,
            _data: DataStruct,
            _stop_type: int,
            _stop_rate: float = 0.05,
            _use_key: str = 'closeprice',
            _idx_key: str = 'time',
            _ret_key: str = 'stopprice',
    ):
        super().__init__()

        assert len(_data) == 1

        self.stop_type = _stop_type
        self.stop_rate = _stop_rate
        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key

        self.best_price = _data.toDict()[self.use_key]

        time = _data.index()[0]

        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key,
            [[time, self.get_stop_price()]]
        )
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:28,代码来源:RateTrailingStop.py

示例7: _addOne

 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),
     })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:7,代码来源:STD.py

示例8: BIAS

class BIAS(IndicatorAbstract):
    """
    rolling ma
    """

    def __init__(
            self, _period: int, _use_key: str = 'closeprice',
            _idx_key: str = 'time', _ret_key: str = 'bias'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.period = _period
        self.buf = deque(maxlen=self.period)

    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        price = _data_struct[self.use_key][0]

        self.buf.append(price)
        price_mean = statistics.mean(self.buf)

        self.data.addDict({
            self.idx_key: index_value,
            self.ret_key: (price - price_mean) / price_mean * 100,
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:33,代码来源:BIAS.py

示例9: SharpRate

class SharpRate(IndicatorAbstract):
    def __init__(
            self, _period: int, _use_key: str = 'closeprice',
            _idx_key: str = 'time', _ret_key: str = 'sharprate',
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.last_price = None
        self.period = _period
        self.buf = deque(maxlen=self.period)

    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        price_value = _data_struct[self.use_key][0]
        if self.last_price is not None:
            chg_rate = price_value / self.last_price - 1
            self.buf.append(chg_rate)
            buf_std = statistics.pstdev(self.buf)
            if buf_std != 0:
                self.data.addDict({
                    self.idx_key: index_value,
                    self.ret_key: statistics.mean(self.buf) / buf_std,
                })
        self.last_price = price_value
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:32,代码来源:SharpRate.py

示例10: STD

class STD(IndicatorAbstract):
    def __init__(
            self, _period: int, _use_key: str = 'closeprice',
            _idx_key: str = 'time', _ret_key: str = 'std'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.period = _period
        self.buf = deque(maxlen=self.period)

    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),
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:25,代码来源:STD.py

示例11: ATRConstStop

class ATRConstStop(StopIndicatorAbstract):
    def __init__(
            self,
            _price_data: DataStruct,
            _atr_data: DataStruct,
            _stop_type: int,
            _rate: float = 3,
            _price_use_key: str = 'closeprice',
            _atr_use_key: str = 'atr',
            _idx_key: str = 'time',
            _ret_key: str = 'stopprice',
    ):
        super().__init__()

        assert len(_price_data) == 1
        assert len(_atr_data) == 1

        self.stop_type = _stop_type
        self.rate = _rate
        self.price_use_key = _price_use_key
        self.atr_use_key = _atr_use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key

        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key,
        )

        price_value = _price_data[self.price_use_key][0]
        atr_value = _atr_data[self.atr_use_key][0]

        if self.stop_type == SignalType.LONG:
            self.stopprice = price_value - self.rate * atr_value
        elif self.stop_type == SignalType.SHORT:
            self.stopprice = price_value + self.rate * atr_value
        else:
            raise Exception('unknown type')

        self._addOne(_price_data)

    def _addOne(
            self, _price_data: DataStruct,
    ):
        self.data.addDict({
            self.idx_key: _price_data.index()[0],
            self.ret_key: self.stopprice,
        })

    def _isStop(self, _data_struct: DataStruct):
        price = _data_struct.toDict()[self.price_use_key]
        stop_price = self.data[self.ret_key][-1]
        if self.stop_type == SignalType.LONG:
            if price < stop_price:
                self.is_stop = True
        elif self.stop_type == SignalType.SHORT:
            if price > stop_price:
                self.is_stop = True
        else:
            raise Exception('unknown type')
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:60,代码来源:ATRConstStop.py

示例12: EFF

class EFF(IndicatorAbstract):
    def __init__(
            self, _period: int, _use_key: str = 'closeprice',
            _idx_key: str = 'time', _ret_key: str = 'eff'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.period = _period
        self.buf = deque(maxlen=self.period)

    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,
            })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:30,代码来源:EFF.py

示例13: Kurtosis

class Kurtosis(IndicatorAbstract):

    def __init__(
            self, _period: int, _use_key: str = 'closeprice',
            _idx_key: str = 'time', _ret_key: str = 'kurtosis'
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.period = _period
        self.last_price = None
        self.buf = deque(maxlen=self.period)

    def _addOne(self, _data_struct: DataStruct):
        index = _data_struct.index()[0]
        price = _data_struct[self.use_key][0]
        if self.last_price:
            self.buf.append(math.log(price / self.last_price))
            if len(self.buf) >= self.period:
                self.data.addDict({
                    self.idx_key: index,
                    self.ret_key: kurtosis(self.buf),
                })
        self.last_price = price
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:31,代码来源:Kurtosis.py

示例14: FastVolatility

class FastVolatility(IndicatorAbstract):
    def __init__(
            self, _period: int,
            _factor: int = 1,
            _smooth: int = 1,
            _use_key: str = 'closeprice',
            _idx_key: str = 'time',
            _ret_key: str = 'volatility',
    ):
        super().__init__()

        self.use_key = _use_key
        self.idx_key = _idx_key
        self.ret_key = _ret_key
        self.data = DataStruct(
            [self.idx_key, self.ret_key],
            self.idx_key
        )

        self.last_price = None
        self.period = _period
        self.factor = math.sqrt(_factor)
        self.smooth = _smooth

        self.buf = deque(maxlen=self.period)
        self.mean = 0.0
        self.sum_of_pow = 0.0

    def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        price_value = _data_struct[self.use_key][0]
        if self.last_price is not None:
            chg_rate = price_value / self.last_price - 1

            if len(self.buf) >= self.period:
                last_value = self.buf.popleft()
                self.buf.append(chg_rate)
                self.sum_of_pow += chg_rate ** 2
                self.sum_of_pow -= last_value ** 2
                self.mean += (chg_rate - last_value) / self.period
            else:
                n = len(self.buf)
                self.buf.append(chg_rate)
                self.sum_of_pow += chg_rate ** 2
                self.mean = (self.mean * n + chg_rate) / len(self.buf)

            var = self.sum_of_pow / len(self.buf) - self.mean ** 2
            std_value = math.sqrt(max(0.0, var)) * self.factor
            if self.smooth > 1 and len(self.data):
                last_std_value = self.data[self.ret_key][-1]
                std_value = (
                    (self.smooth - 1) * last_std_value + std_value
                ) / self.smooth

            self.data.addDict({
                self.idx_key: index_value,
                self.ret_key: std_value,
            })
        self.last_price = price_value
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:59,代码来源:FastVolatility.py

示例15: _addOne

 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)
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:8,代码来源:BBands.py


注:本文中的ParadoxTrading.Utils.DataStruct类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。