本文整理汇总了Python中pytdx.hq.TdxHq_API.get_security_bars方法的典型用法代码示例。如果您正苦于以下问题:Python TdxHq_API.get_security_bars方法的具体用法?Python TdxHq_API.get_security_bars怎么用?Python TdxHq_API.get_security_bars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytdx.hq.TdxHq_API
的用法示例。
在下文中一共展示了TdxHq_API.get_security_bars方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QA_fetch_get_index_min
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_index_min(code, start, end, level='1min', ip=best_ip, port=7709):
api = TdxHq_API()
type_ = ''
if str(level) in ['5', '5m', '5min', 'five']:
level, type_ = 0, '5min'
elif str(level) in ['1', '1m', '1min', 'one']:
level, type_ = 8, '1min'
elif str(level) in ['15', '15m', '15min', 'fifteen']:
level, type_ = 1, '15min'
elif str(level) in ['30', '30m', '30min', 'half']:
level, type_ = 2, '30min'
elif str(level) in ['60', '60m', '60min', '1h']:
level, type_ = 3, '60min'
with api.connect(ip, port):
if str(code)[0] in ['5', '1']: # ETF
data = pd.concat([api.to_df(api.get_security_bars(
level, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (25 - i) * 800, 800)) for i in range(26)], axis=0)
else:
data = pd.concat([api.to_df(api.get_index_bars(
level, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (25 - i) * 800, 800)) for i in range(26)], axis=0)
data = data\
.assign(datetime=pd.to_datetime(data['datetime']), code=str(code))\
.drop(['year', 'month', 'day', 'hour', 'minute'], axis=1, inplace=False)\
.assign(date=data['datetime'].apply(lambda x: str(x)[0:10]))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(x)))\
.assign(time_stamp=data['datetime'].apply(lambda x: QA_util_time_stamp(x)))\
.assign(type=type_).set_index('datetime', drop=False, inplace=False)[start:end]
# data
return data.assign(datetime=data['datetime'].apply(lambda x: str(x)))
示例2: _get_bars
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def _get_bars(self, market, code, ktype):
data = []
tdx_market = self._trans_market(market)
if tdx_market is None:
print("tdx_market == None")
return data
tdx_ktype = self._trans_ktype(ktype)
if tdx_ktype is None:
print("tdx_ktype == None")
return data
try:
ip = self.getParam('ip')
port = self.getParam('port')
except:
ip = '119.147.212.81'
port = 7709
api = TdxHq_API(raise_exception=True)
with api.connect(ip, port):
if (market == 'SH' and code[:3] == '000') \
or (market == 'SZ' and code[:2] == '39'):
for i in range(self._max[ktype]):
data += api.get_index_bars(tdx_ktype, tdx_market, code,
(self._max[ktype]-1-i)*800,800)
else:
for i in range(self._max[ktype]):
data += api.get_security_bars(tdx_ktype, tdx_market, code,
(self._max[ktype]-1-i)*800,800)
return data
示例3: QA_fetch_get_index_day
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_index_day(code, start_date, end_date, level='day', ip=best_ip, port=7709):
'指数日线'
api = TdxHq_API()
if level in ['day', 'd', 'D', 'DAY', 'Day']:
level = 9
elif level in ['w', 'W', 'Week', 'week']:
level = 5
elif level in ['month', 'M', 'm', 'Month']:
level = 6
elif level in ['Q', 'Quarter', 'q']:
level = 10
elif level in ['y', 'Y', 'year', 'Year']:
level = 11
with api.connect(ip, port):
if str(code)[0] in ['5', '1']: # ETF
data = pd.concat([api.to_df(api.get_security_bars(
level, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (25 - i) * 800, 800)) for i in range(26)], axis=0)
else:
data = pd.concat([api.to_df(api.get_index_bars(
level, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (25 - i) * 800, 800)) for i in range(26)], axis=0)
data = data.assign(date=data['datetime'].apply(lambda x: str(x[0:10]))).assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10])))\
.set_index('date', drop=False, inplace=False)\
.drop(['year', 'month', 'day', 'hour',
'minute', 'datetime'], axis=1)[start_date:end_date]
return data.assign(date=data['date'].apply(lambda x: str(x)[0:10]))
示例4: QA_fetch_get_index_min
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_index_min(code, start, end, frequence='1min', ip=None, port=None):
'指数分钟线'
global best_ip
if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
best_ip = select_best_ip()
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
else:
pass
api = TdxHq_API()
type_ = ''
start_date = str(start)[0:10]
today_ = datetime.date.today()
lens = QA_util_get_trade_gap(start_date, today_)
if str(frequence) in ['5', '5m', '5min', 'five']:
frequence, type_ = 0, '5min'
lens = 48 * lens
elif str(frequence) in ['1', '1m', '1min', 'one']:
frequence, type_ = 8, '1min'
lens = 240 * lens
elif str(frequence) in ['15', '15m', '15min', 'fifteen']:
frequence, type_ = 1, '15min'
lens = 16 * lens
elif str(frequence) in ['30', '30m', '30min', 'half']:
frequence, type_ = 2, '30min'
lens = 8 * lens
elif str(frequence) in ['60', '60m', '60min', '1h']:
frequence, type_ = 3, '60min'
lens = 4 * lens
if lens > 20800:
lens = 20800
with api.connect(ip, port):
if str(code)[0] in ['5', '1']: # ETF
data = pd.concat([api.to_df(api.get_security_bars(
frequence, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)
else:
data = pd.concat([api.to_df(api.get_index_bars(
frequence, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)
data = data\
.assign(datetime=pd.to_datetime(data['datetime']), code=str(code))\
.drop(['year', 'month', 'day', 'hour', 'minute'], axis=1, inplace=False)\
.assign(code=code)\
.assign(date=data['datetime'].apply(lambda x: str(x)[0:10]))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(x)))\
.assign(time_stamp=data['datetime'].apply(lambda x: QA_util_time_stamp(x)))\
.assign(type=type_).set_index('datetime', drop=False, inplace=False)[start:end]
# data
return data.assign(datetime=data['datetime'].apply(lambda x: str(x)))
示例5: QA_fetch_get_stock_latest
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_stock_latest(code, ip=best_ip, port=7709):
code = [code] if isinstance(code, str) else code
api = TdxHq_API(multithread=True)
with api.connect(ip, port):
data = pd.concat([api.to_df(api.get_security_bars(
9, __select_market_code(item), item, 0, 1)).assign(code=item) for item in code], axis=0)
return data\
.assign(date=pd.to_datetime(data['datetime']
.apply(lambda x: x[0:10])), date_stamp=data['datetime']
.apply(lambda x: QA_util_date_stamp(str(x[0:10]))))\
.set_index('date', drop=False)\
.drop(['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)
示例6: ping
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def ping(ip, port=7709, multithread=False):
api = TdxHq_API(multithread=multithread)
success = False
starttime = time.time()
try:
with api.connect(ip, port, time_out=1):
#x = api.get_security_count(0)
#x = api.get_index_bars(7, 1, '000001', 800, 100)
x = api.get_security_bars(7, 0, '000001', 800, 100)
if x:
success = True
except Exception as e:
success = False
endtime = time.time()
return (success, endtime - starttime, ip, port)
示例7: QA_fetch_get_index_day
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_index_day(code, start_date, end_date, frequence='day', ip=None, port=None):
'指数日线'
global best_ip
if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
best_ip = select_best_ip()
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
else:
pass
api = TdxHq_API()
if frequence in ['day', 'd', 'D', 'DAY', 'Day']:
frequence = 9
elif frequence in ['w', 'W', 'Week', 'week']:
frequence = 5
elif frequence in ['month', 'M', 'm', 'Month']:
frequence = 6
elif frequence in ['Q', 'Quarter', 'q']:
frequence = 10
elif frequence in ['y', 'Y', 'year', 'Year']:
frequence = 11
with api.connect(ip, port):
start_date = str(start_date)[0:10]
today_ = datetime.date.today()
lens = QA_util_get_trade_gap(start_date, today_)
if str(code)[0] in ['5', '1']: # ETF
data = pd.concat([api.to_df(api.get_security_bars(
frequence, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)
else:
data = pd.concat([api.to_df(api.get_index_bars(
frequence, 1 if str(code)[0] in ['0', '8', '9', '5'] else 0, code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)
data = data.assign(date=data['datetime'].apply(lambda x: str(x[0:10]))).assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10])))\
.set_index('date', drop=False, inplace=False)\
.assign(code=code)\
.drop(['year', 'month', 'day', 'hour',
'minute', 'datetime'], axis=1)[start_date:end_date]
return data.assign(date=data['date'].apply(lambda x: str(x)[0:10]))
示例8: QA_fetch_get_security_bars
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_security_bars(code, _type, lens, ip=None, port=None):
"""按bar长度推算数据
Arguments:
code {[type]} -- [description]
_type {[type]} -- [description]
lens {[type]} -- [description]
Keyword Arguments:
ip {[type]} -- [description] (default: {best_ip})
port {[type]} -- [description] (default: {7709})
Returns:
[type] -- [description]
"""
global best_ip
if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
best_ip = select_best_ip()
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
else:
pass
api = TdxHq_API()
with api.connect(ip, port):
data = pd.concat([api.to_df(api.get_security_bars(_select_type(_type), _select_market_code(
code), code, (i - 1) * 800, 800)) for i in range(1, int(lens / 800) + 2)], axis=0)
data = data\
.assign(datetime=pd.to_datetime(data['datetime']), code=str(code))\
.drop(['year', 'month', 'day', 'hour', 'minute'], axis=1, inplace=False)\
.assign(date=data['datetime'].apply(lambda x: str(x)[0:10]))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(x)))\
.assign(time_stamp=data['datetime'].apply(lambda x: QA_util_time_stamp(x)))\
.assign(type=_type).set_index('datetime', drop=False, inplace=False).tail(lens)
if data is not None:
return data
else:
return None
示例9: QA_fetch_get_stock_latest
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_stock_latest(code, ip=None, port=None):
global best_ip
if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
best_ip = select_best_ip()
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
else:
pass
code = [code] if isinstance(code, str) else code
api = TdxHq_API(multithread=True)
with api.connect(ip, port):
data = pd.concat([api.to_df(api.get_security_bars(
9, _select_market_code(item), item, 0, 1)).assign(code=item) for item in code], axis=0)
return data\
.assign(date=pd.to_datetime(data['datetime']
.apply(lambda x: x[0:10])), date_stamp=data['datetime']
.apply(lambda x: QA_util_date_stamp(str(x[0:10]))))\
.set_index('date', drop=False)\
.drop(['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)
示例10: test_all_functions
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def test_all_functions(multithread, heartbeat, auto_retry, raise_exception):
api = TdxHq_API(multithread=multithread, heartbeat=heartbeat,
auto_retry=auto_retry, raise_exception=raise_exception)
with api.connect(time_out=30):
log.info("获取股票行情")
stocks = api.get_security_quotes([(0, "000001"), (1, "600300")])
assert stocks is not None
assert type(stocks) is list
# 方法2
stocks = api.get_security_quotes(0, "000001")
assert stocks is not None
assert type(stocks) is list
# 方法3
stocks = api.get_security_quotes((0, "000001"))
assert stocks is not None
assert type(stocks) is list
log.info("获取k线")
data = api.get_security_bars(9, 0, '000001', 4, 3)
assert data is not None
assert type(data) is list
assert len(data) == 3
log.info("获取 深市 股票数量")
assert api.get_security_count(0) > 0
log.info("获取股票列表")
stocks = api.get_security_list(1, 0)
assert stocks is not None
assert type(stocks) is list
assert len(stocks) > 0
log.info("获取指数k线")
data = api.get_index_bars(9, 1, '000001', 1, 2)
assert data is not None
assert type(data) is list
assert len(data) == 2
log.info("查询分时行情")
data = api.get_minute_time_data(TDXParams.MARKET_SH, '600300')
assert data is not None
log.info("查询历史分时行情")
data = api.get_history_minute_time_data(
TDXParams.MARKET_SH, '600300', 20161209)
assert data is not None
assert type(data) is list
assert len(data) > 0
log.info("查询分时成交")
data = api.get_transaction_data(TDXParams.MARKET_SZ, '000001', 0, 30)
assert data is not None
assert type(data) is list
log.info("查询历史分时成交")
data = api.get_history_transaction_data(
TDXParams.MARKET_SZ, '000001', 0, 10, 20170209)
assert data is not None
assert type(data) is list
assert len(data) == 10
log.info("查询公司信息目录")
data = api.get_company_info_category(TDXParams.MARKET_SZ, '000001')
assert data is not None
assert type(data) is list
assert len(data) > 0
start = data[0]['start']
length = data[0]['length']
log.info("读取公司信息-最新提示")
data = api.get_company_info_content(
0, '000001', '000001.txt', start, length)
assert data is not None
assert len(data) > 0
log.info("读取除权除息信息")
data = api.get_xdxr_info(1, '600300')
assert data is not None
assert type(data) is list
assert len(data) > 0
log.info("读取财务信息")
data = api.get_finance_info(0, '000001')
assert data is not None
assert type(data) is OrderedDict
assert len(data) > 0
log.info("日线级别k线获取函数")
data = api.get_k_data('000001', '2017-07-01', '2017-07-10')
assert type(data) is pd.DataFrame
assert len(data) == 6
log.info("获取板块信息")
data = api.get_and_parse_block_info(TDXParams.BLOCK_FG)
assert data is not None
assert type(data) is list
#.........这里部分代码省略.........
示例11: QA_fetch_get_stock_day
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_stock_day(code, start_date, end_date, if_fq='00', frequence='day', ip=None, port=None):
"""获取日线及以上级别的数据
Arguments:
code {str:6} -- code 是一个单独的code 6位长度的str
start_date {str:10} -- 10位长度的日期 比如'2017-01-01'
end_date {str:10} -- 10位长度的日期 比如'2018-01-01'
Keyword Arguments:
if_fq {str} -- '00'/'bfq' -- 不复权 '01'/'qfq' -- 前复权 '02'/'hfq' -- 后复权 '03'/'ddqfq' -- 定点前复权 '04'/'ddhfq' --定点后复权
frequency {str} -- day/week/month/quarter/year 也可以是简写 D/W/M/Q/Y
ip {str} -- [description] (default: None) ip可以通过select_best_ip()函数重新获取
port {int} -- [description] (default: {None})
Returns:
pd.DataFrame/None -- 返回的是dataframe,如果出错比如只获取了一天,而当天停牌,返回None
Exception:
如果出现网络问题/服务器拒绝, 会出现socket:time out 尝试再次获取/更换ip即可, 本函数不做处理
"""
global best_ip
if ip is None and port is None and best_ip['stock']['ip'] is None and best_ip['stock']['port'] is None:
best_ip = select_best_ip()
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
elif ip is None and port is None and best_ip['stock']['ip'] is not None and best_ip['stock']['port'] is not None:
ip = best_ip['stock']['ip']
port = best_ip['stock']['port']
else:
pass
api = TdxHq_API()
with api.connect(ip, port, time_out=0.7):
if frequence in ['day', 'd', 'D', 'DAY', 'Day']:
frequence = 9
elif frequence in ['w', 'W', 'Week', 'week']:
frequence = 5
elif frequence in ['month', 'M', 'm', 'Month']:
frequence = 6
elif frequence in ['quarter', 'Q', 'Quarter', 'q']:
frequence = 10
elif frequence in ['y', 'Y', 'year', 'Year']:
frequence = 11
start_date = str(start_date)[0:10]
today_ = datetime.date.today()
lens = QA_util_get_trade_gap(start_date, today_)
data = pd.concat([api.to_df(api.get_security_bars(frequence, _select_market_code(
code), code, (int(lens / 800) - i) * 800, 800)) for i in range(int(lens / 800) + 1)], axis=0)
# 这里的问题是: 如果只取了一天的股票,而当天停牌, 那么就直接返回None了
if len(data) < 1:
return None
data = data[data['open'] != 0]
if if_fq in ['00', 'bfq']:
data = data.assign(date=data['datetime'].apply(lambda x: str(x[0:10]))).assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10]))).set_index('date', drop=False, inplace=False)
return data.drop(['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)[start_date:end_date].assign(date=data['date'].apply(lambda x: str(x)[0:10]))
elif if_fq in ['01', 'qfq']:
xdxr_data = QA_fetch_get_stock_xdxr(code)
bfq_data = data.assign(date=pd.to_datetime(data['datetime'].apply(lambda x: str(x[0:10])))).assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10]))).set_index('date', drop=False, inplace=False)
bfq_data = bfq_data.drop(
['year', 'month', 'day', 'hour', 'minute', 'datetime'], axis=1)
#
if xdxr_data is not None:
info = xdxr_data[xdxr_data['category'] == 1]
bfq_data['if_trade'] = True
data = pd.concat([bfq_data, info[['category']]
[bfq_data.index[0]:]], axis=1)
data['date'] = data.index
data['if_trade'].fillna(value=False, inplace=True)
data = data.fillna(method='ffill')
data = pd.concat([data, info[['fenhong', 'peigu', 'peigujia',
'songzhuangu']][bfq_data.index[0]:]], axis=1)
data = data.fillna(0)
data['preclose'] = (data['close'].shift(1) * 10 - data['fenhong'] + data['peigu']
* data['peigujia']) / (10 + data['peigu'] + data['songzhuangu'])
data['adj'] = (data['preclose'].shift(-1) /
data['close']).fillna(1)[::-1].cumprod()
data['open'] = data['open'] * data['adj']
data['high'] = data['high'] * data['adj']
data['low'] = data['low'] * data['adj']
data['close'] = data['close'] * data['adj']
data['preclose'] = data['preclose'] * data['adj']
data = data[data['if_trade']]
return data.drop(['fenhong', 'peigu', 'peigujia', 'songzhuangu', 'if_trade', 'category'], axis=1)[data['open'] != 0].assign(date=data['date'].apply(lambda x: str(x)[0:10]))[start_date:end_date]
else:
bfq_data['preclose'] = bfq_data['close'].shift(1)
bfq_data['adj'] = 1
#.........这里部分代码省略.........
示例12: QA_fetch_get_stock_day
# 需要导入模块: from pytdx.hq import TdxHq_API [as 别名]
# 或者: from pytdx.hq.TdxHq_API import get_security_bars [as 别名]
def QA_fetch_get_stock_day(code, start_date, end_date, if_fq='00', level='day', ip=best_ip, port=7709):
api = TdxHq_API()
with api.connect(ip, port):
if level in ['day', 'd', 'D', 'DAY', 'Day']:
level = 9
elif level in ['w', 'W', 'Week', 'week']:
level = 5
elif level in ['month', 'M', 'm', 'Month']:
level = 6
elif level in ['Q', 'Quarter', 'q']:
level = 10
elif level in ['y', 'Y', 'year', 'Year']:
level = 11
data = pd.concat([api.to_df(api.get_security_bars(level, __select_market_code(
code), code, (9 - i) * 800, 800)) for i in range(10)], axis=0)
if if_fq in ['00', 'bfq']:
data = data.assign(date=data['datetime'].apply(lambda x: str(x[0:10]))).assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10])))\
.set_index('date', drop=False, inplace=False)\
.drop(['year', 'month', 'day', 'hour',
'minute', 'datetime'], axis=1)[start_date:end_date]
return data.assign(date=data['date'].apply(lambda x: str(x)[0:10]))
elif if_fq in ['01', 'qfq']:
xdxr_data = QA_fetch_get_stock_xdxr(code)
info = xdxr_data[xdxr_data['category'] == 1]
bfq_data = data\
.assign(date=pd.to_datetime(data['datetime'].apply(lambda x: x[0:10])))\
.assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10])))\
.set_index('date', drop=False, inplace=False)\
.drop(['year', 'month', 'day', 'hour',
'minute', 'datetime'], axis=1)
bfq_data['if_trade']=True
data = pd.concat([bfq_data, info[['category']]
[bfq_data.index[0]:]], axis=1)
data['date'] = data.index
data['if_trade'].fillna(value=False, inplace=True)
data = data.fillna(method='ffill')
data = pd.concat([data, info[['fenhong', 'peigu', 'peigujia',
'songzhuangu']][bfq_data.index[0]:]], axis=1)
data = data.fillna(0)
data['preclose'] = (data['close'].shift(1) * 10 - data['fenhong'] + data['peigu']
* data['peigujia']) / (10 + data['peigu'] + data['songzhuangu'])
data['adj'] = (data['preclose'].shift(-1) /
data['close']).fillna(1)[::-1].cumprod()
data['open'] = data['open'] * data['adj']
data['high'] = data['high'] * data['adj']
data['low'] = data['low'] * data['adj']
data['close'] = data['close'] * data['adj']
data['preclose'] = data['preclose'] * data['adj']
data = data[data['if_trade']]
return data.drop(['fenhong', 'peigu', 'peigujia', 'songzhuangu', 'if_trade', 'category'], axis=1)[data['open'] != 0].assign(date=data['date'].apply(lambda x: str(x)[0:10]))[start_date:end_date]
elif if_fq in ['03', 'ddqfq']:
xdxr_data = QA_fetch_get_stock_xdxr(code)
info = xdxr_data[xdxr_data['category'] == 1]
bfq_data = data\
.assign(date=pd.to_datetime(data['datetime'].apply(lambda x: x[0:10])))\
.assign(code=str(code))\
.assign(date_stamp=data['datetime'].apply(lambda x: QA_util_date_stamp(str(x)[0:10])))\
.set_index('date', drop=False, inplace=False)\
.drop(['year', 'month', 'day', 'hour',
'minute', 'datetime'], axis=1)
bfq_data['if_trade']=True
data = pd.concat([bfq_data, info[['category']]
[bfq_data.index[0]:end_date]], axis=1)
data['date'] = data.index
data['if_trade'].fillna(value=False, inplace=True)
data = data.fillna(method='ffill')
data = pd.concat([data, info[['fenhong', 'peigu', 'peigujia',
'songzhuangu']][bfq_data.index[0]:end_date]], axis=1)
data = data.fillna(0)
data['preclose'] = (data['close'].shift(1) * 10 - data['fenhong'] + data['peigu']
* data['peigujia']) / (10 + data['peigu'] + data['songzhuangu'])
data['adj'] = (data['preclose'].shift(-1) /
data['close']).fillna(1)[::-1].cumprod()
data['open'] = data['open'] * data['adj']
data['high'] = data['high'] * data['adj']
data['low'] = data['low'] * data['adj']
data['close'] = data['close'] * data['adj']
data['preclose'] = data['preclose'] * data['adj']
data = data[data['if_trade']]
return data.drop(['fenhong', 'peigu', 'peigujia', 'songzhuangu', 'if_trade', 'category'], axis=1)[data['open'] != 0].assign(date=data['date'].apply(lambda x: str(x)[0:10]))[start_date:end_date]
elif if_fq in ['02', 'hfq']:
xdxr_data = QA_fetch_get_stock_xdxr(code)
#.........这里部分代码省略.........