hikyuu 2.6.7__py3-none-win_amd64.whl → 2.6.8__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. hikyuu/__init__.py +6 -2
  2. hikyuu/__init__.pyi +656 -632
  3. hikyuu/analysis/__init__.pyi +563 -539
  4. hikyuu/analysis/analysis.pyi +583 -561
  5. hikyuu/core.pyi +565 -541
  6. hikyuu/cpp/__init__.pyi +2 -2
  7. hikyuu/cpp/concrt140.dll +0 -0
  8. hikyuu/cpp/core310.pyd +0 -0
  9. hikyuu/cpp/core310.pyi +408 -31
  10. hikyuu/cpp/core311.pyd +0 -0
  11. hikyuu/cpp/core311.pyi +408 -31
  12. hikyuu/cpp/core312.pyd +0 -0
  13. hikyuu/cpp/core312.pyi +408 -31
  14. hikyuu/cpp/core313.pyd +0 -0
  15. hikyuu/cpp/core313.pyi +408 -31
  16. hikyuu/cpp/core39.pyd +0 -0
  17. hikyuu/cpp/core39.pyi +408 -31
  18. hikyuu/cpp/hikyuu.dll +0 -0
  19. hikyuu/cpp/hikyuu.lib +0 -0
  20. hikyuu/cpp/hku_hdf5.dll +0 -0
  21. hikyuu/cpp/hku_hdf5_cpp.dll +0 -0
  22. hikyuu/cpp/hku_hdf5_hl.dll +0 -0
  23. hikyuu/cpp/hku_hdf5_hl_cpp.dll +0 -0
  24. hikyuu/cpp/i18n/zh_CN/hikyuu.mo +0 -0
  25. hikyuu/cpp/msvcp140.dll +0 -0
  26. hikyuu/cpp/msvcp140_1.dll +0 -0
  27. hikyuu/cpp/msvcp140_2.dll +0 -0
  28. hikyuu/cpp/msvcp140_atomic_wait.dll +0 -0
  29. hikyuu/cpp/msvcp140_codecvt_ids.dll +0 -0
  30. hikyuu/cpp/sqlite3.dll +0 -0
  31. hikyuu/cpp/vcruntime140.dll +0 -0
  32. hikyuu/cpp/vcruntime140_1.dll +0 -0
  33. hikyuu/draw/__init__.pyi +1 -1
  34. hikyuu/draw/drawplot/__init__.pyi +31 -36
  35. hikyuu/draw/drawplot/bokeh_draw.pyi +651 -637
  36. hikyuu/draw/drawplot/common.pyi +3 -4
  37. hikyuu/draw/drawplot/echarts_draw.pyi +598 -572
  38. hikyuu/draw/drawplot/matplotlib_draw.pyi +872 -879
  39. hikyuu/draw/elder.pyi +19 -20
  40. hikyuu/draw/kaufman.pyi +18 -18
  41. hikyuu/draw/volume.pyi +10 -10
  42. hikyuu/extend.py +19 -0
  43. hikyuu/extend.pyi +594 -574
  44. hikyuu/hub.pyi +69 -67
  45. hikyuu/include/hikyuu/DataType.h +2 -2
  46. hikyuu/include/hikyuu/KData.h +83 -25
  47. hikyuu/include/hikyuu/KDataImp.h +31 -46
  48. hikyuu/include/hikyuu/KDataPrivatedBufferImp.h +73 -0
  49. hikyuu/include/hikyuu/KDataSharedBufferImp.h +69 -0
  50. hikyuu/include/hikyuu/KQuery.h +16 -4
  51. hikyuu/include/hikyuu/KRecord.h +4 -1
  52. hikyuu/include/hikyuu/Stock.h +10 -4
  53. hikyuu/include/hikyuu/StockManager.h +11 -3
  54. hikyuu/include/hikyuu/TransRecord.h +2 -2
  55. hikyuu/include/hikyuu/data_driver/KDataDriver.h +5 -0
  56. hikyuu/include/hikyuu/doc.h +2 -2
  57. hikyuu/include/hikyuu/global/GlobalSpotAgent.h +8 -0
  58. hikyuu/include/hikyuu/global/agent/SpotAgent.h +12 -7
  59. hikyuu/include/hikyuu/indicator/Indicator.h +11 -0
  60. hikyuu/include/hikyuu/indicator/Indicator2InImp.h +9 -0
  61. hikyuu/include/hikyuu/indicator/IndicatorImp.h +83 -15
  62. hikyuu/include/hikyuu/indicator/build_in.h +1 -0
  63. hikyuu/include/hikyuu/indicator/crt/AMA.h +2 -1
  64. hikyuu/include/hikyuu/indicator/crt/ATR.h +1 -1
  65. hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +2 -0
  66. hikyuu/include/hikyuu/indicator/crt/CYCLE.h +3 -0
  67. hikyuu/include/hikyuu/indicator/crt/DMA.h +1 -1
  68. hikyuu/include/hikyuu/indicator/crt/IC.h +14 -6
  69. hikyuu/include/hikyuu/indicator/crt/ICIR.h +8 -4
  70. hikyuu/include/hikyuu/indicator/crt/INSUM.h +2 -0
  71. hikyuu/include/hikyuu/indicator/crt/PRICELIST.h +2 -0
  72. hikyuu/include/hikyuu/indicator/crt/REFX.h +25 -0
  73. hikyuu/include/hikyuu/indicator/crt/SLICE.h +4 -4
  74. hikyuu/include/hikyuu/indicator/crt/SPEARMAN.h +3 -2
  75. hikyuu/include/hikyuu/indicator/imp/IContext.h +5 -0
  76. hikyuu/include/hikyuu/indicator/imp/ICval.h +6 -0
  77. hikyuu/include/hikyuu/indicator/imp/IDropna.h +9 -0
  78. hikyuu/include/hikyuu/indicator/imp/IIc.h +2 -1
  79. hikyuu/include/hikyuu/indicator/imp/IPriceList.h +1 -0
  80. hikyuu/include/hikyuu/indicator/imp/IRefX.h +23 -0
  81. hikyuu/include/hikyuu/plugin/backtest.h +2 -0
  82. hikyuu/include/hikyuu/plugin/extind.h +45 -0
  83. hikyuu/include/hikyuu/plugin/hkuextra.h +21 -0
  84. hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +16 -0
  85. hikyuu/include/hikyuu/plugin/interface/TMReportPluginInterface.h +1 -0
  86. hikyuu/include/hikyuu/python/pybind_utils.h +19 -11
  87. hikyuu/include/hikyuu/trade_manage/Performance.h +0 -1
  88. hikyuu/include/hikyuu/trade_manage/TradeCostBase.h +5 -0
  89. hikyuu/include/hikyuu/trade_manage/TradeManager.h +4 -0
  90. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +10 -1
  91. hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +5 -0
  92. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +5 -0
  93. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +5 -0
  94. hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +5 -0
  95. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +6 -3
  96. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +4 -0
  97. hikyuu/include/hikyuu/trade_sys/profitgoal/ProfitGoalBase.h +5 -0
  98. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +5 -2
  99. hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +5 -0
  100. hikyuu/include/hikyuu/trade_sys/slippage/SlippageBase.h +5 -0
  101. hikyuu/include/hikyuu/trade_sys/stoploss/StoplossBase.h +6 -1
  102. hikyuu/include/hikyuu/trade_sys/system/System.h +5 -0
  103. hikyuu/include/hikyuu/utilities/datetime/Datetime.h +2 -2
  104. hikyuu/include/hikyuu/utilities/os.h +4 -0
  105. hikyuu/include/hikyuu/utilities/thread/GlobalMQStealThreadPool.h +1 -1
  106. hikyuu/include/hikyuu/utilities/thread/GlobalMQThreadPool.h +1 -1
  107. hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +1 -1
  108. hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +1 -1
  109. hikyuu/include/hikyuu/version.h +4 -4
  110. hikyuu/include/hikyuu/views/arrow_common.h +38 -0
  111. hikyuu/include/hikyuu/views/arrow_views.h +117 -0
  112. hikyuu/indicator/indicator.py +4 -5
  113. hikyuu/plugin/backtest.dll +0 -0
  114. hikyuu/plugin/clickhousedriver.dll +0 -0
  115. hikyuu/plugin/dataserver.dll +0 -0
  116. hikyuu/plugin/device.dll +0 -0
  117. hikyuu/plugin/extind.dll +0 -0
  118. hikyuu/plugin/hkuextra.dll +0 -0
  119. hikyuu/plugin/import2hdf5.dll +0 -0
  120. hikyuu/plugin/tmreport.dll +0 -0
  121. hikyuu/strategy/strategy_demo1.py +1 -1
  122. hikyuu/test/test_init.py +19 -19
  123. hikyuu/trade_manage/__init__.pyi +581 -556
  124. hikyuu/trade_manage/broker.pyi +19 -18
  125. hikyuu/trade_manage/broker_easytrader.pyi +6 -4
  126. hikyuu/trade_manage/broker_mail.pyi +22 -24
  127. hikyuu/trade_manage/trade.py +6 -0
  128. hikyuu/trade_manage/trade.pyi +581 -556
  129. hikyuu/trade_sys/__init__.py +4 -0
  130. hikyuu/util/check.pyi +17 -15
  131. hikyuu/util/mylog.pyi +8 -7
  132. hikyuu/util/notebook.pyi +9 -11
  133. hikyuu/util/singleton.pyi +8 -6
  134. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/METADATA +3 -1
  135. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/RECORD +140 -135
  136. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/top_level.txt +1 -1
  137. hikyuu/include/hikyuu/view/MarketView.h +0 -59
  138. /hikyuu/include/hikyuu/{view → views}/__init__.py +0 -0
  139. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/LICENSE +0 -0
  140. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/WHEEL +0 -0
  141. {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.dist-info}/entry_points.txt +0 -0
@@ -16,6 +16,9 @@ namespace hku {
16
16
  * @brief 计算指定的因子相对于参考证券的 ICIR (实际为 RankIC)
17
17
  * @details IR:信息比率(Information Ratio,简称IR)=
18
18
  * IC的多周期均值/IC的标准方差,代表因子获取稳定Alpha的能力。
19
+ * @note IC 原本需要 “t 时刻因子值→t+1 时刻收益”,改为计算 “t 时刻因子值→t 时刻之前 N
20
+ * 天的收益”(比如过去 5 天的收益),并称之为 “当前 IC”。(否则当前值都会是缺失NA)
21
+ * 如需严格“t 时刻因子值→t+1 时刻收益“计算,请设置 strict=True (注意此模式下, 后n位为 NA)
19
22
  * @param ind 因子公式
20
23
  * @param stks 证券组合
21
24
  * @param query 查询条件
@@ -23,13 +26,14 @@ namespace hku {
23
26
  * @param n IC对应的N日收益率
24
27
  * @param rolling_n 滚动时间窗口
25
28
  * @param spearman 使用 spearman 相关系数,否则为 pearson
29
+ * @param strict 是否严格模式
26
30
  * @return Indicator
27
31
  * @ingroup Indicator
28
32
  */
29
33
  inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery& query,
30
34
  const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
31
- bool spearman = true) {
32
- Indicator ic = IC(ind, stks, query, ref_stk, n, spearman);
35
+ bool spearman = true, bool strict = false) {
36
+ Indicator ic = IC(ind, stks, query, ref_stk, n, spearman, strict);
33
37
  Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
34
38
  x.name("ICIR");
35
39
  x.setParam<int>("n", n);
@@ -39,8 +43,8 @@ inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery&
39
43
 
40
44
  inline Indicator ICIR(const Indicator& ind, const Block& blk, const KQuery& query,
41
45
  const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
42
- bool spearman = true) {
43
- Indicator ic = IC(ind, blk, query, ref_stk, n, spearman);
46
+ bool spearman = true, bool strict = false) {
47
+ Indicator ic = IC(ind, blk, query, ref_stk, n, spearman, strict);
44
48
  Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
45
49
  x.name("ICIR");
46
50
  x.setParam<int>("n", n);
@@ -28,4 +28,6 @@ Indicator HKU_API INSUM(const Block& block, const KQuery& query, const Indicator
28
28
 
29
29
  Indicator HKU_API INSUM(const Block& block, const Indicator& ind, int mode, bool fill_null = true);
30
30
 
31
+ Indicator HKU_API INSUM(const Block& block, int mode, bool fill_null);
32
+
31
33
  } // namespace hku
@@ -23,6 +23,8 @@ namespace hku {
23
23
  */
24
24
  Indicator HKU_API PRICELIST(const PriceList& data, int discard = 0);
25
25
  Indicator HKU_API PRICELIST(const PriceList& data, const DatetimeList& ds, int discard = 0);
26
+ Indicator HKU_API PRICELIST(size_t size, double value, int discard = 0);
27
+ Indicator HKU_API PRICELIST(const DatetimeList& dates, double value, int discard = 0);
26
28
  Indicator HKU_API PRICELIST();
27
29
 
28
30
  /**
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-08-22
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../Indicator.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * REF增强(不安全引用), 用于数据左移或右移,周期为整数时,功能同 REF
16
+ * @note 不应用于回测,通常用于AI模型训练等场景
17
+ * @param n 引用周期
18
+ * @ingroup Indicator
19
+ */
20
+ Indicator HKU_API REFX(int n);
21
+ inline Indicator HKU_API REFX(const Indicator& ind, int n) {
22
+ return REFX(n)(ind);
23
+ }
24
+
25
+ } // namespace hku
@@ -24,20 +24,20 @@ Indicator HKU_API SLICE(const PriceList& data, int64_t start, int64_t end);
24
24
  * 获取某指标中指定范围的数据
25
25
  * @param start 起始范围,可为负数
26
26
  * @param end 终止范围(不包含本身),可为负数
27
- * @param result_index 源数据中指定的结果集
27
+ * @param result_index 源数据中指定的结果集, 小于0时表示全部
28
28
  * @ingroup Indicator
29
29
  */
30
- Indicator HKU_API SLICE(int64_t start, int64_t end, int result_index = 0);
30
+ Indicator HKU_API SLICE(int64_t start, int64_t end, int result_index = -1);
31
31
 
32
32
  /**
33
33
  * 获取某指标中指定范围的数据
34
34
  * @param ind 源数据
35
35
  * @param start 起始范围,可为负数
36
36
  * @param end 终止范围(不包含本身),可为负数
37
- * @param result_index 源数据中指定的结果集
37
+ * @param result_index 源数据中指定的结果集,小于0时表示全部
38
38
  * @ingroup Indicator
39
39
  */
40
- inline Indicator SLICE(const Indicator& ind, int64_t start, int64_t end, int result_index = 0) {
40
+ inline Indicator SLICE(const Indicator& ind, int64_t start, int64_t end, int result_index = -1) {
41
41
  return SLICE(start, end, result_index)(ind);
42
42
  }
43
43
 
@@ -12,9 +12,10 @@ namespace hku {
12
12
 
13
13
  /**
14
14
  * Spearman 相关系数
15
- * @param ind1 指标1
16
- * @param ind2 指标2
15
+ * @param ind 指标1
16
+ * @param ref_ind 指标2
17
17
  * @param n 滚动窗口(大于2 或 等于0),等于0时,代表 n 实际使用 ind 的长度
18
+ * @param fill_null 填充缺失值
18
19
  * @ingroup Indicator
19
20
  */
20
21
  Indicator HKU_API SPEARMAN(const Indicator& ind, const Indicator& ref_ind, int n = 0,
@@ -21,6 +21,11 @@ public:
21
21
  virtual string formula() const override;
22
22
  virtual void _calculate(const Indicator& data) override;
23
23
  virtual IndicatorImpPtr _clone() override;
24
+ virtual bool needSelfAlikeCompare() const noexcept override {
25
+ return true;
26
+ }
27
+
28
+ virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
24
29
 
25
30
  KData getContextKdata() const;
26
31
 
@@ -22,6 +22,12 @@ public:
22
22
  ICval(double value, size_t discard);
23
23
  virtual ~ICval();
24
24
  virtual void _checkParam(const string& name) const override;
25
+
26
+ virtual bool needSelfAlikeCompare() const noexcept override {
27
+ return true;
28
+ }
29
+
30
+ virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
25
31
  };
26
32
 
27
33
  } /* namespace hku */
@@ -22,6 +22,15 @@ class IDropna : public IndicatorImp {
22
22
  public:
23
23
  IDropna();
24
24
  virtual ~IDropna();
25
+
26
+ virtual bool needSelfAlikeCompare() const noexcept override {
27
+ return true;
28
+ }
29
+
30
+ // 禁止子节点合并, 上级默认已为 false
31
+ // virtual bool selfAlike(const IndicatorImp& other) const noexcept override {
32
+ // return false;
33
+ // }
25
34
  };
26
35
 
27
36
  } /* namespace hku */
@@ -14,7 +14,8 @@ namespace hku {
14
14
  class IIc : public IndicatorImp {
15
15
  public:
16
16
  IIc();
17
- IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman);
17
+ IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman,
18
+ bool strict);
18
19
  virtual ~IIc();
19
20
 
20
21
  virtual void _checkParam(const string& name) const override;
@@ -21,6 +21,7 @@ class IPriceList : public IndicatorImp {
21
21
  public:
22
22
  IPriceList();
23
23
  IPriceList(const PriceList&, int discard);
24
+ IPriceList(size_t size, double value, int discard);
24
25
  virtual ~IPriceList();
25
26
  virtual void _checkParam(const string& name) const override;
26
27
  };
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-08-22
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../Indicator.h"
11
+
12
+ namespace hku {
13
+
14
+ class IRefX : public IndicatorImp {
15
+ INDICATOR_IMP(IRefX)
16
+ INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ IRefX();
20
+ virtual ~IRefX();
21
+ };
22
+
23
+ } /* namespace hku */
@@ -22,6 +22,8 @@ namespace hku {
22
22
  * @param ref_market 所属市场
23
23
  * @param mode 模式 0: 当前bar收盘价执行买卖操作;1: 下一bar开盘价执行买卖操作;
24
24
  * @param support_short 是否支持做空
25
+ * @param slip 滑点算法
26
+ * @ingroup Strategy
25
27
  */
26
28
  void HKU_API backtest(const StrategyContext& context, const std::function<void(Strategy*)>& on_bar,
27
29
  const TradeManagerPtr& tm, const Datetime& start_date,
@@ -11,6 +11,11 @@
11
11
 
12
12
  namespace hku {
13
13
 
14
+ /**
15
+ * @ingroup Indicator
16
+ * @{
17
+ */
18
+
14
19
  /**
15
20
  * @brief 将指标数据转换到指定周期
16
21
  * @param ktype 指定周期
@@ -146,5 +151,45 @@ inline Indicator WITHHOUR4(const Indicator& ind, bool fill_null = false) {
146
151
  */
147
152
  Indicator HKU_API RANK(const Block& block, const Indicator& ref_ind, int mode = 0,
148
153
  bool fill_null = true, const string& market = "SH");
154
+ Indicator HKU_API RANK(const Block& block, int mode = 0, bool fill_null = true,
155
+ const string& market = "SH");
149
156
 
157
+ /**
158
+ * @brief 聚合其他K线周期统计值,聚合计算指定K线类型数据均值到以上下文中的K线周期
159
+ * @param ktype 指定K线周期
160
+ * @param fill_null 是否填充null数据
161
+ * @param unit 聚合周期单位,默认为1。按上下文K线 unit 个周期计算
162
+ * @return Indicator
163
+ */
164
+ #define AGG_FUNC_DEFINE(agg_name) \
165
+ Indicator HKU_API agg_name(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN, \
166
+ bool fill_null = false, int unit = 1);
167
+
168
+ #define AGG_FUNC_IMP(agg_name) \
169
+ Indicator HKU_API agg_name(const Indicator& ind, const KQuery::KType& ktype, bool fill_null, \
170
+ int unit) { \
171
+ Parameter params; \
172
+ params.set<string>("ktype", ktype); \
173
+ params.set<bool>("fill_null", fill_null); \
174
+ params.set<int>("unit", unit); \
175
+ return getExtIndicator(#agg_name, ind, params); \
176
+ }
177
+
178
+ AGG_FUNC_DEFINE(AGG_MEAN)
179
+ AGG_FUNC_DEFINE(AGG_COUNT)
180
+ AGG_FUNC_DEFINE(AGG_SUM)
181
+ AGG_FUNC_DEFINE(AGG_MAX)
182
+ AGG_FUNC_DEFINE(AGG_MIN)
183
+ AGG_FUNC_DEFINE(AGG_MAD)
184
+ AGG_FUNC_DEFINE(AGG_MEDIAN)
185
+ AGG_FUNC_DEFINE(AGG_PROD)
186
+
187
+ Indicator HKU_API AGG_STD(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
188
+ bool fill_null = false, int unit = 1, int ddof = 1);
189
+ Indicator HKU_API AGG_VAR(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
190
+ bool fill_null = false, int unit = 1, int ddof = 1);
191
+ Indicator HKU_API AGG_QUANTILE(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
192
+ bool fill_null = false, int unit = 1, double quantile = 0.75);
193
+
194
+ /** @} */
150
195
  } // namespace hku
@@ -7,7 +7,9 @@
7
7
 
8
8
  #pragma once
9
9
 
10
+ #include <arrow/api.h>
10
11
  #include "hikyuu/Stock.h"
12
+ #include "hikyuu/indicator/Indicator.h"
11
13
 
12
14
  namespace hku {
13
15
 
@@ -53,4 +55,23 @@ size_t getStockExtraCount(const Stock& stk, const string& ktype);
53
55
  bool getStockExtraIndexRange(const Stock& stk, const KQuery& query, size_t& out_start,
54
56
  size_t& out_end);
55
57
 
58
+ KDataImpPtr getKDataImp(const Stock& stk, const KQuery& query);
59
+
60
+ //-------------------------------
61
+ // Views 扩展
62
+ //-------------------------------
63
+
64
+ std::shared_ptr<arrow::Table> getIndicatorsViewParallel(const StockList& stks,
65
+ const IndicatorList& inds,
66
+ const KQuery& query, const string& market);
67
+
68
+ std::shared_ptr<arrow::Table> getIndicatorsViewParallel(const StockList& stks,
69
+ const IndicatorList& inds,
70
+ const Datetime& date, size_t cal_len,
71
+ const KQuery::KType& ktype,
72
+ const string& market);
73
+
74
+ std::shared_ptr<arrow::Table> getMarketViewParallel(const StockList& stks, const Datetime& date,
75
+ const string& market);
76
+
56
77
  } // namespace hku
@@ -7,6 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
+ #include <arrow/api.h>
10
11
  #include "hikyuu/utilities/plugin/PluginBase.h"
11
12
 
12
13
  namespace hku {
@@ -33,6 +34,21 @@ public:
33
34
 
34
35
  virtual bool getStockExtraIndexRange(const Stock& stk, const KQuery& query, size_t& out_start,
35
36
  size_t& out_end) = 0;
37
+
38
+ virtual KDataImpPtr getKDataImp(const Stock& stk, const KQuery& query) = 0;
39
+
40
+ virtual std::shared_ptr<arrow::Table> getIndicatorsViewParallel(const StockList& stks,
41
+ const IndicatorList& inds,
42
+ const KQuery& query,
43
+ const string& market) = 0;
44
+
45
+ virtual std::shared_ptr<arrow::Table> getIndicatorsViewParallel(
46
+ const StockList& stks, const IndicatorList& inds, const Datetime& date, size_t cal_len,
47
+ const KQuery::KType& ktype, const string& market) = 0;
48
+
49
+ virtual std::shared_ptr<arrow::Table> getMarketViewParallel(const StockList& stks,
50
+ const Datetime& date,
51
+ const string& market) = 0;
36
52
  };
37
53
 
38
54
  } // namespace hku
@@ -54,6 +54,7 @@ public:
54
54
  * 以便用于计算当前市值
55
55
  * @param tm 指定的交易管理实例
56
56
  * @param datetime 统计截止时刻
57
+ * @param ktype k线类型
57
58
  */
58
59
  virtual Performance getExtPerformance(const TMPtr& tm, const Datetime& datetime,
59
60
  const KQuery::KType& ktype) = 0;
@@ -54,10 +54,11 @@ std::vector<T> python_bytes_to_vector(const py::bytes& obj) {
54
54
 
55
55
  template <typename T>
56
56
  std::vector<T> python_list_to_vector(const py::sequence& obj) {
57
+ // 如果 len(obj) 长度为零,即使类型不是所期望的也可能成功,但无风险
57
58
  auto total = len(obj);
58
59
  std::vector<T> vect(total);
59
60
  for (auto i = 0; i < total; ++i) {
60
- vect[i] = obj[i].cast<T>();
61
+ vect[i] = py::cast<T>(obj[i]);
61
62
  }
62
63
  return vect;
63
64
  }
@@ -86,16 +87,23 @@ std::string to_py_str(const T& item) {
86
87
  // 直接使用 pybind11 重载 _clone,在 C++ 中会丢失 python 中的类型
87
88
  // 参考:https://github.com/pybind/pybind11/issues/1049 进行修改
88
89
  // PYBIND11_OVERLOAD(IndicatorImpPtr, IndicatorImp, _clone, );
89
- #define PY_CLONE(pyclassname, classname) \
90
- public: \
91
- std::shared_ptr<classname> _clone() override { \
92
- auto self = py::cast(this); \
93
- auto cloned = self.attr("_clone")(); \
94
- \
95
- auto keep_python_state_alive = std::make_shared<py::object>(cloned); \
96
- auto ptr = cloned.cast<pyclassname*>(); \
97
- \
98
- return std::shared_ptr<classname>(keep_python_state_alive, ptr); \
90
+ #define PY_CLONE(pyclassname, classname) \
91
+ public: \
92
+ std::shared_ptr<classname> _clone() override { \
93
+ if (isPythonObject()) { \
94
+ py::gil_scoped_acquire acquire; \
95
+ auto self = py::cast(this); \
96
+ auto cloned = self.attr("_clone")(); \
97
+ auto keep_python_state_alive = std::make_shared<py::object>(cloned); \
98
+ auto ptr = cloned.cast<pyclassname*>(); \
99
+ return std::shared_ptr<classname>(keep_python_state_alive, ptr); \
100
+ } \
101
+ return this->_clone(); \
102
+ } \
103
+ \
104
+ protected: \
105
+ inline bool isPythonObject() const override { \
106
+ return true; \
99
107
  }
100
108
 
101
109
  // 用于检查已 py::object 方式传递的函数参数个数是否符合预期
@@ -47,7 +47,6 @@ public:
47
47
  /**
48
48
  * 简单的文本统计报告,用于直接输出打印。
49
49
  * @note 只有运行 statistics 后或 Performance 本身为从 TM 获取的结果时才生效
50
- * @param datetime 指定的截止时刻
51
50
  * @return
52
51
  */
53
52
  string report();
@@ -106,6 +106,11 @@ public:
106
106
  /** 继承子类必须实现私有变量的克隆接口 */
107
107
  virtual TradeCostPtr _clone() = 0;
108
108
 
109
+ protected:
110
+ virtual bool isPythonObject() const {
111
+ return false;
112
+ }
113
+
109
114
  private:
110
115
  string m_name;
111
116
 
@@ -225,6 +225,7 @@ public:
225
225
  * @param goalPrice 目标价格
226
226
  * @param planPrice 计划买入价格
227
227
  * @param from 记录是哪个系统部件发出的买入指示
228
+ * @param remark 买入备注
228
229
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
229
230
  */
230
231
  virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -242,6 +243,7 @@ public:
242
243
  * @param goalPrice 新的目标价格
243
244
  * @param planPrice 原计划卖出价格
244
245
  * @param from 记录是哪个系统部件发出的卖出指示
246
+ * @param remark 卖出备注
245
247
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
246
248
  */
247
249
  virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -259,6 +261,7 @@ public:
259
261
  * @param goalPrice 目标价格
260
262
  * @param planPrice 计划卖空价格
261
263
  * @param from 记录是哪个系统部件发出的买入指示
264
+ * @param remark 备注
262
265
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
263
266
  */
264
267
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -276,6 +279,7 @@ public:
276
279
  * @param goalPrice 目标价格
277
280
  * @param planPrice 计划买入价格
278
281
  * @param from 记录是哪个系统部件发出的卖出指示
282
+ * @param remark 备注
279
283
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
280
284
  */
281
285
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -521,6 +521,7 @@ public:
521
521
  * @param goalPrice 目标价格
522
522
  * @param planPrice 计划买入价格
523
523
  * @param from 记录是哪个系统部件发出的买入指示
524
+ * @param remark 备注
524
525
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
525
526
  */
526
527
  virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -541,6 +542,7 @@ public:
541
542
  * @param goalPrice 新的目标价格
542
543
  * @param planPrice 原计划卖出价格
543
544
  * @param from 记录是哪个系统部件发出的卖出指示
545
+ * @param remark 卖出备注
544
546
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
545
547
  */
546
548
  virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -561,6 +563,7 @@ public:
561
563
  * @param goalPrice 目标价格
562
564
  * @param planPrice 计划卖空价格
563
565
  * @param from 记录是哪个系统部件发出的买入指示
566
+ * @param remark 备注
564
567
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
565
568
  */
566
569
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -581,6 +584,7 @@ public:
581
584
  * @param goalPrice 目标价格
582
585
  * @param planPrice 计划买入价格
583
586
  * @param from 记录是哪个系统部件发出的卖出指示
587
+ * @param remark 备注
584
588
  * @return 返回对应的交易记录,如果操作失败,business等于BUSINESS_INVALID
585
589
  */
586
590
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
@@ -716,13 +720,13 @@ public:
716
720
  * 统计截至某一时刻的系统绩效, datetime必须大于等于lastDatetime,
717
721
  * 以便用于计算当前市值
718
722
  * @param datetime 统计截止时刻
723
+ * @param ktype k线类型
719
724
  */
720
725
  Performance getPerformance(const Datetime& datetime = Datetime::now(),
721
726
  const KQuery::KType& ktype = KQuery::DAY);
722
727
 
723
728
  /**
724
729
  * @brief 获取指定时刻时账户的最大回撤百分比(负数)(仅根据收盘价计算)
725
- * @param tm 指定账户
726
730
  * @param date 指定日期(包含该时刻)
727
731
  * @param ktype k线类型
728
732
  * @return price_t
@@ -765,6 +769,11 @@ public:
765
769
  std::vector<std::pair<Datetime, double>> getProfitPercentYearly(
766
770
  const Datetime& datetime = Datetime::now());
767
771
 
772
+ protected:
773
+ virtual bool isPythonObject() const {
774
+ return false;
775
+ }
776
+
768
777
  protected:
769
778
  string m_name; // 账户名称
770
779
  TradeCostPtr m_costfunc; // 成本算法
@@ -101,6 +101,11 @@ public:
101
101
  static void adjustWeight(SystemWeightList& sw_list, double can_allocate_weight,
102
102
  bool auto_adjust, bool ignore_zero);
103
103
 
104
+ protected:
105
+ virtual bool isPythonObject() const {
106
+ return false;
107
+ }
108
+
104
109
  private:
105
110
  void initParam();
106
111
 
@@ -109,6 +109,11 @@ public:
109
109
  return m_values.cend();
110
110
  }
111
111
 
112
+ protected:
113
+ virtual bool isPythonObject() const {
114
+ return false;
115
+ }
116
+
112
117
  protected:
113
118
  string m_name;
114
119
  KData m_kdata;
@@ -93,6 +93,11 @@ public:
93
93
  /** 子类克隆接口 */
94
94
  virtual EnvironmentPtr _clone() = 0;
95
95
 
96
+ protected:
97
+ virtual bool isPythonObject() const {
98
+ return false;
99
+ }
100
+
96
101
  protected:
97
102
  string m_name;
98
103
  KQuery m_query;
@@ -152,6 +152,11 @@ public:
152
152
  /** 子类克隆私有变量接口 */
153
153
  virtual MoneyManagerPtr _clone() = 0;
154
154
 
155
+ protected:
156
+ virtual bool isPythonObject() const {
157
+ return false;
158
+ }
159
+
155
160
  protected:
156
161
  string m_name;
157
162
  KQuery m_query;
@@ -10,8 +10,6 @@
10
10
  #include "hikyuu/KData.h"
11
11
  #include "ScoreRecord.h"
12
12
 
13
- #define MF_USE_MULTI_THREAD 1
14
-
15
13
  namespace hku {
16
14
 
17
15
  /**
@@ -114,7 +112,7 @@ public:
114
112
  const vector<ScoreRecordList>& getAllScores();
115
113
 
116
114
  /**
117
- * 获取合成因子的IC, 长度与参考日期同
115
+ * 获取合成因子的IC, 长度与参考日期同 (非严格IC模式)
118
116
  * @note ndays 对于使用 IC/ICIR 加权的新因子,最好保持好 ic_n 一致,
119
117
  * 但对于等权计算的新因子,不一定非要使用 ic_n 计算。
120
118
  * 所以,ndays 增加了一个特殊值 0, 表示直接使用 ic_n 参数计算 IC
@@ -145,6 +143,11 @@ public:
145
143
  virtual MultiFactorPtr _clone() = 0;
146
144
  virtual IndicatorList _calculate(const vector<IndicatorList>&) = 0;
147
145
 
146
+ protected:
147
+ virtual bool isPythonObject() const {
148
+ return false;
149
+ }
150
+
148
151
  private:
149
152
  /** 执行计算 */
150
153
  void calculate();
@@ -115,6 +115,10 @@ private:
115
115
  const string& mode);
116
116
 
117
117
  protected:
118
+ virtual bool isPythonObject() const {
119
+ return false;
120
+ }
121
+
118
122
  // 跟踪打印当前TM持仓情况
119
123
  void traceMomentTMAfterRunAtOpen(const Datetime& date);
120
124
  void traceMomentTMAfterRunAtClose(const Datetime& date);
@@ -82,6 +82,11 @@ public:
82
82
  /** 子类计算接口,由setTO调用 */
83
83
  virtual void _calculate() = 0;
84
84
 
85
+ protected:
86
+ virtual bool isPythonObject() const {
87
+ return false;
88
+ }
89
+
85
90
  protected:
86
91
  string m_name;
87
92
  KData m_kdata;
@@ -48,7 +48,6 @@ public:
48
48
  * 添加备选股票及其交易策略原型
49
49
  * @param stock 备选股票
50
50
  * @param protoSys 交易系统策略原型
51
- * @return 如果 protoSys 无效 或 stock 无效,则返回 false, 否则返回 true
52
51
  */
53
52
  void addStock(const Stock& stock, const SystemPtr& protoSys);
54
53
 
@@ -57,7 +56,6 @@ public:
57
56
  * @note 如果存在无效的stock,则自动忽略,不会返回false
58
57
  * @param stkList 备选股票列表
59
58
  * @param protoSys 交易系统策略原型
60
- * @return 如果 protoSys 无效则返回false,否则返回 true
61
59
  */
62
60
  void addStockList(const StockList& stkList, const SystemPtr& protoSys);
63
61
 
@@ -134,6 +132,11 @@ public:
134
132
 
135
133
  virtual string str() const;
136
134
 
135
+ protected:
136
+ virtual bool isPythonObject() const {
137
+ return false;
138
+ }
139
+
137
140
  private:
138
141
  void initParam();
139
142
 
@@ -130,6 +130,11 @@ public:
130
130
  /** 子类计算接口,在setTO中调用 */
131
131
  virtual void _calculate(const KData&) = 0;
132
132
 
133
+ protected:
134
+ virtual bool isPythonObject() const {
135
+ return false;
136
+ }
137
+
133
138
  private:
134
139
  void initParam();
135
140