用python使用baostock接口定义一个函数,该函数可以通过输入股票代码找出该股票一年以内的的股价跳空缺口出现的日期和当日的股价详细数据
时间: 2023-03-11 09:18:50 浏览: 129
python实现弹跳小球
可以使用以下函数来实现:def find_price_gap(stock_code):
from baostock import BaosStock as bs
import pandas as pd
import numpy as np
# 通过输入股票代码,获取一年以内的股价
lg = bs.login()
rs = bs.query_history_k_data_plus(stock_code,
"date,code,open,high,low,close,preclose",
start_date='2019-01-01', end_date='2020-01-01',
frequency="d", adjustflag="3")
data_list = []
while (rs.error_code == '0') & rs.next():
data_list.append(rs.get_row_data())
result = pd.DataFrame(data_list, columns=rs.fields)
result = result.set_index('date')
result = result.sort_index(ascending=True)
lg.logout()
# 查找股价跳空缺口出现的日期和当日的股价详细数据
gaps = []
for i in range(1, len(result)):
if result.loc[result.index[i - 1], 'close'] > result.loc[result.index[i], 'high'] and result.loc[result.index[i - 1], 'open'] < result.loc[result.index[i], 'low']:
gaps.append([result.index[i], result.loc[result.index[i], 'open'], result.loc[result.index[i], 'high'], result.loc[result.index[i], 'low'], result.loc[result.index[i], 'close']])
return gaps
阅读全文