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


Python DataStruct.index方法代码示例

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


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

示例1: __init__

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    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,代码行数:35,代码来源:RateConstStop.py

示例2: __init__

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    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,代码行数:30,代码来源:RateTrailingStop.py

示例3: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    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,代码行数:33,代码来源:FastVolatility.py

示例4: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 def _addOne(
         self, _price_data: DataStruct,
 ):
     self.data.addDict({
         self.idx_key: _price_data.index()[0],
         self.ret_key: self.stopprice,
     })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:9,代码来源:ATRConstStop.py

示例5: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    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,代码行数:31,代码来源:AdaBBands.py

示例6: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    def _addOne(self, _data_struct: DataStruct):
        index = _data_struct.index()[0]
        price = _data_struct[self.use_key][0]

        if self.last_price is not None:
            rate = math.log(price) - math.log(self.last_price)
            if self.new_mean is not None:
                self.new_info = rate - self.new_mean
            self.return_buf.append(rate)

            self.fit_count += 1  # retrain model
            if self.fit_count > self.fit_period and \
                    len(self.return_buf) >= self.fit_begin:
                self.model.fit(self.return_buf)
                self.phi = self.model.getPhis()[0]
                self.theta = self.model.getThetas()[0]
                self.alpha = self.model.getAlphas()[0]
                self.beta = self.model.getBetas()[0]
                self.const = self.model.getConst()[0]
                self.new_info = self.model.latent_arma_arr[-1]
                self.new_var = self.model.latent_garch_arr[-1]
                self.fit_count = 0

            if self.new_info is not None:  # predict value
                self.new_mean = self.phi * rate + self.theta * self.new_info
                self.new_var = self.alpha * self.new_info ** 2 + \
                               self.beta * self.new_var + self.const
                self.data.addDict({
                    self.idx_key: index,
                    self.ret_key[0]: self.new_mean,
                    self.ret_key[1]: math.sqrt(self.new_var),
                })

        self.last_price = price
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:36,代码来源:ARMAGARCH.py

示例7: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 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,代码行数:9,代码来源:STD.py

示例8: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 def _addOne(self, _data_struct: DataStruct):
     self.high_buf.append(_data_struct[self.high_key][0])
     self.low_buf.append(_data_struct[self.low_key][0])
     closeprice = _data_struct[self.close_key][0]
     if self.last_close_price is not None:
         index_value = _data_struct.index()[0]
         # atr
         tr_value = max(
             _data_struct[self.high_key][0], self.last_close_price
         ) - min(_data_struct[self.low_key][0], self.last_close_price)
         self.atr_buf.append(tr_value)
         atr_value = sum(self.atr_buf) / len(self.atr_buf)
         # ema
         self.fast_ema_value = (closeprice - self.fast_ema_value) / \
                               self.fast_ema_period + self.fast_ema_value
         self.slow_ema_value = (closeprice - self.slow_ema_value) / \
                               self.slow_ema_period + self.slow_ema_value
         # plunge
         if self.fast_ema_value > self.slow_ema_value:
             plunge_value = (max(self.high_buf) - closeprice) / atr_value
         elif self.fast_ema_value < self.slow_ema_value:
             plunge_value = (closeprice - min(self.low_buf)) / atr_value
         else:
             plunge_value = 0.0
         self.ret_buf.append(plunge_value)
         self.data.addDict({
             self.idx_key: index_value,
             self.ret_key: sum(self.ret_buf) / len(self.ret_buf),
         })
     else:
         self.fast_ema_value = closeprice
         self.slow_ema_value = closeprice
     self.last_close_price = closeprice
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:35,代码来源:Plunge.py

示例9: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    def _addOne(
            self, _price_data: DataStruct,
            _atr_data: DataStruct = None,
    ):
        assert len(_atr_data) == 1

        price = _price_data.toDict()[self.price_use_key]
        atr = _atr_data.toDict()[self.atr_use_key]

        price_time = _price_data.index()[0]
        atr_time = _atr_data.index()[0]
        assert price_time == atr_time

        self.data.addDict({
            self.idx_key: price_time,
            self.ret_key: self.get_stop_price(price, atr),
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:19,代码来源:ATRTrailingStop.py

示例10: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    def _addOne(self, _data_struct: DataStruct):
        stop_price = self.data[self.ret_key][-1]
        time = _data_struct.index()[0]

        self.data.addDict({
            self.idx_key: time,
            self.ret_key: stop_price,
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:10,代码来源:RateConstStop.py

示例11: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
    def _addOne(
            self, _price_data: DataStruct,
            _volatility_data: DataStruct = None,
    ):
        assert len(_volatility_data) == 1

        price = _price_data.toDict()[self.price_use_key]
        volatility = _volatility_data.toDict()[self.volatility_use_key]

        price_time = _price_data.index()[0]
        volatility_time = _volatility_data.index()[0]
        assert price_time == volatility_time

        self.data.addDict({
            self.idx_key: price_time,
            self.ret_key: self.get_stop_price(price, volatility),
        })
开发者ID:neosun100,项目名称:ParadoxTrading,代码行数:19,代码来源:VolatilityTrailingStop.py

示例12: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 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,代码行数:10,代码来源:BBands.py

示例13: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 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,代码行数:12,代码来源:EMA.py

示例14: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 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,代码行数:13,代码来源:LogReturn.py

示例15: _addOne

# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import index [as 别名]
 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,代码行数:13,代码来源:Kurtosis.py


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