Skip to content

Commit

Permalink
Merge pull request #235 from fasiondog/release
Browse files Browse the repository at this point in the history
Release 2.0.2
  • Loading branch information
fasiondog authored Apr 19, 2024
2 parents 4cb20b5 + a79da66 commit 03a7798
Show file tree
Hide file tree
Showing 24 changed files with 2,810 additions and 811 deletions.
20 changes: 20 additions & 0 deletions docs/source/indicator/indicator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,18 @@
:rtype: Indicator


.. py:function:: FINANCE([kdata, ix, name])
获取历史财务信息。(可通过 StockManager.get_history_finance_all_fields 查询相应的历史财务字段信息)

ix, name 使用时,为二选一。即要不使用 ix,要不就使用 name 进行获取。

:param KData kdata: K线数据
:param int ix: 历史财务信息字段索引
:param int name: 历史财务信息字段名称
:rtype: Indicator


.. py:function:: FLOOR([data])
向下舍入(向数值减小方向舍入)取整
Expand Down Expand Up @@ -1128,6 +1140,14 @@
:param float default_val: 如果输入的日期早于已有国债数据的最早记录,则使用此默认值


.. py:function:: ZONGGUBEN([data])
获取总股本(单位:万股)

:param KData kdata: k线数据
:rtype: Indicator


.. py:function:: ZSCORE([data, out_extreme, nsigma, recursive])
对数据进行标准化(归一),可选进行极值排除
Expand Down
2 changes: 2 additions & 0 deletions docs/source/indicator/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
* :py:func:`RECOVER_BACKWARD` - 后向复权
* :py:func:`RECOVER_EQUAL_FORWARD` - 等比前向复权
* :py:func:`RECOVER_EQUAL_BACKWARD` - 等比后向复权
* :py:func:`FINANCE` - 历史财务信息
* :py:func:`HSL` - 换手率
* :py:func:`CAPITAL` - 流通盘,同名:LIUTONGPAN
* :py:func:`TIMELINE` - 分时价格
* :py:func:`TIMELINEVOL` - 分时成交量
* :py:func:`ZHBOND10` - 10年期中国国债收益率
* :py:func:`ZONGGUBEN` - 总股本


**大盘指标**
Expand Down
2 changes: 1 addition & 1 deletion docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

支持的操作系统:64位 Windows7及以上版本、Linux请使用源码自行编译安装。

Python环境:>= Python3.8
Python环境:>= Python3.9

.. note::

Expand Down
14 changes: 14 additions & 0 deletions docs/source/release.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
版本发布说明
=======================

2.0.2 - 2024年4月19日
-------------------------

1. 新增特性
- 历史财务信息入库,并增加指标 FINANCE 获取相应历史财务数据
- 新增 RESULT 指标,以便对存在多个结果集的指标可以通过指标公式的方式获取结果
- Stock 开放部分属性可在运行时修改,增加 set_krecord_list 方法,可以希望使用其他数据源时生成临时的 Stock 并获取 K 线数据

2. 缺陷修复
- fixed 获取节假日信息时出现错误
- fixed hdf5 在只有日线数据时,运行在 jupyter 中,初始化会出现卡死
- fixed 新增的北交所股票类型未修改全,导入数据后又变成了 A 股类型


2.0.1 - 2024年4月7日
-------------------------

Expand Down
3 changes: 2 additions & 1 deletion hikyuu/data/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def historyfinancialreader(filepath):
report_date = int(cw_info[313]) # 财务公告日期
report_date = 19000000 + report_date if report_date > 800000 else 20000000 + report_date
# results.append((modifiy_code(code), report_date, cw_info))
results.append((file_date, modifiy_code(code), report_date, cpp_bytes_to_vector_float_blob(info_data)))
# results.append((file_date, modifiy_code(code), report_date, cpp_bytes_to_vector_float_blob(info_data)))
results.append((file_date, modifiy_code(code), report_date, info_data))
cw_file.close()
return results
36 changes: 18 additions & 18 deletions hikyuu/data/common_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ def create_database(connect):
with open(filename, 'r', encoding='utf8') as f:
sql = f.read()
for x in cur.execute(sql, multi=True):
#print(x.statement)
# print(x.statement)
pass

db_version = get_db_version(connect)
files = [x for x in Path(sql_dir).iterdir() \
if x.is_file() \
and x.name != 'createdb.sql' \
and x.name != '__init__.py' \
and int(x.stem) > db_version and not x.is_dir()]
files = [x for x in Path(sql_dir).iterdir()
if x.is_file()
and x.name != 'createdb.sql'
and x.name != '__init__.py'
and int(x.stem) > db_version and not x.is_dir()]
files.sort()
for file in files:
sql = file.read_text(encoding='utf8')
for x in cur.execute(sql, multi=True):
#print(x.statement)
# print(x.statement)
pass

connect.commit()
Expand Down Expand Up @@ -177,7 +177,7 @@ def get_table(connect, market, code, ktype):
`count` DOUBLE UNSIGNED NOT NULL,
PRIMARY KEY (`date`)
)
COLLATE='utf8_general_ci'
COLLATE='utf8mb4_general_ci'
ENGINE=MyISAM
;
""".format(schema=schema, name=tablename)
Expand Down Expand Up @@ -252,7 +252,7 @@ def getMin60Date(olddate):
startdate = newdate + 1401
enddate = newdate + 1500
return (startdate, enddate)

def getHour2Date(olddate):
mint = olddate - olddate // 10000 * 10000
newdate = olddate // 10000 * 10000
Expand All @@ -263,7 +263,7 @@ def getHour2Date(olddate):
startdate = newdate + 1301
enddate = newdate + 1500
return (startdate, enddate)

def getMin15Date(olddate):
mint = olddate - olddate // 10000 * 10000
newdate = olddate // 10000 * 10000
Expand Down Expand Up @@ -374,7 +374,7 @@ def getNewDate(index_type, olddate):
base_table = get_table(connect, market, code, 'day')
else:
index_list = ('min15', 'min30', 'min60', 'hour2')
#index_list = ('min15', )
# index_list = ('min15', )
base_table = get_table(connect, market, code, 'min5')

base_lastdate = get_lastdatetime(connect, base_table)
Expand Down Expand Up @@ -407,23 +407,23 @@ def getNewDate(index_type, olddate):

update_buffer = []
insert_buffer = []
#for current_base in base_list:
# for current_base in base_list:
length_base_all = len(base_list)
for x in range(length_base_all):
current_date = base_list[x][0]
if current_date <= last_end_date:
continue
last_start_date, last_end_date = getNewDate(index_type, current_date)

#cur = connect.cursor()
#cur.execute(
# cur = connect.cursor()
# cur.execute(
# 'select date, open, high, low, close, amount, count from {} \
# where date>={} and date<={} order by date asc'.format(
# base_table, last_start_date, last_end_date
# )
#)
#base_record_list = [r for r in cur]
#cur.close()
# )
# base_record_list = [r for r in cur]
# cur.close()
base_record_list = []
start_ix = x
ix_date = current_date
Expand Down Expand Up @@ -482,4 +482,4 @@ def getNewDate(index_type, olddate):
cnx = mysql.connector.connect(user=usr, password=pwd, host=host, port=port)

update_extern_data(cnx, 'SH', '000001', 'day')
cnx.close()
cnx.close()
9 changes: 4 additions & 5 deletions hikyuu/data/mysql_upgrade/0001.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CREATE TABLE `hku_base`.`version` (
`version` INT(11) UNSIGNED NOT NULL
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
INSERT INTO `hku_base`.`version` (version) VALUES (1);
`version` INT(11) UNSIGNED NOT NULL
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

INSERT INTO `hku_base`.`version` (version) VALUES (1);
78 changes: 33 additions & 45 deletions hikyuu/data/mysql_upgrade/0009.sql
Original file line number Diff line number Diff line change
@@ -1,48 +1,36 @@
CREATE TABLE IF NOT EXISTS `hku_base`.`stkfinance` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`stockid` INT UNSIGNED NOT NULL,
`updated_date` INT NOT NULL,
`ipo_date` INT NOT NULL, -- 42.上市日期
`province` DOUBLE NOT NULL,
`industry` DOUBLE NOT NULL,
`zongguben` DOUBLE NOT NULL, -- 1.总股本(股)
`liutongguben` DOUBLE NOT NULL, -- 7.流通A股(股)
`guojiagu` DOUBLE NOT NULL, -- 2.国家股(股)
`faqirenfarengu` DOUBLE NOT NULL, -- 3.发起人法人股(股)
`farengu` DOUBLE NOT NULL, -- 4.法人股(股)
`bgu` DOUBLE NOT NULL, -- 5.B股(股)
`hgu` DOUBLE NOT NULL, -- 6.H股(股)
`zhigonggu` DOUBLE NOT NULL, -- 8.职工股(股)
`zongzichan` DOUBLE NOT NULL, -- 10.总资产(元)
`liudongzichan` DOUBLE NOT NULL, -- 11.流动资产(元)
`gudingzichan` DOUBLE NOT NULL, -- 12.固定资产(元)
`wuxingzichan` DOUBLE NOT NULL, -- 13.无形资产(元)
`gudongrenshu` DOUBLE NOT NULL, -- 股东人数
`liudongfuzhai` DOUBLE NOT NULL, -- 15.流动负债
`changqifuzhai` DOUBLE NOT NULL, -- 16.长期负债
`zibengongjijin` DOUBLE NOT NULL, -- 17.资本公积金
`jingzichan` DOUBLE NOT NULL, -- 净资产(元)
`zhuyingshouru` DOUBLE NOT NULL, -- 20.主营收入
`zhuyinglirun` DOUBLE NOT NULL, -- 21.主营利润
`yingshouzhangkuan` DOUBLE NOT NULL, -- 应收账款
`yingyelirun` DOUBLE NOT NULL, -- 23.营业利润
`touzishouyu` DOUBLE NOT NULL, -- 投资收益
`jingyingxianjinliu` DOUBLE NOT NULL, -- 经营现金流
`zongxianjinliu` DOUBLE NOT NULL, -- 总现金流
`cunhuo` DOUBLE NOT NULL, -- 存货
`lirunzonghe` DOUBLE NOT NULL, -- 28.利润总额
`shuihoulirun` DOUBLE NOT NULL, -- 29.税后利润
`jinglirun` DOUBLE NOT NULL, -- 30.净利润
`weifenpeilirun` DOUBLE NOT NULL, -- 31.未分配利润
`meigujingzichan` DOUBLE NOT NULL, -- 34.每股净资产
`baoliu2` DOUBLE NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY(`stockid`) REFERENCES `hku_base`.`stock` (`stockid`),
INDEX `ix_stkfinance_date` (`updated_date`),
INDEX `ix_stkfinance_stock_date` (`stockid`, `updated_date`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
;
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `stockid` INT UNSIGNED NOT NULL, `updated_date` INT NOT NULL, `ipo_date` INT NOT NULL, -- 42.上市日期
`province` DOUBLE NOT NULL, `industry` DOUBLE NOT NULL, `zongguben` DOUBLE NOT NULL, -- 1.总股本(股)
`liutongguben` DOUBLE NOT NULL, -- 7.流通A股(股)
`guojiagu` DOUBLE NOT NULL, -- 2.国家股(股)
`faqirenfarengu` DOUBLE NOT NULL, -- 3.发起人法人股(股)
`farengu` DOUBLE NOT NULL, -- 4.法人股(股)
`bgu` DOUBLE NOT NULL, -- 5.B股(股)
`hgu` DOUBLE NOT NULL, -- 6.H股(股)
`zhigonggu` DOUBLE NOT NULL, -- 8.职工股(股)
`zongzichan` DOUBLE NOT NULL, -- 10.总资产(元)
`liudongzichan` DOUBLE NOT NULL, -- 11.流动资产(元)
`gudingzichan` DOUBLE NOT NULL, -- 12.固定资产(元)
`wuxingzichan` DOUBLE NOT NULL, -- 13.无形资产(元)
`gudongrenshu` DOUBLE NOT NULL, -- 股东人数
`liudongfuzhai` DOUBLE NOT NULL, -- 15.流动负债
`changqifuzhai` DOUBLE NOT NULL, -- 16.长期负债
`zibengongjijin` DOUBLE NOT NULL, -- 17.资本公积金
`jingzichan` DOUBLE NOT NULL, -- 净资产(元)
`zhuyingshouru` DOUBLE NOT NULL, -- 20.主营收入
`zhuyinglirun` DOUBLE NOT NULL, -- 21.主营利润
`yingshouzhangkuan` DOUBLE NOT NULL, -- 应收账款
`yingyelirun` DOUBLE NOT NULL, -- 23.营业利润
`touzishouyu` DOUBLE NOT NULL, -- 投资收益
`jingyingxianjinliu` DOUBLE NOT NULL, -- 经营现金流
`zongxianjinliu` DOUBLE NOT NULL, -- 总现金流
`cunhuo` DOUBLE NOT NULL, -- 存货
`lirunzonghe` DOUBLE NOT NULL, -- 28.利润总额
`shuihoulirun` DOUBLE NOT NULL, -- 29.税后利润
`jinglirun` DOUBLE NOT NULL, -- 30.净利润
`weifenpeilirun` DOUBLE NOT NULL, -- 31.未分配利润
`meigujingzichan` DOUBLE NOT NULL, -- 34.每股净资产
`baoliu2` DOUBLE NOT NULL, PRIMARY KEY (`id`), FOREIGN KEY (`stockid`) REFERENCES `hku_base`.`stock` (`stockid`), INDEX `ix_stkfinance_date` (`updated_date`), INDEX `ix_stkfinance_stock_date` (`stockid`, `updated_date`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 9;
12 changes: 3 additions & 9 deletions hikyuu/data/mysql_upgrade/0010.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
CREATE TABLE
IF NOT EXISTS `hku_base`.`block` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`category` VARCHAR(100) NOT NULL,
`name` VARCHAR(100) NOT NULL,
`market_code` VARCHAR(30) NOT NULL,
PRIMARY KEY (`id`),
INDEX `ix_block` (`category`, `name`)
) COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `hku_base`.`block` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `category` VARCHAR(100) NOT NULL, `name` VARCHAR(100) NOT NULL, `market_code` VARCHAR(30) NOT NULL, PRIMARY KEY (`id`), INDEX `ix_block` (`category`, `name`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 10;
11 changes: 3 additions & 8 deletions hikyuu/data/mysql_upgrade/0011.sql
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
CREATE TABLE
IF NOT EXISTS `hku_base`.`zh_bond10` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`date` INT UNSIGNED NOT NULL,
`value` INT NOT NULL,
PRIMARY KEY (`id`),
INDEX `ix_date_on_zh_bond10` (`date`)
) COLLATE = 'utf8_general_ci' ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `hku_base`.`zh_bond10` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `date` INT UNSIGNED NOT NULL, `value` INT NOT NULL, PRIMARY KEY (`id`), INDEX `ix_date_on_zh_bond10` (`date`)
) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB;

UPDATE `hku_base`.`version` set `version` = 11;
Loading

0 comments on commit 03a7798

Please sign in to comment.