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
@@ -0,0 +1,69 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-08-28
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "KDataImp.h"
11
+
12
+ namespace hku {
13
+
14
+ class HKU_API KDataSharedBufferImp : public KDataImp {
15
+ public:
16
+ KDataSharedBufferImp() = default;
17
+ KDataSharedBufferImp(const Stock& stock, const KQuery& query);
18
+ virtual ~KDataSharedBufferImp();
19
+
20
+ virtual bool empty() const override {
21
+ return m_size == 0;
22
+ }
23
+
24
+ virtual size_t size() const override {
25
+ return m_size;
26
+ }
27
+
28
+ virtual size_t startPos() const override {
29
+ return m_start;
30
+ }
31
+
32
+ virtual size_t endPos() const override {
33
+ return m_end;
34
+ }
35
+
36
+ virtual size_t lastPos() const override {
37
+ return m_end == 0 ? 0 : m_end - 1;
38
+ }
39
+
40
+ virtual size_t getPos(const Datetime& datetime) const override;
41
+
42
+ virtual const KRecord& getKRecord(size_t pos) const override;
43
+
44
+ virtual const KRecord& front() const override {
45
+ return m_data[0];
46
+ }
47
+
48
+ virtual const KRecord& back() const override {
49
+ return m_data[m_size - 1];
50
+ }
51
+
52
+ virtual const KRecord* data() const override {
53
+ return m_data;
54
+ }
55
+
56
+ virtual KRecord* data() override {
57
+ return m_data;
58
+ }
59
+
60
+ virtual DatetimeList getDatetimeList() const override;
61
+
62
+ private:
63
+ size_t m_start{0};
64
+ size_t m_end{0};
65
+ size_t m_size{0};
66
+ KRecord* m_data{nullptr};
67
+ };
68
+
69
+ } /* namespace hku */
@@ -47,10 +47,12 @@ public:
47
47
  static const string DAY5;
48
48
  static const string DAY7;
49
49
  static const string MIN3;
50
- static const string HOUR4;
51
- static const string HOUR6;
52
- static const string HOUR12;
53
- // static const string INVALID_KTYPE;
50
+ static const string HOUR4; // 默认不支持
51
+ static const string HOUR6; // 默认不支持
52
+ static const string HOUR12; // 默认不支持
53
+
54
+ static const string TIMELINE; // 分时
55
+ static const string TRANS; // 分笔
54
56
 
55
57
  /** 判断指定的K线类型是否有效 */
56
58
  static bool isValidKType(const string& ktype);
@@ -71,6 +73,8 @@ public:
71
73
 
72
74
  static int32_t getBaseKTypeInMin(const KType& ktype);
73
75
 
76
+ static int64_t getKTypeInSeconds(const KType& ktype);
77
+
74
78
  /**
75
79
  * 复权类型
76
80
  * @note 日线以上,如周线/月线不支持复权
@@ -175,6 +179,14 @@ public:
175
179
  */
176
180
  uint64_t hash() const;
177
181
 
182
+ /** 判断是否为右开区间,即未指定结束时间 */
183
+ bool isRightOpening() const {
184
+ if (m_queryType == DATE) {
185
+ return endDatetime().isNull();
186
+ }
187
+ return m_end == Null<int64_t>();
188
+ }
189
+
178
190
  /** 获取queryType名称,用于显示输出 */
179
191
  static string getQueryTypeName(QueryType);
180
192
 
@@ -17,7 +17,7 @@ namespace hku {
17
17
  * K线数据记录
18
18
  * @ingroup StockManage
19
19
  */
20
- class KRecord {
20
+ class HKU_API KRecord {
21
21
  public:
22
22
  Datetime datetime; ///< 日期,格式:YYYYMMDDHHMM 如:200901010930
23
23
  price_t openPrice; ///< 开盘价
@@ -58,6 +58,9 @@ public:
58
58
  bool isValid() const {
59
59
  return datetime == Null<Datetime>() ? false : true;
60
60
  }
61
+
62
+ public:
63
+ static const KRecord NullKRecord;
61
64
  };
62
65
 
63
66
  /** @ingroup StockManage */
@@ -29,6 +29,7 @@ typedef shared_ptr<KDataDriverConnectPool> KDataDriverConnectPoolPtr;
29
29
  class HKU_API KData;
30
30
  class HKU_API Parameter;
31
31
  class HKU_API Block;
32
+ class HKU_API KDataSharedBufferImp;
32
33
 
33
34
  /**
34
35
  * Stock基类,Application中一般使用StockPtr进行操作
@@ -36,6 +37,7 @@ class HKU_API Block;
36
37
  */
37
38
  class HKU_API Stock {
38
39
  friend class StockManager;
40
+ friend class KDataSharedBufferImp;
39
41
 
40
42
  private:
41
43
  static const string default_market;
@@ -162,7 +164,7 @@ public:
162
164
  */
163
165
  bool getIndexRange(const KQuery& query, size_t& out_start, size_t& out_end) const;
164
166
 
165
- /** 获取指定索引的K线数据记录,pos 无效时返回 Null<KRecord> */
167
+ /** 获取指定索引的K线数据记录,pos 无效时返回 KRecord::NullRecord */
166
168
  KRecord getKRecord(size_t pos, const KQuery::KType& dataType = KQuery::DAY) const;
167
169
 
168
170
  /** 根据数据类型(日线/周线等),获取指定日期的KRecord */
@@ -242,7 +244,10 @@ public:
242
244
  bool isNull() const;
243
245
 
244
246
  /** (临时函数)只用于更新缓存中的K线数据 **/
245
- void realtimeUpdate(KRecord, KQuery::KType ktype = KQuery::DAY);
247
+ void realtimeUpdate(KRecord, const KQuery::KType& ktype = KQuery::DAY);
248
+
249
+ /** 获取指定K线数据类型最后更新时间 */
250
+ Datetime getLastUpdateTime(const KQuery::KType& ktype) const;
246
251
 
247
252
  /**
248
253
  * 部分临时创建的 Stock, 直接设置KRecordList
@@ -259,7 +264,7 @@ private:
259
264
 
260
265
  // 以下函数属于基础操作添加了读锁
261
266
  size_t _getCountFromBuffer(const KQuery::KType& ktype) const;
262
- KRecord _getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const;
267
+ const KRecord& _getKRecordFromBuffer(size_t pos, const KQuery::KType& ktype) const;
263
268
  KRecordList _getKRecordListFromBuffer(size_t start_ix, size_t end_ix,
264
269
  KQuery::KType ktype) const;
265
270
  bool _getIndexRangeByDateFromBuffer(const KQuery&, size_t&, size_t&) const;
@@ -267,7 +272,7 @@ private:
267
272
  KRecordList _getKRecordList(const KQuery& query) const;
268
273
 
269
274
  // 仅供 StockManager 初始化时调用
270
- void setPreload(vector<KQuery::KType>& preload_ktypes);
275
+ void setPreload(const vector<KQuery::KType>& preload_ktypes);
271
276
 
272
277
  bool isPreload(KQuery::KType ktype) const;
273
278
 
@@ -305,6 +310,7 @@ struct HKU_API Stock::Data {
305
310
  std::unordered_set<string> m_ktype_preload; // 记录当前证券的K线数据是否需要预加载
306
311
  unordered_map<string, KRecordList*> pKData;
307
312
  unordered_map<string, std::shared_mutex*> pMutex;
313
+ unordered_map<string, Datetime> m_lastUpdate; // 记录各类型K线数据最后更新时间
308
314
 
309
315
  Data();
310
316
  Data(const string& market, const string& code, const string& name, uint32_t type, bool valid,
@@ -109,7 +109,7 @@ public:
109
109
  * @param market 指定的市场标识
110
110
  * @return 相应的市场信息,如果相应的市场信息不存在,则返回Null<MarketInfo>()
111
111
  */
112
- MarketInfo getMarketInfo(const string& market) const;
112
+ MarketInfo getMarketInfo(const string& market) const noexcept;
113
113
 
114
114
  /**
115
115
  * 获取指定市场代表指数证券
@@ -183,11 +183,19 @@ public:
183
183
  const ZhBond10List& getZhBond10() const;
184
184
 
185
185
  /**
186
- * 判断指定日期是否为节假日
187
- * @param d 指定日期
186
+ * 判断指定时间对应的日期是否为节假日(包含周六、周日)
187
+ * @note 仅支持中国大陆市场, Null<Datetime>() 将抛出异常
188
+ * @param d 指定时间
188
189
  */
189
190
  bool isHoliday(const Datetime& d) const;
190
191
 
192
+ /**
193
+ * 粗略判断指定时间是否为交易时间
194
+ * @param d 指定时间,Null<Datetime>() 将抛出异常
195
+ * @param market 指定市场
196
+ */
197
+ bool isTradingHours(const Datetime& d, const string& market = "SH") const;
198
+
191
199
  const string& getHistoryFinanceFieldName(size_t ix) const;
192
200
  size_t getHistoryFinanceFieldIndex(const string& name) const;
193
201
  vector<std::pair<size_t, string>> getHistoryFinanceAllFields() const;
@@ -22,10 +22,10 @@ public:
22
22
  Datetime datetime; // 时间
23
23
  price_t price; // 成交均价
24
24
  price_t vol; // 成交量
25
- int direct; // 买卖盘性质:1--sell 0--buy 2--集合竞价 其他未知
25
+ int32_t direct; // 买卖盘性质:1--sell 0--buy 2--集合竞价 其他未知
26
26
 
27
27
  TransRecord();
28
- TransRecord(const Datetime& datetime, price_t price, price_t vol, int direct);
28
+ TransRecord(const Datetime& datetime, price_t price, price_t vol, int32_t direct);
29
29
 
30
30
  bool isValid() const;
31
31
  };
@@ -119,6 +119,11 @@ public:
119
119
  */
120
120
  virtual TransList getTransList(const string& market, const string& code, const KQuery& query);
121
121
 
122
+ protected:
123
+ virtual bool isPythonObject() const {
124
+ return false;
125
+ }
126
+
122
127
  private:
123
128
  bool checkType();
124
129
 
@@ -157,9 +157,9 @@
157
157
  * @defgroup ThreadPool Thread Pool 线程池
158
158
  * @ingroup Utilities
159
159
  *
160
- * @defgroup View View数据视图
160
+ * @defgroup Views 数据视图
161
161
  * 数据视图, 属于用于显示、打印数据
162
- * @ingroup View
162
+ * @ingroup Views
163
163
  */
164
164
 
165
165
  /**
@@ -30,4 +30,12 @@ HKU_API SpotAgent* getGlobalSpotAgent();
30
30
 
31
31
  void HKU_API releaseGlobalSpotAgent();
32
32
 
33
+ inline bool spotAgentIsRunning() {
34
+ return getGlobalSpotAgent()->isRunning();
35
+ }
36
+
37
+ inline bool spotAgentIsConnected() {
38
+ return getGlobalSpotAgent()->isConnected();
39
+ }
40
+
33
41
  } // namespace hku
@@ -68,6 +68,10 @@ public:
68
68
  return m_server_addr;
69
69
  }
70
70
 
71
+ bool isConnected() const {
72
+ return m_connected;
73
+ }
74
+
71
75
  /**
72
76
  * 增加收到 Spot 数据时的处理函数
73
77
  * @note 仅能在停止状态时执行此操作,否则将抛出异常
@@ -99,9 +103,9 @@ public:
99
103
  static void setQuotationServer(const string& server);
100
104
 
101
105
  private:
102
- static string ms_pubUrl; // 数据发送服务地址
103
- static const char* ms_startTag; // 批次数据接收起始标记,用于判断启动了新的批次数据接收
104
- static const char* ms_endTag; // 批次数据接收接收标记,用于判断该批次数据更新结束
106
+ static string ms_pubUrl; // 数据发送服务地址
107
+ static const char* ms_startTag; // 批次数据接收起始标记,用于判断启动了新的批次数据接收
108
+ static const char* ms_endTag; // 批次数据接收接收标记,用于判断该批次数据更新结束
105
109
  static const char* ms_spotTopic; // 向数据发送服务订阅的主题
106
110
  static const size_t ms_startTagLength; // 批次数据接收起始标记长度
107
111
  static const size_t ms_endTagLength; // 批次数据接收结束标记长度
@@ -121,9 +125,10 @@ private:
121
125
  void work_thread();
122
126
 
123
127
  private:
124
- enum STATUS { WAITING, RECEIVING }; // 等待新的批次数据,正在接收批次数据中
125
- enum STATUS m_status = WAITING; // 当前内部状态
126
- std::atomic_bool m_stop = true; // 结束代理工作标识
128
+ enum STATUS { WAITING, RECEIVING }; // 等待新的批次数据,正在接收批次数据中
129
+ enum STATUS m_status = WAITING; // 当前内部状态
130
+ std::atomic_bool m_stop = true; // 结束代理工作标识
131
+ std::atomic_bool m_connected = false; // 是否已连接数据服务
127
132
 
128
133
  int m_revTimeout = 100; // 连接数据服务超时时长(毫秒)
129
134
  std::thread m_receiveThread; // 数据接收线程
@@ -137,7 +142,7 @@ private:
137
142
  // 下面属性被修改时需要加锁,以便可以使用多线程方式运行 strategy
138
143
  std::mutex m_mutex;
139
144
  list<std::function<void(const SpotRecord&)>> m_processList; // 已注册的 spot 处理函数列表
140
- list<std::function<void(Datetime)>> m_postProcessList; // 已注册的批次后处理函数列表
145
+ list<std::function<void(Datetime)>> m_postProcessList; // 已注册的批次后处理函数列表
141
146
  };
142
147
 
143
148
  } // namespace hku
@@ -110,6 +110,9 @@ public:
110
110
  */
111
111
  value_t get(size_t pos, size_t num = 0) const;
112
112
 
113
+ value_t front(size_t num = 0) const;
114
+ value_t back(size_t num = 0) const;
115
+
113
116
  /**
114
117
  * 获取指定位置的日期
115
118
  * @param pos 结果集中的位置
@@ -322,6 +325,14 @@ inline Indicator::value_t Indicator::get(size_t pos, size_t num) const {
322
325
  return m_imp->get(pos, num);
323
326
  }
324
327
 
328
+ inline Indicator::value_t Indicator::front(size_t num) const {
329
+ return m_imp->front(num);
330
+ }
331
+
332
+ inline Indicator::value_t Indicator::back(size_t num) const {
333
+ return m_imp->back(num);
334
+ }
335
+
325
336
  inline Datetime Indicator::getDatetime(size_t pos) const {
326
337
  return m_imp ? m_imp->getDatetime(pos) : Null<Datetime>();
327
338
  }
@@ -11,6 +11,7 @@
11
11
 
12
12
  namespace hku {
13
13
 
14
+ /* note: 双输入但同一上下文*/
14
15
  class Indicator2InImp : public IndicatorImp {
15
16
  public:
16
17
  Indicator2InImp();
@@ -21,6 +22,14 @@ public:
21
22
 
22
23
  virtual IndicatorImpPtr _clone() override;
23
24
 
25
+ virtual bool needSelfAlikeCompare() const noexcept override {
26
+ return true;
27
+ }
28
+
29
+ virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
30
+
31
+ virtual void getSelfInnerNodesWithInputConext(vector<IndicatorImpPtr>& nodes) const override;
32
+
24
33
  protected:
25
34
  Indicator prepare(const Indicator& ind);
26
35
 
@@ -78,6 +78,9 @@ public:
78
78
 
79
79
  value_t get(size_t pos, size_t num = 0) const;
80
80
 
81
+ value_t front(size_t num = 0) const;
82
+ value_t back(size_t num = 0) const;
83
+
81
84
  value_t getByDate(Datetime, size_t num = 0);
82
85
 
83
86
  Datetime getDatetime(size_t pos) const;
@@ -92,12 +95,6 @@ public:
92
95
  /** 以Indicator的方式获取指定的输出集,该方式包含了discard的信息 */
93
96
  IndicatorImpPtr getResult(size_t result_num);
94
97
 
95
- /** 判断是否和另一个指标等效,即计算效果相同 */
96
- bool alike(const IndicatorImp& other) const;
97
-
98
- /** 判断指标公式中是否包含指定名称的指标(特殊用途) */
99
- bool contains(const string& name) const;
100
-
101
98
  /**
102
99
  * 使用IndicatorImp(const Indicator&...)构造函数后,计算结果使用该函数,
103
100
  * 未做越界保护
@@ -149,9 +146,6 @@ public:
149
146
  typedef std::map<string, IndicatorImpPtr> ind_param_map_t;
150
147
  const ind_param_map_t& getIndParams() const;
151
148
 
152
- value_t* data(size_t result_idx = 0);
153
- value_t const* data(size_t result_idx = 0) const;
154
-
155
149
  // ===================
156
150
  // 子类接口
157
151
  // ===================
@@ -179,6 +173,45 @@ public:
179
173
 
180
174
  virtual void _dyn_calculate(const Indicator&);
181
175
 
176
+ public:
177
+ // ===================
178
+ // 内部特殊用途公共接口
179
+ // ===================
180
+
181
+ /** 判断是否和另一个指标等效,即计算效果相同 */
182
+ bool alike(const IndicatorImp& other) const;
183
+
184
+ /** 判断指标公式中是否包含指定名称的指标(特殊用途) */
185
+ bool contains(const string& name) const;
186
+
187
+ value_t* data(size_t result_idx = 0);
188
+ value_t const* data(size_t result_idx = 0) const;
189
+
190
+ void getAllSubNodes(vector<IndicatorImpPtr>& nodes) const;
191
+
192
+ IndicatorImpPtr getRightNode() const;
193
+ IndicatorImpPtr getLeftNode() const;
194
+ IndicatorImpPtr getThreeNode() const;
195
+ void printTree(bool show_long_name = false) const;
196
+ void printAllSubTrees(bool show_long_name = false) const;
197
+ void printLeaves(bool show_long_name = false) const;
198
+
199
+ /* 特殊指标需自己实现 selfAlike 函数的, needSelfAlikeCompare 应返回 true */
200
+ virtual bool needSelfAlikeCompare() const noexcept {
201
+ return false;
202
+ }
203
+
204
+ // 特殊指标需自己实现 selfAlike 函数,返回true表示两个指标等效
205
+ virtual bool selfAlike(const IndicatorImp& other) const noexcept {
206
+ return false;
207
+ }
208
+
209
+ // 使用输入上下文的特殊指标获取内部节点,以便合入指标树优化
210
+ virtual void getSelfInnerNodesWithInputConext(vector<IndicatorImpPtr>& nodes) const {}
211
+
212
+ // 指定独立 ktype 的叶子节点重载获取内部子节点
213
+ virtual void getSeparateKTypeLeafSubNodes(vector<IndicatorImpPtr>& nodes) const {}
214
+
182
215
  private:
183
216
  void initContext();
184
217
  bool needCalculate();
@@ -198,17 +231,32 @@ private:
198
231
  void execute_weave();
199
232
  void execute_if();
200
233
 
201
- std::vector<IndicatorImpPtr> getAllSubNodes() const;
234
+ static void inner_repeatALikeNodes(vector<IndicatorImpPtr>& sub_nodes);
202
235
  void repeatALikeNodes();
236
+ void repeatSeparateKTypeLeafALikeNodes();
237
+
238
+ void generateSpecialLeafSet();
203
239
 
204
240
  void _clearBuffer();
205
241
 
242
+ void _printTree(int depth = 0, bool isLast = true, bool show_long_name = false) const;
243
+
244
+ // 获取所有子树
245
+ vector<IndicatorImp*> getAllSubTrees() const;
246
+
247
+ // 获取子树中节点的数量
248
+ static size_t treeSize(IndicatorImp* tree);
249
+
250
+ static bool nodeInTree(IndicatorImp* node, IndicatorImp* tree);
251
+
206
252
  protected:
207
253
  static size_t _get_step_start(size_t pos, size_t step, size_t discard);
208
254
 
209
255
  // 用于动态参数时,更新 discard
210
256
  void _update_discard();
211
257
 
258
+ virtual bool isPythonObject() const;
259
+
212
260
  protected:
213
261
  string m_name;
214
262
  size_t m_discard;
@@ -296,17 +344,17 @@ private:
296
344
  ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
297
345
  vector<value_t>& values = *m_pBuffer[i];
298
346
  values.resize(count);
299
- for (size_t i = 0; i < count; i++) {
347
+ for (size_t j = 0; j < count; j++) {
300
348
  std::string vstr;
301
349
  ar >> boost::serialization::make_nvp<string>("item", vstr);
302
350
  if (vstr == "nan") {
303
- values[i] = std::numeric_limits<double>::quiet_NaN();
351
+ values[j] = std::numeric_limits<double>::quiet_NaN();
304
352
  } else if (vstr == "+inf") {
305
- values[i] = std::numeric_limits<double>::infinity();
353
+ values[j] = std::numeric_limits<double>::infinity();
306
354
  } else if (vstr == "-inf") {
307
- values[i] = 0.0 - std::numeric_limits<double>::infinity();
355
+ values[j] = 0.0 - std::numeric_limits<double>::infinity();
308
356
  } else {
309
- values[i] = std::atof(vstr.c_str());
357
+ values[j] = std::atof(vstr.c_str());
310
358
  }
311
359
  }
312
360
  }
@@ -392,6 +440,10 @@ inline KData IndicatorImp::getContext() const {
392
440
  return getParam<KData>("kdata");
393
441
  }
394
442
 
443
+ inline void IndicatorImp::setContext(const Stock& stock, const KQuery& query) {
444
+ setContext(stock.getKData(query));
445
+ }
446
+
395
447
  inline const IndicatorImp::ind_param_map_t& IndicatorImp::getIndParams() const {
396
448
  return m_ind_params;
397
449
  }
@@ -412,6 +464,22 @@ inline size_t IndicatorImp::_get_step_start(size_t pos, size_t step, size_t disc
412
464
  return step == 0 || pos < discard + step ? discard : pos + 1 - step;
413
465
  }
414
466
 
467
+ inline bool IndicatorImp::isPythonObject() const {
468
+ return false;
469
+ }
470
+
471
+ inline IndicatorImpPtr IndicatorImp::getRightNode() const {
472
+ return m_right;
473
+ }
474
+
475
+ inline IndicatorImpPtr IndicatorImp::getLeftNode() const {
476
+ return m_left;
477
+ }
478
+
479
+ inline IndicatorImpPtr IndicatorImp::getThreeNode() const {
480
+ return m_three;
481
+ }
482
+
415
483
  } /* namespace hku */
416
484
 
417
485
  #if FMT_VERSION >= 90000
@@ -90,6 +90,7 @@
90
90
  #include "crt/PRICELIST.h"
91
91
  #include "crt/RECOVER.h"
92
92
  #include "crt/REF.h"
93
+ #include "crt/REFX.h"
93
94
  #include "crt/REPLACE.h"
94
95
  #include "crt/RESULT.h"
95
96
  #include "crt/REVERSE.h"
@@ -18,7 +18,8 @@ namespace hku {
18
18
  * @param n 计算均值的周期窗口,必须为大于2的整数,默认为10天
19
19
  * @param fast_n 对应快速周期N,默认为2
20
20
  * @param slow_n 对应慢速EMA线的N值,默认为30,不过当超过60左右该指标会收敛不会有太大的影响
21
- * @ingroup Indicator 具有2个结果集,result(0)为AMA,result(1)为ER
21
+ * @return 具有2个结果集,result(0)为AMA,result(1)为ER
22
+ * @ingroup Indicator
22
23
  */
23
24
  Indicator HKU_API AMA(int n = 10, int fast_n = 2, int slow_n = 30);
24
25
  Indicator HKU_API AMA(int n, int fast_n, const IndParam& slow_n);
@@ -22,7 +22,7 @@ Indicator HKU_API ATR(int n = 14);
22
22
 
23
23
  /**
24
24
  * 平均真实波幅(Average True Range)
25
- * @param data 待计算的源数据
25
+ * @param kdata 待计算的源数据
26
26
  * @param n 计算均值的周期窗口,必须为大于1的整数
27
27
  * @ingroup Indicator
28
28
  */
@@ -15,6 +15,8 @@ namespace hku {
15
15
  * 独立上下文指标
16
16
  * @param ind 待包装指标
17
17
  * @param fill_null 是否填充空值,默认为 false
18
+ * @param use_self_ktype 使用自身独立上下文的K线类型,否则计算时将使用计算上下文中K线类型
19
+ * @param use_self_recover_type 使用自身独立上下文的复权类型,否则计算时将使用计算上下文中的复权类型
18
20
  * @ingroup Indicator
19
21
  */
20
22
  Indicator HKU_API CONTEXT(const Indicator& ind, bool fill_null = false, bool use_self_ktype = false,
@@ -14,6 +14,9 @@ namespace hku {
14
14
  /**
15
15
  * PF调仓周期指标,主要用于PF调仓日验证,及作为SG
16
16
  * @param k 关联的K线数据
17
+ * @param adjust_cycle 调仓周期,默认为1
18
+ * @param adjust_mode 调仓方式,默认为"query" day|week|month|quarter|year|query
19
+ * @param delay_to_trading_day 延迟至交易日,当调仓日为非交易日时,自动延迟至下一个交易日作为调仓日
17
20
  * @ingroup Indicator
18
21
  */
19
22
  Indicator CYCLE(const KData& k, int adjust_cycle = 1, const string& adjust_mode = "query",
@@ -23,7 +23,7 @@ namespace hku {
23
23
  * 算法:若Y=DMA(X,A) 则 Y=A*X+(1-A)*Y',其中Y'表示上一周期Y值。
24
24
  * 例如:DMA(CLOSE,VOL/CAPITAL)表示求以换手率作平滑因子的平均价
25
25
  * </pre>
26
- * @param ind1 待计算的数据
26
+ * @param x 待计算的数据
27
27
  * @param a 动态系数
28
28
  * @param fill_null 日期对齐时缺失数据填充nan值
29
29
  * @ingroup Indicator
@@ -14,28 +14,36 @@ namespace hku {
14
14
 
15
15
  /**
16
16
  * @brief 计算指定的因子相对于参考证券的 IC (实际为 RankIC)
17
+ * @note IC 原本需要 “t 时刻因子值→t+1 时刻收益”,改为计算 “t 时刻因子值→t 时刻之前 N
18
+ 天的收益”(比如过去 5 天的收益),并称之为 “当前 IC”。(否则当前值都会是缺失NA)
19
+ 如需严格“t 时刻因子值→t+1 时刻收益“计算,请设置 strict=True (注意此模式下, 后n位为 NA)
17
20
  * @param stks 证券组合
18
21
  * @param query 查询条件
19
22
  * @param ref_stk 参照证券,默认 sh000300 沪深300
20
23
  * @param n 时间窗口 (对应 n 日收益率)
21
24
  * @param spearman 使用 spearman 相关系数,否则为 pearson
25
+ * @param strict 严格模式, 遵循IC定义“t 时刻因子值→t+1 时刻收益”
22
26
  * @return Indicator
23
27
  * @ingroup Indicator
24
28
  */
25
29
  Indicator HKU_API IC(const StockList& stks, const KQuery& query,
26
- const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
30
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
31
+ bool strict = false);
27
32
 
28
33
  Indicator HKU_API IC(const Block& blk, const KQuery& query,
29
- const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
34
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
35
+ bool strict = false);
30
36
 
31
37
  inline Indicator IC(const Indicator& ind, const StockList& stks, const KQuery& query,
32
- const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
33
- return IC(stks, query, ref_stk, n, spearman)(ind);
38
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
39
+ bool strict = false) {
40
+ return IC(stks, query, ref_stk, n, spearman, strict)(ind);
34
41
  }
35
42
 
36
43
  inline Indicator IC(const Indicator& ind, const Block& blk, const KQuery& query,
37
- const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
38
- return IC(blk, query, ref_stk, n, spearman)(ind);
44
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
45
+ bool strict = false) {
46
+ return IC(blk, query, ref_stk, n, spearman, strict)(ind);
39
47
  }
40
48
 
41
49
  } // namespace hku