Hikyuu变量,数据类型

全局变量与常量定义

  全局常量

  Null值及证券类别

基础数据类型

  日期时间

  K线数据

  分时线数据

  分笔线数据

杂项或辅助

  函数

  

  枚举

1.全局变量(以下全局变量仅在 hikyuu 交互式工具中存在,hikyuu库中并无定义。)

hikyuu.sm  StockManager 的实例

hikyuu.blocka Block 实例,包含全部A股

hikyuu.blocksh Block 实例,包含全部沪市股票

hikyuu.blocksz Block 实例,包含全部深市股票

hikyuu.blockg Block 实例,包含全部创业板股票

 

2.Null值和证券类别

hikyuu.constant 全局常量, Constant 的实例,用于判断相关的 null 值及股票类型,如:

a = Datetime(201601010000)
if (a == constant.null_datetime ):
    print(True)

classhikyuu.Constant
  null_datetime 无效Datetime
  inf
  nan
  null_price 同 nan
  null_int 无效int
  null_size 无效size
  null_int64 无效int64
  pickle_support 是否支持 pickle
  STOCKTYPE_BLOCK 股票类型-板块
  STOCKTYPE_A 股票类型-A股
  STOCKTYPE_INDEX 股票类型-指数
  STOCKTYPE_B 股票类型-B股
  STOCKTYPE_FUND 股票类型-基金
  STOCKTYPE_ETF 股票类型-ETF
  STOCKTYPE_ND 股票类型-国债
  STOCKTYPE_BOND 股票类型-其他债券
  STOCKTYPE_GEM 股票类型-创业板
  STOCKTYPE_TMP 股票类型-临时CSV
3.基础数据类型-日期时间
  日期时间及其运算主要涉及 DatetimeTimeDelta
  两者及其相关运算规则可参考 python datetime 模块中的 datetime 和 timedelta 帮助, 并且两者可和 datetime、timedelta 相互转换,并直接进行运算操作。

  TimeDelta 的运算规则基本与 datetime.timedelta 相同。  

classhikyuu.Datetime

日期时间类(精确到微秒),通过以下方式构建:

  • 通过字符串:Datetime(“2010-1-1 10:00:00”)、Datetime(“2001-1-1”)、Datetime(“20010101”)、Datetime(“20010101T232359)
  • 通过 Python 的date:Datetime(date(2010,1,1))
  • 通过 Python 的datetime:Datetime(datetime(2010,1,1,10)
  • 通过 YYYYMMDDHHMM 或 YYYYMMDD 形式的整数:Datetime(201001011000)、Datetime(20010101)
  • Datetime(year, month, day, hour=0, minute=0, second=0, millisecond=0, microsecond=0)

获取日期列表参见: getDateRange()

获取交易日日期参见: StockManager.getTradingCalendar()

year 年,如果是 Null 将抛出异常
month 月,如果是 Null 将抛出异常
day 日,如果是 Null 将抛出异常
hour 时,如果是 Null 将抛出异常
minute 分,如果是 Null 将抛出异常
second 秒,如果是 Null 将抛出异常
millisecond 毫秒,如果是 Null 将抛出异常
microsecond 微秒,如果是 Null 将抛出异常
number YYYYMMDDHHMM 形式的整数,精度只到分钟
date(self)

转化生成 python 的 date

datetime(self)

转化生成 python 的datetime

is_null(self)

是否是Null值, 即是否等于 constant.null_datetime

__add__(selftd)

加上指定时长,时长对象可为 TimeDelta 或 datetime.timedelta 类型

参数: td (TimeDelta) – 时长
返回类型: Datetime
__sub__(selftd)

减去指定的时长, 时长对象可为 TimeDelta 或 datetime.timedelta 类型

参数: td (TimeDelta) – 指定时长
返回类型: Datetime
day_of_week(self)

返回是一周中的第几天,周日为0,周一为1

返回类型: int
date_of_week(selfday)

返回指定的本周中第几天的日期,周日为0天,周六为第6天

参数: day (int) – 指明本周的第几天,如小于则认为为第0天,如大于6则认为为第6天
返回类型: Datetime
day_of_year(self)

返回一年中的第几天,1月1日为一年中的第1天

返回类型: int
start_of_day(self)

返回当天 0点0分0秒

end_of_day(self)

返回当日 23点59分59秒

start_of_week(self)

返回周起始日期(周一)

end_of_week(self)

返回周结束日期(周日)

start_of_month(self)

返回月度起始日期

end_of_month(self)

返回月末最后一天日期

start_of_quarter(self)

返回季度起始日期

end_of_quarter(self)

返回季度结束日期

start_of_halfyear(self)

返回半年度起始日期

end_of_halfyear(self)

返回半年度结束日期

start_of_year(self)

返回年度起始日期

end_of_year(self)

返回年度结束日期

next_day(self)

返回下一自然日

next_week(self)

返回下周周一日期

next_month(self)

返回下月首日日期

next_quarter(self)

返回下一季度首日日期

next_halfyear(self)

返回下一半年度首日日期

next_year(self)

返回下一年度首日日期

pre_day(self)

返回前一自然日日期

pre_week(self)

返回上周周一日期

pre_month(self)

返回上月首日日期

pre_quarter(self)

返回上一季度首日日期

pre_halfyear(self)

返回上一半年度首日日期

pre_year(self)

返回上一年度首日日期

staticmax()

获取支持的最大日期时间

staticmin()

获取支持的最小日期时间

staticnow()

获取当前的日期时间

statictoday()

获取当前的日期

classhikyuu.TimeDelta

时间时长,用于时间计算。可通过以下方式构建:

  • 通过 datetime.timedelta 构建。TimdeDelta(timedelta实例)

  • TimeDelta(days=0, hours=0, minutes=0, seconds=0, milliseconds=0, microseconds=0)

    • -99999999 <= days <= 99999999
    • -100000 <= hours <= 100000
    • -100000 <= minutes <= 100000
    • -8639900 <= seconds <= 8639900
    • -86399000000 <= milliseconds <= 86399000000
    • -86399000000 <= microseconds <= 86399000000

以上参数限制,主要为防止求总微秒数时可能出现溢出的情况。如只使用一个参数不希望存在上述限制时,可使用快捷函数: Days()Hours()Minutes()Seconds()Milliseconds(),Microseconds()

days 天数 [-99999999, 99999999]
hours 小时数 [0, 23]
minutes 分钟数 [0, 59]
seconds 秒数 [0, 59]
milliseconds 毫秒数 [0, 999]
microseconds 微秒数 [0, 999]
ticks 同总微秒数
isNegative(self)

是否为负时长

返回类型: bool
total_days(self)

获取带小数的总天数

返回类型: float
total_hours(self)

获取带小数的总小时数

返回类型: float
total_minutes(self)

获取带小数的总分钟数

返回类型: float
total_seconds(self)

获取带小数的总秒数

返回类型: float
total_milliseconds(self)

获取带小数的总毫秒数

返回类型: float
staticmax()

支持的最大时长

返回: TimeDelta(99999999, 23, 59, 59, 999, 999)
staticmin()

支持的最小时长

返回: TimeDelta(-99999999, 0, 0, 0, 0, 0)
staticresolution()

支持的最小精度

返回: TimeDelta(0, 0, 0, 0, 0, 1)
staticmax_ticks()

支持的最大 ticks (即微秒数)

返回类型: int
staticmin_ticks()

支持的最小 ticks (即微秒数)

返回类型: int
staticfrom_ticks(ticks)

使用 ticks(即微秒数) 值创建

参数: ticks (int) – 微秒数
返回类型: TimeDelta
hikyuu.Days(days)

以天数创建 TimeDelta

参数: days (int) – 天数
返回类型: TimeDelta
hikyuu.Hours(hours)

以小时数创建 TimeDelta

参数: hours (int) – 小时数
返回类型: TimeDelta
hikyuu.Minutes(minutes)

以分钟数创建 TimeDelta

参数: minutes (int) – 分钟数
返回类型: TimeDelta
hikyuu.Seconds(seconds)

以秒数创建 TimeDelta

参数: seconds (int) – 秒数
返回类型: TimeDelta
hikyuu.Milliseconds(milliseconds)

以毫秒数创建 TimeDelta

参数: milliseconds (int) – 毫秒数
返回类型: TimeDelta
hikyuu.Microseconds(microseconds)

以微秒数创建 TimeDelta

参数: microseconds (int) – 微秒数
返回类型: TimeDelta

4.k线数据

classhikyuu.KRecord

K线记录,组成K线数据,属性可读写。

datetime : 日期时间
open : 开盘价
high : 最高价
low : 最低价
close : 收盘价
amount : 成交金额
volume : 成交量
classhikyuu.KData

通过 Stock.get_kdata 获取的K线数据,由 KRecord 组成的数组,可象 list 一样进行遍历

start_pos

获取在原始K线记录中对应的起始位置,如果KData为空返回0

last_pos

获取在原始K线记录中对应的最后一条记录的位置,如果为空返回0,其他等于endPos - 1

end_pos

获取在原始K线记录中对应范围的下一条记录的位置,如果为空返回0,其他等于lastPos + 1

get_datetime_list()

返回交易日期列表

返回类型: DatetimeList
get(pos)

获取指定索引位置的K线记录

参数: pos (int) – 位置索引
返回类型: KRecord
get_by_datetime(datetime)

获取指定时间的K线记录。

参数: datetime (Datetime) – 指定的日期
返回类型: KRecord
get_pos(datetime)

获取指定时间对应的索引位置

参数: datetime (Datetime) – 指定的时间
返回: 对应的索引位置,如果不在数据范围内,则返回 None
empty()

判断是否为空

返回类型: bool
get_query()

获取关联的查询条件

返回类型: Query
get_stock()

获取关联的Stock

返回类型: Stock
tocsv(filename)

将数据保存至CSV文件

参数: filename (str) – 指定保存的文件名称
to_np()

转化为numpy结构数组

返回类型: numpy.array
to_df()

转化为pandas的DataFrame

返回类型: pandas.DataFrame

5. 分时线数据

classhikyuu.TimeLineRecord

分时线记录,属性可读写。

date : 日期时间
price : 价格
vol : 成交量
classhikyuu.TimeLineList

通过 Stock.getTimeLineList 获取的分时线数据,由 TimeLineRecord 组成的数组,可象 list 一样进行遍历

to_np()

转化为numpy结构数组

返回类型: numpy.array
to_df()

转化为pandas的DataFrame

返回类型: pandas.DataFrame

 

分笔历史数据

classhikyuu.TransRecord

历史分笔数据记录

date : 时间
price : 价格
vol : 成交量
direct : 买卖盘性质
classhikyuu.TransList

分时线数据列表

to_np()

转化为numpy结构数组

返回类型: numpy.array
to_df()

转化为pandas的DataFrame

返回类型: pandas.DataFrame

 

杂项或辅助

6.函数

hikyuu.select()

示例:

#选出涨停股
C = CLOSE()
x = select(C / REF(C, 1) - 1 >= 0.0995))
参数:
  • cond (Indicator) – 条件指标
  • start (Datetime) – 起始日期
  • end (Datetime) – 结束日期
  • print_out (bool) – 打印选中的股票
返回类型:

选中的股票列表

hikyuu.get_log_level()

获取当前日志打印级别

返回类型: LOG_LEVEL
hikyuu.set_log_level(level)

设置日志打印级别

参数: level (LOG_LEVEL) – 指定的日志打印级别
hikyuu.hku_save(varfilename)

序列化,将hikyuu内建类型的变量(如Stock、TradeManager等)保存在指定的文件中,格式为XML。

参数:
  • var – hikyuu内建类型的变量
  • filename (str) – 指定的文件名
hikyuu.hku_load(varfilename)

将通过 hku_save 保存的变量,读取到var中。

参数:
  • var – 指定的变量
  • filename (str) – 待载入的序列化文件。
hikyuu.roundUp(arg1[arg2=0])

向上截取,如10.1截取后为11

参数:
  • arg1 (float) – 待处理数据
  • arg2 (int) – 保留小数位数
返回:

处理过的数据

hikyuu.roundDown(arg1[arg2=0])

向下截取,如10.1截取后为10

参数:
  • arg1 (float) – 待处理数据
  • arg2 (int) – 保留小数位数
返回:

处理过的数据

hikyuu.getDateRange(startend)

获取指定 [start, end) 日期时间范围的自然日日历日期列表,仅支持到日

参数:
返回类型:

DatetimeList

hikyuu.toPriceList(arg)

将Python的可迭代对象如 list、tuple 转化为 PriceList

参数: arg – 待转化的Python序列
返回类型: PriceList
hikyuu.set_global_context(stkquery)

设置全局的 context

参数:
  • stk (Stock) – 指定的全局Stock
  • query (Query) – 指定的查询条件
hikyuu.get_global_context()

获取当前全局默认上下文

返回类型: KData

7.

classhikyuu.Parameter

参数类

get(selfname)

获取指定参数

参数: name (str) – 参数名称
返回: 参数值
set(selfnamevalue)

设置参数

参数:
  • name (str) – 参数名称
  • value – 参数值(仅支持 int | float | str | bool 类型)
classhikyuu.PriceList

价格序列,其中价格使用double表示,对应C++中的std::vector<double>。

to_np(self)

仅在安装了numpy模块时生效,转换为numpy.array

to_df(self)

仅在安装了pandas模块时生效,转换为pandas.DataFrame

classhikyuu.DatetimeList

日期序列,对应C++中的std::vector<Datetime>

append(selfdatetime)

向列表末端加入元素

参数: datetime (Datetime) – 待加入的元素
to_np(self)

仅在安装了numpy模块时生效,转换为numpy.array

to_df(self)

仅在安装了pandas模块时生效,转换为pandas.DataFrame

classhikyuu.StringList

字符串列表,对应C++中的std::vector<String>

classhikyuu.KRecordList

C++ std::vector<KRecord>包装

append(selfkrecord)

向列表末端加入元素

参数: krecord (KRecord) – 待加入的元素
to_np(self)

仅在安装了numpy模块时生效,转换为numpy.array

to_df(self)

仅在安装了pandas模块时生效,转换为pandas.DataFrame

classhikyuu.BlockList

C++ std::vector<Block>包装

classhikyuu.OstreamRedirect

重定向C++ std::cout、std::cerr至python。在非命令行方式下,某些App无法显示C++ iostream的输出信息,如Jupyter notebook。默认构造时,只是指定是否需要重定向std::cout或std::cerr,必须使用open方法或with语法才会启用重定向。

使用with示例:

with OstreamRedirect():
    your_function() #被封装的C++函数,其中使用了std::iostream输出
init(self[stdout=Truestderr=True])
参数:
  • stdout (bool) – 是否重定向C++ std::cout
  • stderr (bool) – 是否重定向C++ std::cerr
open(self)

启用重定向

close(self)

关闭重定向

 

8.枚举

classhikyuu.LOG_LEVEL
  • DEBUG
  • TRACE
  • INFO
  • WARN
  • ERROR
  • FATAL
  • NO_PRINT

classhikyuu.Constant

null_datetime 无效Datetime
inf
nan
null_price 同 nan
null_int 无效int
null_size 无效size
null_int64 无效int64
pickle_support 是否支持 pickle
STOCKTYPE_BLOCK 股票类型-板块
STOCKTYPE_A 股票类型-A股
STOCKTYPE_INDEX 股票类型-指数
STOCKTYPE_B 股票类型-B股
STOCKTYPE_FUND 股票类型-基金
STOCKTYPE_ETF 股票类型-ETF
STOCKTYPE_ND 股票类型-国债
STOCKTYPE_BOND 股票类型-其他债券
STOCKTYPE_GEM 股票类型-创业板
STOCKTYPE_TMP 股票类型-临时CSV
posted @ 2021-02-09 11:56  KnowledgePorter  阅读(86)  评论(0)    收藏  举报