本文整理汇总了Python中ParadoxTrading.Utils.DataStruct.toDict方法的典型用法代码示例。如果您正苦于以下问题:Python DataStruct.toDict方法的具体用法?Python DataStruct.toDict怎么用?Python DataStruct.toDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParadoxTrading.Utils.DataStruct
的用法示例。
在下文中一共展示了DataStruct.toDict方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [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()]]
)
示例2: _addOne
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [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),
})
示例3: _addOne
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [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),
})
示例4: _isStop
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [as 别名]
def _isStop(self, _data_struct: DataStruct):
price = _data_struct.toDict()[self.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')
示例5: _addOne
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [as 别名]
def _addOne(self, _data_struct: DataStruct):
price = _data_struct.toDict()[self.use_key]
if self.stop_type == SignalType.LONG:
self.best_price = max(price, self.best_price)
elif self.stop_type == SignalType.SHORT:
self.best_price = min(price, self.best_price)
else:
raise Exception('unknown type')
time = _data_struct.index()[0]
self.data.addDict({
self.idx_key: time,
self.ret_key: self.get_stop_price(),
})
示例6: addMarketEvent
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [as 别名]
def addMarketEvent(
self, _symbol: str, _data: DataStruct
) -> ReturnMarket:
"""
add new tick data into market register, and add event
:param _symbol:
:param _data:
:return:
"""
for k in self.symbol_dict[_symbol]:
# add event for each strategy if necessary
for strategy in self.register_dict[k].strategy_set:
self.engine.addEvent(MarketEvent(k, strategy, _symbol, _data))
logging.debug('Data({}) {}'.format(_symbol, _data.toDict()))
return ReturnMarket(_symbol, _data)
示例7: __init__
# 需要导入模块: from ParadoxTrading.Utils import DataStruct [as 别名]
# 或者: from ParadoxTrading.Utils.DataStruct import toDict [as 别名]
def __init__(
self,
_data: DataStruct,
_stop_type: int,
_init_stop: float = 0.05,
_profit_thresh: typing.Sequence[float] = (
0.1, 0.2, 0.3, 0.5
),
_stop_thresh: typing.Sequence[float] = (
1.0, 0.5, 0.3, 0.15
),
_use_key: str = 'closeprice',
_idx_key: str = 'time',
_status_key: str = 'status',
_ret_key: str = 'stopprice',
):
super().__init__()
assert len(_data) == 1
self.stop_type = _stop_type
self.status = 0
self.profit_thresh = _profit_thresh
self.stop_thresh = _stop_thresh
self.use_key = _use_key
self.idx_key = _idx_key
self.status_key = _status_key
self.ret_key = _ret_key
self.init_price = _data.toDict()[self.use_key]
if self.stop_type == SignalType.LONG:
self.init_stop_price = self.init_price * (1 - _init_stop)
elif self.stop_type == SignalType.SHORT:
self.init_stop_price = self.init_price * (1 + _init_stop)
else:
raise Exception('unknown type')
self.best_price = self.init_price
self.data = DataStruct(
[self.idx_key, self.status_key, self.ret_key],
self.idx_key,
[[_data.index()[0], self.status, self.init_stop_price]]
)