本文整理汇总了Python中quantdigger.datastruct.PContract.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python PContract.from_string方法的具体用法?Python PContract.from_string怎么用?Python PContract.from_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quantdigger.datastruct.PContract
的用法示例。
在下文中一共展示了PContract.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _load_data
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def _load_data(self, strpcons, dt_start, dt_end, n, spec_date):
all_data = OrderedDict()
max_window = -1
logger.info("loading data...")
pbar = ProgressBar().start()
pcontracts = [PContract.from_string(s) for s in strpcons]
pcontracts = sorted(pcontracts, reverse=True)
for i, pcon in enumerate(pcontracts):
strpcon = str(pcon)
if strpcon in spec_date:
dt_start = spec_date[strpcon][0]
dt_end = spec_date[strpcon][1]
assert(dt_start < dt_end)
if n:
wrapper = self._data_manager.get_last_bars(strpcon, n)
else:
wrapper = self._data_manager.get_bars(strpcon, dt_start, dt_end)
if len(wrapper) == 0:
continue
all_data[strpcon] = DataContext(wrapper)
max_window = max(max_window, len(wrapper))
pbar.update(i*100.0/len(strpcons))
# progressbar.log('')
if n:
assert(max_window <= n)
pbar.finish()
if len(all_data) == 0:
assert(False)
# @TODO raise
return all_data, max_window
示例2: import_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def import_bars(self, data_iter, strpcon):
""" 导入交易数据
Args:
data_iter (iteratorable object): 数据['datetime', 'open', 'close',
'high', 'low', 'volume']
strpcon (str): 周期合约字符串如, 'AA.SHFE-1.Minute'
"""
pcontract = PContract.from_string(strpcon)
self._src.import_bars(data_iter, pcontract)
示例3: __getitem__
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def __getitem__(self, strpcon):
""" 获取跨品种合约 """
## @TODO
#if type(strpcon) == str:
#pass
#self._cur_data_context = self._data_contexts[pcon]
## @TODO 字典,str做key
tt = PContract.from_string(strpcon)
for key, value in self._data_contexts.iteritems():
if str(key) == str(tt):
return value
示例4: get_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_bars(self, strpcon, dt_start, dt_end):
""" 获取本地历史数
Args:
strpcon (str): 周期合约
dt_start (datetime): 数据的开始时间
dt_end (datetime): 数据的结束时间
Returns:
SourceWrapper. 数据
"""
pcontract = PContract.from_string(strpcon)
return self._src.get_bars(pcontract, dt_start, dt_end)
示例5: data
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def data(self, strpcon=None):
""" 周期合约数据
Args:
strpcon (str): 周期合约,如'BB.SHFE-1.Minute'
Returns:
pd.DataFrame. 数据
"""
pcon = self._main_pcontract
if strpcon:
pcon = PContract.from_string(strpcon)
return self._dcontexts[pcon].raw_data
示例6: data
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def data(self, strpcon=None):
""" 周期合约数据, 只有向量运行才有意义。
Args:
strpcon (str): 周期合约,如'BB.SHFE-1.Minute'
Returns:
pd.DataFrame. 数据
"""
if series.g_rolling:
assert(False and '只有向量运行才存在数据')
pcon = self._main_pcontract
if strpcon:
pcon = PContract.from_string(strpcon)
return self._dcontexts[pcon].raw_data
示例7: get_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_bars(self, strpcon, dt_start, dt_end):
""" 获取本地历史数据
Args:
strpcon (str): 周期合约
dt_start (datetime): 数据的开始时间
dt_end (datetime): 数据的结束时间
Returns:
SourceWrapper. 数据
"""
pcontract = PContract.from_string(strpcon)
if pcontract.contract.exchange == 'stock':
return []
else:
return self._src.get_bars(pcontract, dt_start, dt_end)
示例8: indicators
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def indicators(self, j=None, strpcon=None):
""" 返回第j个策略的指标, 默认返回组合的所有指标。
Args:
j (int): 第j个策略
strpcon (str): 周期合约
Returns:
dict. {指标名:指标}
"""
pcon = PContract.from_string(strpcon) if strpcon else self._main_pcontract
if j != None:
return self._dcontexts[pcon].indicators[self.i][j]
rst = { }
for j in range(0, len(self._blts)):
rst.update(self._dcontexts[pcon].indicators[self.i][j])
return rst
示例9: load_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def load_bars(self, strpcon, dt_start, dt_end, window_size):
""" 获取本地历史数据
Args:
strpcon (str): 周期合约
dt_start (datetime): 数据的开始时间
dt_end (datetime): 数据的结束时间
window_size (int): 窗口大小,0表示大小为数据长度。
Returns:
SourceWrapper. 数据
"""
pcontract = PContract.from_string(strpcon)
if pcontract.contract.exch_type == 'stock':
return []
else:
return self._src.load_bars(pcontract, dt_start, dt_end, window_size);
示例10: set_symbols
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def set_symbols(pcons, window_size,
dt_start=datetime(1980,1,1),
dt_end=datetime(2100,1,1)):
""" 添加数据
Args:
pcons ([str,]): 周期合约数组
dt_start (str): 开始时间
dt_end (str): 结束
window_size (int): 序列数据的窗口大小
"""
global g_simulator
new_pcons = []
for pcon in pcons:
new_pcons.append(PContract.from_string(pcon))
g_simulator = ExecuteUnit(new_pcons, window_size, dt_start, dt_end)
return g_simulator
示例11: get_all_contracts
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_all_contracts(self):
# 模拟接口
data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
pcons = [PContract.from_string(d) for d in data]
contracts = [pcon.contract for pcon in pcons]
return serialize_all_contracts(contracts)
示例12: get_last_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_last_bars(self, strpcon, n):
pcontract = PContract.from_string(strpcon)
return self._src.get_last_bars(pcontract, n)
示例13: get_bars
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_bars(self, strpcon,
dt_start=DEFAULT_DT_START, dt_end=DEFAULT_DT_END):
pcontract = PContract.from_string(strpcon)
return self._src.get_bars(pcontract, dt_start, dt_end)
示例14: setUp
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def setUp(self):
cache = LocalFsCache(TestCache.CACHE_PATH)
self.src = _MockSource()
self.ds = CachedDatasource(self.src, cache)
self.pcontract = PContract.from_string('000001.SH-1.DAY')
示例15: get_all_pcontracts
# 需要导入模块: from quantdigger.datastruct import PContract [as 别名]
# 或者: from quantdigger.datastruct.PContract import from_string [as 别名]
def get_all_pcontracts(self):
# 模拟接口
data = ['CC.SHFE-1.MINUTE', 'BB.SHFE-1.MINUTE']
pcontracts = [PContract.from_string(d) for d in data]
return serialize_all_pcontracts(pcontracts)