Skip to content

Commit

Permalink
Merge pull request #293 from fasiondog/release
Browse files Browse the repository at this point in the history
Release 2.2.0
  • Loading branch information
fasiondog committed Sep 26, 2024
2 parents 3d4f076 + 5b3fb18 commit e467843
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 26 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

sys.path.insert(0, os.path.abspath('.'))

version = '2.1.5'
version = '2.2.0'
release = version

# General information about the project.
Expand Down
5 changes: 4 additions & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Welcome to Hikyuu's documentation!

.. toctree::
:maxdepth: 1
:caption: Reference
:caption: Python指南

interactive/index
base/index
Expand All @@ -24,12 +24,15 @@ Welcome to Hikyuu's documentation!
trade_manage/trade_manage
trade_sys/trade_sys
trade_portfolio/trade_portfolio
trade_sys/walkforward
strategy
reference


.. toctree::
:maxdepth: 1
:caption: C++开发指南
:name: C++ Develop Guide

developer.rst

Expand Down
2 changes: 1 addition & 1 deletion docs/source/indicator/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.. toctree::

ind_class
overview
indicator
talib
ind_class
6 changes: 4 additions & 2 deletions docs/source/indicator/indicator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -472,18 +472,19 @@
:param KData kdata: k线数据
:rtype: Indicator

.. py:function:: IC(ind, stks, query, ref_stk[, n=1])
.. py:function:: IC(ind, stks, query, ref_stk[, n=1, spearman=True])
计算指定的因子相对于参考证券的 IC (实际为 RankIC)

:param sequence | Block stks 证券组合
:param Query query: 查询条件
:param Stock ref_stk: 参照证券,通常使用 sh000300 沪深300
:param int n: 时间窗口(对应的 n 日收益率)
:param bool spearman: 默认使用 spearman 计算相关系数,否则为 pearson
:rtype: Indicator


.. py:function:: ICIR(ind, stks, query, ref_stk[, n=1, rolling_n=120])
.. py:function:: ICIR(ind, stks, query, ref_stk[, n=1, rolling_n=120, spearman=True])
计算 IC 因子 IR = IC的多周期均值/IC的标准方差

Expand All @@ -492,6 +493,7 @@
:param Stock ref_stk: 参照证券,通常使用 sh000300 沪深300
:param int n: 时间窗口(对应的 n 日收益率)
:param int rolling_n: 滚动周期
:param bool spearman: 默认使用 spearman 计算相关系数,否则为 pearson
:rtype: Indicator


Expand Down
7 changes: 6 additions & 1 deletion docs/source/indicator/talib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
TA-Lib 包装
============

由于内建指标还不完整,在交互工具里对TA-Lib进行了包装,命名方式统一为 TA_FUNC名称。其中,ta-lib指标的lookback属性,用discard属性代替。
.. note::

talib 包无法在 Windows 下通过 pip 安装,请从 `<https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib/>`_ 上下载相应的 wheel 包,手工安装。


在交互工具里对TA-Lib进行了包装,做为对 hikyuu 指标的补充,其命名方式统一为 TA_FUNC名称。其中,ta-lib指标的lookback属性,用discard属性代替。

::

Expand Down
6 changes: 1 addition & 5 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ pip 安装
.. note::

第一次使用,请详细阅读 :ref:`quickstart` 。

.. note::

由于依赖的 talib 包,无法在 Windows 下通过 pip 安装,请从 `<https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib/>`_ 上下载相应的 wheel 包,手工安装。


.. note::

Linux 需要安装依赖的库:libhdf5、libmysqlclient、libsqlite3
Expand Down
24 changes: 24 additions & 0 deletions docs/source/release.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
版本发布说明
=======================

2.2.0 - 2024年9月26日
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1. 新增特性
- 新增 WalkForwardSystem 滚动系统策略(单候选系统时为滚动,多候选系统时为滚动寻优)
- 新增 OptimalSelector 滚动系统策略寻优算法(配合 WalkForwardSystem 使用)
- Strategy 支持指定多个时间点任务
- IC/ICIR/MF_MultiFactor/SE_MultiFactor 增加 spearman 参数,控制相关系数计算方法

2. 功能优化
- 优化 SpotAgent
- 解决 hub 中自定义继承类接口在另一个part中引用时丢失的问题
- 调整 HikyuuTDX 超时时长,避免 linux 超时时等待时间过长

3. 缺陷修复
- fixed etf 缩扩股,调整权息表以适应缩扩股
- fixed DMA和INSUM,处理 nan 和 discard
- fixed 日期型 KQuery 比较失败
- fixed System未正确使用 m_kdata
- fixed performance 统计计算天数时加1
- fixed some CN not register serialization
- fixed portfolio 打印缺失


2.1.5 - 2024年9月11日
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
多因子合成
============

多因子本质是在时间截面上对候选标的进行评分,所以实际需要配合 Selector (策略选择算法) 使用。


内建对因子合成算法
--------------------------------

.. py:function:: MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5])
.. py:function:: MF_EqualWeight(inds, stks, query, ref_stk[, ic_n=5, spearman=True])
等权重合成因子

Expand All @@ -16,10 +19,11 @@
:param Query query: 日期范围
:param Stock ref_stk: 参考证券
:param int ic_n: 默认 IC 对应的 N 日收益率
:param bool spearman: 默认使用 spearman 计算相关系数,否则为 pearson
:rtype: MultiFactorBase


.. py:function:: MF_ICWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])
.. py:function:: MF_ICWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120, spearman=True])
滚动IC权重合成因子

Expand All @@ -29,10 +33,11 @@
:param Stock ref_stk: 参考证券
:param int ic_n: 默认 IC 对应的 N 日收益率
:param int ic_rolling_n: IC 滚动周期
:param bool spearman: 默认使用 spearman 计算相关系数,否则为 pearson
:rtype: MultiFactorBase


.. py:function:: MF_ICIRWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120])
.. py:function:: MF_ICIRWeight(inds, stks, query, ref_stk[, ic_n=5, ic_rolling_n=120, spearman=True])
滚动ICIR权重合成因子

Expand All @@ -42,6 +47,7 @@
:param Stock ref_stk: 参考证券
:param int ic_n: 默认 IC 对应的 N 日收益率
:param int ic_rolling_n: IC 滚动周期
:param bool spearman: 默认使用 spearman 计算相关系数,否则为 pearson
:rtype: MultiFactorBase


Expand Down
4 changes: 3 additions & 1 deletion docs/source/trade_portfolio/portfolio.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
.. py:currentmodule:: hikyuu.trade_sys
.. highlight:: python

.. _portfolio:

投资组合
=============

目前仅实现了多标的、相同策略的投资组合,还需完善,未来接口可能变化(包括选择器策略)!
在 Hikyuu 中 Portfolio 投资组合是以系统交易策略为单位的,Hikyuu 即可以使用不同目标同一交易策略的组合,也可以使用不同目标不同交易逻辑的系统策略进行组合,和常见程序化交易中的多目标但策略逻辑相同的投资组合并不完全相同。

.. py:function:: PF_Simple([tm, af, se])
Expand Down
3 changes: 2 additions & 1 deletion docs/source/trade_portfolio/selector.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
:param System sys: 系统策略原型
:return: SE选择器实例

.. py:function:: SE_MultiFactor(inds[, topn=10, ic_n=5, ic_rolling_n=120, ref_stk=None, mode="MF_ICIRWeight"])
.. py:function:: SE_MultiFactor(inds[, topn=10, ic_n=5, ic_rolling_n=120, ref_stk=None, spearman=True, mode="MF_ICIRWeight"])
创建基于多因子评分的选择器,两种创建方式:

Expand All @@ -41,6 +41,7 @@
:param int ic_n: 默认 IC 对应的 N 日收益率
:param int ic_rolling_n: IC 滚动周期
:param Stock ref_stk: 参考证券 (未指定时,默认为 sh000300 沪深300)
:param bool spearman: 默认使用 spearman 计算相关系数,否则使用 pearson
:param str mode: "MF_ICIRWeight" | "MF_ICWeight" | "MF_EqualWeight" 因子合成算法名称
:return: SE选择器实例

Expand Down
1 change: 1 addition & 0 deletions docs/source/trade_portfolio/trade_portfolio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
.. toctree::

portfolio
multifactor
selector
allocate_funds
4 changes: 3 additions & 1 deletion docs/source/trade_sys/system.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.. py:currentmodule:: hikyuu.trade_sys
.. highlight:: python

系统框架
系统策略
=============

系统是指针对单个交易对象的完整策略,包括环境判断、系统有效条件、资金管理、止损、止盈、盈利目标、移滑价差的完整策略,用于模拟回测。

对于多目标,在 Hikyuu 中需要使用投资组合,参见::ref:`portfolio`。

公共参数:

* **buy_delay=True** *(bool)* : 买入操作是否延迟到下一个bar开盘时进行交易
Expand Down
3 changes: 1 addition & 2 deletions docs/source/trade_sys/trade_sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@
stoploss
money_manager
profitgoal
slippage
multifactor
slippage
42 changes: 42 additions & 0 deletions docs/source/trade_sys/walkforward.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.. py:currentmodule:: hikyuu.trade_sys
.. highlight:: python

滚动交易系统
=============

创建滚动交易系统
------------------

.. py:function:: SYS_WalkForward(sys_list, [tm=None, train_len=100, test_len=20, se=None, train_tm=None])
创建滚动寻优系统,当输入的后续系统列表中仅有一个候选系统时,即为滚动系统

:param sequence sys_list: 后续系统列表
:param TradeManager tm: 交易账户
:param int train_len: 滚动评估系统绩效时使用的数据长度
:param int test_len: 使用在 train_len 中选出的最优系统执行的数据长度
:param SelectorBase se: 寻优选择器
:param TradeManager train_tm: 滚动评估时使用的交易账户, 为None时, 使用 tm 的拷贝进行评估


内建交易系统寻优选择器
-------------------------

系统寻优选择器在 Hikyuu 中虽然也使用 SE 前缀,但和 PF(投资组合) 中的 SE 并不相同,两者不能互换。系统寻优选择器必须和 SYS_WalkForward 配合使用。

系统寻优选择器是在候选交易系统中选出“最优”的一个系统,在接下来的时间使用这个“最优”系统进行交易。

PF(投资组合)中的 SE,则是在调仓日对所有候选系统进行排序评分,并由 PF 根据评分结果进行资金分配,每个候选系统都为实际的交易系统。


.. py:function:: SE_MaxFundsOptimal()
账户资产最大寻优选择器


.. py:function:: SE_PerformanceOptimal(key="帐户平均年收益率%", mode=0)
使用 Performance 统计结果进行寻优的选择器

:param string key: Performance 统计项
:param int mode: 0 取统计结果最大的值系统 | 1 取统计结果为最小值的系统
2 changes: 1 addition & 1 deletion hikyuu_cpp/hikyuu/trade_sys/selector/crt/SE_Optimal.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ SEPtr HKU_API SE_MaxFundsOptimal();
* 使用 Performance 统计结果进行寻优的选择器
* @return SEPtr
*/
SEPtr HKU_API SE_PerformanceOptimal();
SEPtr HKU_API SE_PerformanceOptimal(const string& key = "帐户平均年收益率%", int mode = 0);

} // namespace hku
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,11 @@ void PerformanceOptimalSelector::_calculate_parallel(
}
}

SEPtr HKU_API SE_PerformanceOptimal() {
return make_shared<PerformanceOptimalSelector>();
SEPtr HKU_API SE_PerformanceOptimal(const string& key, int mode) {
PerformanceOptimalSelector* p = new PerformanceOptimalSelector();
p->setParam<string>("key", key);
p->setParam<int>("mode", mode);
return SEPtr(p);
}

} // namespace hku
18 changes: 15 additions & 3 deletions hikyuu_pywrap/trade_sys/_Selector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class PySelectorBase : public SelectorBase {
}
};

#ifdef __GNUC__
#pragma GCC visibility push(hidden)
#endif
class PyOptimalSelector : public OptimalSelectorBase {
OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION

Expand Down Expand Up @@ -83,8 +86,11 @@ class PyOptimalSelector : public OptimalSelectorBase {
// 目前无法序列化
py::function m_evaluate;
};
#ifdef __GNUC__
#pragma GCC visibility pop
#endif

SEPtr crtSEOptimal(const py::function&& evalfunc) {
SEPtr crtSEOptimal(const py::function& evalfunc) {
return std::make_shared<PyOptimalSelector>(evalfunc);
}

Expand Down Expand Up @@ -284,6 +290,12 @@ void export_Selector(py::module& m) {
:param func: 一个可调用对象,接收参数为 (sys, lastdate),返回一个 float 数值)");

m.def("SE_MaxFundsOptimal", SE_MaxFundsOptimal, "账户资产最大寻优选择器");
m.def("SE_PerformanceOptimal", SE_PerformanceOptimal,
"使用 Performance 统计结果进行寻优的选择器");

m.def("SE_PerformanceOptimal", SE_PerformanceOptimal, py::arg("key") = "帐户平均年收益率%",
py::arg("mode") = 0, R"(SE_PerformanceOptimal(key="帐户平均年收益率%", mode=0)
使用 Performance 统计结果进行寻优的选择器
:param string key: Performance 统计项
:param int mode: 0 取统计结果最大的值系统 | 1 取统计结果为最小值的系统)");
}
2 changes: 1 addition & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set_project("hikyuu")
add_rules("mode.debug", "mode.release")

-- version
set_version("2.1.5", {build = "%Y%m%d%H%M"})
set_version("2.2.0", {build = "%Y%m%d%H%M"})

set_warnings("all")

Expand Down

0 comments on commit e467843

Please sign in to comment.