hikyuu 2.7.3__py3-none-win_amd64.whl → 2.7.5__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 (217) hide show
  1. hikyuu/__init__.py +3 -1
  2. hikyuu/__init__.pyi +14 -13
  3. hikyuu/analysis/__init__.pyi +1 -0
  4. hikyuu/analysis/analysis.pyi +2 -1
  5. hikyuu/core.pyi +3 -2
  6. hikyuu/cpp/core310.pyd +0 -0
  7. hikyuu/cpp/core310.pyi +80 -46
  8. hikyuu/cpp/core311.pyd +0 -0
  9. hikyuu/cpp/core311.pyi +80 -46
  10. hikyuu/cpp/core312.pyd +0 -0
  11. hikyuu/cpp/core312.pyi +80 -46
  12. hikyuu/cpp/core313.pyd +0 -0
  13. hikyuu/cpp/core313.pyi +80 -46
  14. hikyuu/cpp/hikyuu.dll +0 -0
  15. hikyuu/cpp/hikyuu.lib +0 -0
  16. hikyuu/cpp/mimalloc-redirect.dll +0 -0
  17. hikyuu/cpp/mimalloc.dll +0 -0
  18. hikyuu/data/clickhouse_upgrade/0002.sql +9 -0
  19. hikyuu/data/common_mysql.py +1 -1
  20. hikyuu/data/em_block_to_mysql.py +16 -4
  21. hikyuu/data/em_block_to_sqlite.py +16 -4
  22. hikyuu/data/hku_config_template.py +1 -1
  23. hikyuu/data/mysql_upgrade/0030.sql +3 -0
  24. hikyuu/data/pytdx_to_h5.py +2 -2
  25. hikyuu/data/pytdx_to_mysql.py +5 -5
  26. hikyuu/data/sqlite_upgrade/0030.sql +5 -0
  27. hikyuu/draw/__init__.pyi +1 -1
  28. hikyuu/draw/drawplot/__init__.pyi +1 -1
  29. hikyuu/draw/drawplot/bokeh_draw.pyi +7 -6
  30. hikyuu/draw/drawplot/echarts_draw.pyi +7 -6
  31. hikyuu/draw/drawplot/matplotlib_draw.py +19 -11
  32. hikyuu/draw/drawplot/matplotlib_draw.pyi +7 -6
  33. hikyuu/examples/notebook/001-overview.ipynb +112 -78
  34. hikyuu/examples/notebook/004-IndicatorOverview.ipynb +52 -65
  35. hikyuu/examples/notebook/006-TradeManager.ipynb +402 -291
  36. hikyuu/examples/notebook/008-Pickle.ipynb +25 -17
  37. hikyuu/examples/notebook/009-RealData.ipynb +36 -38
  38. hikyuu/examples/notebook/Demo/Demo2.ipynb +146 -116
  39. hikyuu/extend.pyi +4 -3
  40. hikyuu/gui/data/UseTdxImportToH5Thread.py +4 -2
  41. hikyuu/gui/start_qmt.py +1 -1
  42. hikyuu/hub.pyi +6 -6
  43. hikyuu/include/hikyuu/Block.h +9 -9
  44. hikyuu/include/hikyuu/HistoryFinanceInfo.h +3 -3
  45. hikyuu/include/hikyuu/KData.h +51 -28
  46. hikyuu/include/hikyuu/KDataImp.h +12 -7
  47. hikyuu/include/hikyuu/KDataPrivatedBufferImp.h +13 -7
  48. hikyuu/include/hikyuu/KDataSharedBufferImp.h +8 -6
  49. hikyuu/include/hikyuu/KQuery.h +11 -11
  50. hikyuu/include/hikyuu/KRecord.h +1 -1
  51. hikyuu/include/hikyuu/MarketInfo.h +10 -10
  52. hikyuu/include/hikyuu/Stock.h +30 -30
  53. hikyuu/include/hikyuu/StockManager.h +11 -10
  54. hikyuu/include/hikyuu/StockTypeInfo.h +9 -9
  55. hikyuu/include/hikyuu/StockWeight.h +9 -9
  56. hikyuu/include/hikyuu/TimeLineRecord.h +1 -1
  57. hikyuu/include/hikyuu/TransRecord.h +1 -1
  58. hikyuu/include/hikyuu/data_driver/BlockInfoDriver.h +6 -0
  59. hikyuu/include/hikyuu/data_driver/KDataDriver.h +4 -3
  60. hikyuu/include/hikyuu/indicator/IndParam.h +1 -1
  61. hikyuu/include/hikyuu/indicator/Indicator.h +56 -27
  62. hikyuu/include/hikyuu/indicator/Indicator2InImp.h +0 -4
  63. hikyuu/include/hikyuu/indicator/IndicatorImp.h +146 -73
  64. hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +11 -1
  65. hikyuu/include/hikyuu/indicator/crt/IC.h +19 -14
  66. hikyuu/include/hikyuu/indicator/crt/ICIR.h +4 -7
  67. hikyuu/include/hikyuu/indicator/imp/IAbs.h +1 -0
  68. hikyuu/include/hikyuu/indicator/imp/IAcos.h +1 -0
  69. hikyuu/include/hikyuu/indicator/imp/IAd.h +0 -2
  70. hikyuu/include/hikyuu/indicator/imp/IAdvance.h +3 -0
  71. hikyuu/include/hikyuu/indicator/imp/IAma.h +3 -0
  72. hikyuu/include/hikyuu/indicator/imp/IAsin.h +1 -0
  73. hikyuu/include/hikyuu/indicator/imp/IAtan.h +1 -0
  74. hikyuu/include/hikyuu/indicator/imp/IAtr.h +2 -3
  75. hikyuu/include/hikyuu/indicator/imp/IBackset.h +2 -4
  76. hikyuu/include/hikyuu/indicator/imp/IBlockSetNum.h +3 -0
  77. hikyuu/include/hikyuu/indicator/imp/ICeil.h +1 -0
  78. hikyuu/include/hikyuu/indicator/imp/IContext.h +0 -3
  79. hikyuu/include/hikyuu/indicator/imp/ICorr.h +3 -0
  80. hikyuu/include/hikyuu/indicator/imp/ICos.h +1 -0
  81. hikyuu/include/hikyuu/indicator/imp/ICost.h +0 -2
  82. hikyuu/include/hikyuu/indicator/imp/ICount.h +2 -1
  83. hikyuu/include/hikyuu/indicator/imp/ICval.h +1 -4
  84. hikyuu/include/hikyuu/indicator/imp/ICycle.h +0 -2
  85. hikyuu/include/hikyuu/indicator/imp/IDecline.h +3 -0
  86. hikyuu/include/hikyuu/indicator/imp/IDevsq.h +4 -1
  87. hikyuu/include/hikyuu/indicator/imp/IDiff.h +1 -0
  88. hikyuu/include/hikyuu/indicator/imp/IDma.h +2 -0
  89. hikyuu/include/hikyuu/indicator/imp/IDropna.h +0 -4
  90. hikyuu/include/hikyuu/indicator/imp/IEma.h +3 -1
  91. hikyuu/include/hikyuu/indicator/imp/IEvery.h +5 -1
  92. hikyuu/include/hikyuu/indicator/imp/IExist.h +5 -1
  93. hikyuu/include/hikyuu/indicator/imp/IExp.h +1 -0
  94. hikyuu/include/hikyuu/indicator/imp/IFilter.h +4 -5
  95. hikyuu/include/hikyuu/indicator/imp/IFinance.h +1 -2
  96. hikyuu/include/hikyuu/indicator/imp/IFloor.h +1 -0
  97. hikyuu/include/hikyuu/indicator/imp/IHhvbars.h +5 -1
  98. hikyuu/include/hikyuu/indicator/imp/IHighLine.h +5 -1
  99. hikyuu/include/hikyuu/indicator/imp/IHsl.h +0 -2
  100. hikyuu/include/hikyuu/indicator/imp/IIc.h +3 -6
  101. hikyuu/include/hikyuu/indicator/imp/IInBlock.h +1 -2
  102. hikyuu/include/hikyuu/indicator/imp/IIntpart.h +1 -0
  103. hikyuu/include/hikyuu/indicator/imp/IIsInf.h +1 -0
  104. hikyuu/include/hikyuu/indicator/imp/IIsInfa.h +1 -0
  105. hikyuu/include/hikyuu/indicator/imp/IIsLastBar.h +0 -1
  106. hikyuu/include/hikyuu/indicator/imp/IIsNa.h +1 -0
  107. hikyuu/include/hikyuu/indicator/imp/IJumpDown.h +1 -0
  108. hikyuu/include/hikyuu/indicator/imp/IJumpUp.h +1 -0
  109. hikyuu/include/hikyuu/indicator/imp/IKData.h +1 -2
  110. hikyuu/include/hikyuu/indicator/imp/ILiuTongPan.h +0 -2
  111. hikyuu/include/hikyuu/indicator/imp/ILn.h +1 -0
  112. hikyuu/include/hikyuu/indicator/imp/ILog.h +1 -0
  113. hikyuu/include/hikyuu/indicator/imp/ILowLine.h +5 -1
  114. hikyuu/include/hikyuu/indicator/imp/ILowLineBars.h +5 -1
  115. hikyuu/include/hikyuu/indicator/imp/IMa.h +6 -1
  116. hikyuu/include/hikyuu/indicator/imp/IMacd.h +2 -0
  117. hikyuu/include/hikyuu/indicator/imp/INot.h +1 -0
  118. hikyuu/include/hikyuu/indicator/imp/IPow.h +3 -1
  119. hikyuu/include/hikyuu/indicator/imp/IQuantileTrunc.h +1 -0
  120. hikyuu/include/hikyuu/indicator/imp/IRecover.h +3 -0
  121. hikyuu/include/hikyuu/indicator/imp/IRef.h +3 -1
  122. hikyuu/include/hikyuu/indicator/imp/IResult.h +1 -0
  123. hikyuu/include/hikyuu/indicator/imp/IReverse.h +1 -0
  124. hikyuu/include/hikyuu/indicator/imp/IRoc.h +6 -1
  125. hikyuu/include/hikyuu/indicator/imp/IRocp.h +5 -1
  126. hikyuu/include/hikyuu/indicator/imp/IRocr.h +5 -1
  127. hikyuu/include/hikyuu/indicator/imp/IRocr100.h +5 -1
  128. hikyuu/include/hikyuu/indicator/imp/IRound.h +1 -0
  129. hikyuu/include/hikyuu/indicator/imp/IRoundDown.h +1 -0
  130. hikyuu/include/hikyuu/indicator/imp/IRoundUp.h +1 -0
  131. hikyuu/include/hikyuu/indicator/imp/ISaftyLoss.h +1 -0
  132. hikyuu/include/hikyuu/indicator/imp/ISign.h +1 -0
  133. hikyuu/include/hikyuu/indicator/imp/ISin.h +1 -0
  134. hikyuu/include/hikyuu/indicator/imp/ISlope.h +5 -1
  135. hikyuu/include/hikyuu/indicator/imp/ISma.h +2 -0
  136. hikyuu/include/hikyuu/indicator/imp/ISpearman.h +3 -0
  137. hikyuu/include/hikyuu/indicator/imp/ISqrt.h +1 -0
  138. hikyuu/include/hikyuu/indicator/imp/IStdev.h +5 -1
  139. hikyuu/include/hikyuu/indicator/imp/IStdp.h +5 -1
  140. hikyuu/include/hikyuu/indicator/imp/ISum.h +6 -1
  141. hikyuu/include/hikyuu/indicator/imp/ITan.h +1 -0
  142. hikyuu/include/hikyuu/indicator/imp/ITime.h +1 -2
  143. hikyuu/include/hikyuu/indicator/imp/ITimeLine.h +0 -2
  144. hikyuu/include/hikyuu/indicator/imp/ITr.h +1 -2
  145. hikyuu/include/hikyuu/indicator/imp/IVar.h +5 -1
  146. hikyuu/include/hikyuu/indicator/imp/IVarp.h +5 -1
  147. hikyuu/include/hikyuu/indicator/imp/IVigor.h +0 -2
  148. hikyuu/include/hikyuu/indicator/imp/IWma.h +5 -1
  149. hikyuu/include/hikyuu/indicator/imp/IZongGuBen.h +1 -2
  150. hikyuu/include/hikyuu/indicator_talib/imp/TaAdosc.h +0 -2
  151. hikyuu/include/hikyuu/indicator_talib/imp/TaSar.h +0 -2
  152. hikyuu/include/hikyuu/indicator_talib/imp/TaSarext.h +0 -4
  153. hikyuu/include/hikyuu/indicator_talib/imp/TaStoch.h +0 -3
  154. hikyuu/include/hikyuu/indicator_talib/imp/TaStochf.h +0 -2
  155. hikyuu/include/hikyuu/indicator_talib/imp/TaUltosc.h +0 -2
  156. hikyuu/include/hikyuu/indicator_talib/imp/ta_defines.h +2 -4
  157. hikyuu/include/hikyuu/indicator_talib/imp/ta_imp.h +70 -90
  158. hikyuu/include/hikyuu/plugin/hkuextra.h +2 -0
  159. hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +2 -0
  160. hikyuu/include/hikyuu/python/pybind_utils.h +22 -5
  161. hikyuu/include/hikyuu/trade_manage/TradeCostBase.h +5 -3
  162. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +9 -2
  163. hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +8 -3
  164. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +5 -2
  165. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -2
  166. hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +5 -2
  167. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +23 -19
  168. hikyuu/include/hikyuu/trade_sys/multifactor/NormalizeBase.h +6 -3
  169. hikyuu/include/hikyuu/trade_sys/multifactor/ScoresFilterBase.h +5 -2
  170. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -3
  171. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +4 -4
  172. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -4
  173. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +4 -4
  174. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +5 -2
  175. hikyuu/include/hikyuu/trade_sys/profitgoal/ProfitGoalBase.h +4 -2
  176. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +12 -2
  177. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +1 -1
  178. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor2.h +1 -1
  179. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +1 -0
  180. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector2.h +1 -0
  181. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +0 -2
  182. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +0 -4
  183. hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +5 -2
  184. hikyuu/include/hikyuu/trade_sys/slippage/SlippageBase.h +5 -2
  185. hikyuu/include/hikyuu/trade_sys/stoploss/StoplossBase.h +5 -2
  186. hikyuu/include/hikyuu/trade_sys/system/System.h +5 -2
  187. hikyuu/include/hikyuu/utilities/LruCache.h +299 -0
  188. hikyuu/include/hikyuu/utilities/arithmetic.h +2 -2
  189. hikyuu/include/hikyuu/utilities/omp_macro.h +25 -0
  190. hikyuu/include/hikyuu/utilities/plugin/PluginManager.h +5 -0
  191. hikyuu/include/hikyuu/utilities/thread/GlobalStealThreadPool.h +72 -19
  192. hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +0 -4
  193. hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +0 -4
  194. hikyuu/include/hikyuu/utilities/thread/algorithm.h +286 -0
  195. hikyuu/include/hikyuu/version.h +4 -4
  196. hikyuu/plugin/backtest.dll +0 -0
  197. hikyuu/plugin/checkdata.dll +0 -0
  198. hikyuu/plugin/clickhousedriver.dll +0 -0
  199. hikyuu/plugin/dataserver.dll +0 -0
  200. hikyuu/plugin/dataserver_parquet.dll +0 -0
  201. hikyuu/plugin/device.dll +0 -0
  202. hikyuu/plugin/extind.dll +0 -0
  203. hikyuu/plugin/hkuextra.dll +0 -0
  204. hikyuu/plugin/import2ch.dll +0 -0
  205. hikyuu/plugin/import2hdf5.dll +0 -0
  206. hikyuu/plugin/import2mysql.dll +0 -0
  207. hikyuu/plugin/tmreport.dll +0 -0
  208. hikyuu/test/Indicator.py +1 -2
  209. hikyuu/trade_manage/__init__.pyi +6 -5
  210. hikyuu/trade_manage/trade.pyi +6 -5
  211. hikyuu/util/__init__.pyi +1 -1
  212. hikyuu/util/singleton.pyi +1 -1
  213. {hikyuu-2.7.3.dist-info → hikyuu-2.7.5.dist-info}/METADATA +2 -13
  214. {hikyuu-2.7.3.dist-info → hikyuu-2.7.5.dist-info}/RECORD +217 -210
  215. {hikyuu-2.7.3.dist-info → hikyuu-2.7.5.dist-info}/WHEEL +1 -1
  216. {hikyuu-2.7.3.dist-info → hikyuu-2.7.5.dist-info}/entry_points.txt +0 -0
  217. {hikyuu-2.7.3.dist-info → hikyuu-2.7.5.dist-info}/top_level.txt +0 -0
@@ -45,13 +45,13 @@ public:
45
45
 
46
46
  public:
47
47
  Indicator() : m_imp(make_shared<IndicatorImp>()) {}
48
- Indicator(const IndicatorImpPtr& imp);
49
- Indicator(const Indicator& ind);
48
+ Indicator(const IndicatorImpPtr& imp) noexcept;
49
+ Indicator(const Indicator& ind) noexcept;
50
50
  Indicator(Indicator&& ind) noexcept;
51
51
  virtual ~Indicator();
52
52
 
53
- Indicator& operator=(const Indicator&);
54
- Indicator& operator=(Indicator&&);
53
+ Indicator& operator=(const Indicator&) noexcept;
54
+ Indicator& operator=(Indicator&&) noexcept;
55
55
 
56
56
  /** 使用已有参数计算新值,返回全新的Indicator */
57
57
  Indicator operator()(const Indicator& ind);
@@ -63,8 +63,10 @@ public:
63
63
  Indicator operator()();
64
64
 
65
65
  /** 指标名称 */
66
- string name() const;
67
- void name(const string& name);
66
+ string name() const noexcept;
67
+ void name(const string& name) noexcept;
68
+
69
+ IndicatorImp::OPType getOPType() const noexcept;
68
70
 
69
71
  /** 返回形如:Name(param1_val,param2_val,...) */
70
72
  string long_name() const;
@@ -79,23 +81,29 @@ public:
79
81
  /** 获取上下文 */
80
82
  KData getContext() const;
81
83
 
84
+ /** 在有上下文时,自动将上下文扩展至当前最新数据并计算 */
85
+ void extend();
86
+
82
87
  /** 显示指标公式 */
83
88
  string formula() const;
84
89
 
85
90
  /** 结果中需抛弃的个数 */
86
- size_t discard() const;
91
+ size_t discard() const noexcept;
87
92
 
88
93
  /** 设置抛弃的个数,如果小于原有的discard则无效 */
89
- void setDiscard(size_t discard);
94
+ void setDiscard(size_t discard) noexcept;
95
+
96
+ /** 根据自身数值,更新抛弃的个数, force=true则强制更新, 否则从当前自身的 discard() 开始更新 */
97
+ void updateDiscard(bool force = false) noexcept;
90
98
 
91
99
  /** 返回有几个结果集输出 */
92
- size_t getResultNumber() const;
100
+ size_t getResultNumber() const noexcept;
93
101
 
94
102
  /** 判断是否为空 **/
95
- bool empty() const;
103
+ bool empty() const noexcept;
96
104
 
97
105
  /** 获取大小 **/
98
- size_t size() const;
106
+ size_t size() const noexcept;
99
107
 
100
108
  /** 只获取第一个结果集中相应位置输出,等同于get(pos, 0) */
101
109
  value_t operator[](size_t pos) const;
@@ -130,7 +138,8 @@ public:
130
138
  size_t getPos(Datetime) const;
131
139
 
132
140
  /**
133
- * 以指标的方式获取指定的结果集
141
+ * 以指标的方式获取指定的结果集,不保留其公式。
142
+ * 对于不在需要进行运算的指标,可以通过该方法清除已占用的内存。
134
143
  * @param num 指定的结果集
135
144
  */
136
145
  Indicator getResult(size_t num) const;
@@ -171,22 +180,21 @@ public:
171
180
  return m_imp->getParam<ValueType>(name);
172
181
  }
173
182
 
174
- bool supportIndParam() const;
175
183
  bool haveIndParam(const string& name) const;
176
184
  void setIndParam(const string& name, const Indicator& ind);
177
185
  void setIndParam(const string& name, const IndParam& ind);
178
186
  IndParam getIndParam(const string& name) const;
179
187
  const IndicatorImpPtr getIndParamImp(const string& name) const;
180
188
 
181
- IndicatorImpPtr getImp() const {
189
+ IndicatorImpPtr getImp() const noexcept {
182
190
  return m_imp;
183
191
  }
184
192
 
185
- value_t* data(size_t result_idx = 0) {
193
+ value_t* data(size_t result_idx = 0) noexcept {
186
194
  return m_imp ? m_imp->data(result_idx) : nullptr;
187
195
  }
188
196
 
189
- value_t const* data(size_t result_idx = 0) const {
197
+ value_t const* data(size_t result_idx = 0) const noexcept {
190
198
  return m_imp ? m_imp->data(result_idx) : nullptr;
191
199
  }
192
200
 
@@ -194,10 +202,10 @@ public:
194
202
  * 判断两个ind的值是否相等
195
203
  * @note operator==重载生成新的新的Indicator,此函数用于对两个ind进行值比较
196
204
  */
197
- bool equal(const Indicator& other) const;
205
+ bool equal(const Indicator& other) const noexcept;
198
206
 
199
207
  /** 判断是否是同一个实例 */
200
- bool isSame(const Indicator& other) const {
208
+ bool isSame(const Indicator& other) const noexcept {
201
209
  return !m_imp && m_imp == other.m_imp;
202
210
  }
203
211
 
@@ -208,6 +216,8 @@ public:
208
216
 
209
217
  string str() const;
210
218
 
219
+ bool isPythonObject() const noexcept;
220
+
211
221
  public:
212
222
  class Iterator {
213
223
  private:
@@ -245,6 +255,15 @@ public:
245
255
 
246
256
  typedef Iterator iterator;
247
257
 
258
+ public:
259
+ static void enableIncrementCalculate(bool flag) {
260
+ IndicatorImp::enableIncrementCalculate(flag);
261
+ }
262
+
263
+ static bool enableIncrementCalculate() {
264
+ return IndicatorImp::enableIncrementCalculate();
265
+ }
266
+
248
267
  protected:
249
268
  IndicatorImpPtr m_imp;
250
269
 
@@ -261,39 +280,49 @@ private:
261
280
  /** @ingroup Indicator */
262
281
  typedef vector<Indicator> IndicatorList;
263
282
 
264
- inline string Indicator::name() const {
283
+ inline string Indicator::name() const noexcept {
265
284
  return m_imp ? m_imp->name() : "IndicatorImp";
266
285
  }
267
286
 
268
- inline void Indicator::name(const string& name) {
287
+ inline void Indicator::name(const string& name) noexcept {
269
288
  if (m_imp) {
270
289
  m_imp->name(name);
271
290
  }
272
291
  }
273
292
 
293
+ inline IndicatorImp::OPType Indicator::getOPType() const noexcept {
294
+ return m_imp ? m_imp->getOPType() : IndicatorImp::INVALID;
295
+ }
296
+
274
297
  inline string Indicator::long_name() const {
275
298
  return m_imp ? m_imp->long_name() : "IndicatorImp()";
276
299
  }
277
300
 
278
- inline size_t Indicator::discard() const {
301
+ inline size_t Indicator::discard() const noexcept {
279
302
  return m_imp ? m_imp->discard() : 0;
280
303
  }
281
304
 
282
- inline void Indicator::setDiscard(size_t discard) {
305
+ inline void Indicator::setDiscard(size_t discard) noexcept {
283
306
  if (m_imp) {
284
307
  m_imp->setDiscard(discard);
285
308
  }
286
309
  }
287
310
 
288
- inline size_t Indicator::getResultNumber() const {
311
+ inline void Indicator::updateDiscard(bool force) noexcept {
312
+ if (m_imp) {
313
+ m_imp->updateDiscard(force);
314
+ }
315
+ }
316
+
317
+ inline size_t Indicator::getResultNumber() const noexcept {
289
318
  return m_imp ? m_imp->getResultNumber() : 0;
290
319
  }
291
320
 
292
- inline bool Indicator::empty() const {
321
+ inline bool Indicator::empty() const noexcept {
293
322
  return (!m_imp || m_imp->size() == 0) ? true : false;
294
323
  }
295
324
 
296
- inline size_t Indicator::size() const {
325
+ inline size_t Indicator::size() const noexcept {
297
326
  return m_imp ? m_imp->size() : 0;
298
327
  }
299
328
 
@@ -369,8 +398,8 @@ inline const IndicatorImpPtr Indicator::getIndParamImp(const string& name) const
369
398
  return m_imp ? m_imp->getIndParamImp(name) : IndicatorImpPtr();
370
399
  }
371
400
 
372
- inline bool Indicator::supportIndParam() const {
373
- return m_imp ? m_imp->supportIndParam() : false;
401
+ inline bool Indicator::isPythonObject() const noexcept {
402
+ return m_imp ? m_imp->isPythonObject() : false;
374
403
  }
375
404
 
376
405
  //--------------------------------------------------------------
@@ -22,10 +22,6 @@ public:
22
22
 
23
23
  virtual IndicatorImpPtr _clone() override;
24
24
 
25
- virtual bool needSelfAlikeCompare() const noexcept override {
26
- return true;
27
- }
28
-
29
25
  virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
30
26
 
31
27
  virtual void getSelfInnerNodesWithInputConext(vector<IndicatorImpPtr>& nodes) const override;
@@ -9,6 +9,7 @@
9
9
  #ifndef INDICATORIMP_H_
10
10
  #define INDICATORIMP_H_
11
11
 
12
+ #include <mimalloc.h>
12
13
  #include "../config.h"
13
14
  #include "../KData.h"
14
15
  #include "../utilities/Parameter.h"
@@ -30,7 +31,7 @@ class HKU_API IndicatorImp : public enable_shared_from_this<IndicatorImp> {
30
31
  friend HKU_API std::ostream& operator<<(std::ostream& os, const IndicatorImp& imp);
31
32
 
32
33
  public:
33
- enum OPType {
34
+ enum OPType : uint8_t {
34
35
  LEAF, ///< 叶子节点
35
36
  OP, /// OP(OP1,OP2) OP1->calcalue(OP2->calculate(ind))
36
37
  ADD, ///< 加
@@ -56,6 +57,7 @@ public:
56
57
  #else
57
58
  typedef double value_t;
58
59
  #endif
60
+ typedef vector<value_t, mi_stl_allocator<value_t>> buffer_t;
59
61
 
60
62
  public:
61
63
  /** 默认构造函数 */
@@ -68,13 +70,15 @@ public:
68
70
  typedef shared_ptr<IndicatorImp> IndicatorImpPtr;
69
71
  IndicatorImpPtr operator()(const Indicator& ind);
70
72
 
71
- size_t getResultNumber() const;
73
+ size_t getResultNumber() const noexcept;
74
+ OPType getOPType() const noexcept;
72
75
 
73
- size_t discard() const;
76
+ size_t discard() const noexcept;
74
77
 
75
- void setDiscard(size_t discard);
78
+ void setDiscard(size_t discard) noexcept;
79
+ void updateDiscard(bool force = false) noexcept;
76
80
 
77
- size_t size() const;
81
+ size_t size() const noexcept;
78
82
 
79
83
  value_t get(size_t pos, size_t num = 0) const;
80
84
 
@@ -112,8 +116,8 @@ public:
112
116
  /** 数据中是否包含 nan 值 */
113
117
  bool existNan(size_t result_idx = 0) const;
114
118
 
115
- const string& name() const;
116
- void name(const string& name);
119
+ const string& name() const noexcept;
120
+ void name(const string& name) noexcept;
117
121
 
118
122
  /** 返回形如:Name(param1=val,param2=val,...) */
119
123
  string long_name() const;
@@ -121,7 +125,7 @@ public:
121
125
  virtual string formula() const;
122
126
  virtual string str() const;
123
127
 
124
- bool isLeaf() const;
128
+ bool isLeaf() const noexcept;
125
129
 
126
130
  Indicator calculate();
127
131
 
@@ -129,7 +133,7 @@ public:
129
133
 
130
134
  void setContext(const KData&);
131
135
 
132
- KData getContext() const;
136
+ const KData& getContext() const;
133
137
 
134
138
  void add(OPType, IndicatorImpPtr left, IndicatorImpPtr right);
135
139
 
@@ -137,6 +141,12 @@ public:
137
141
 
138
142
  IndicatorImpPtr clone();
139
143
 
144
+ bool isPythonObject() const noexcept;
145
+
146
+ /** 仅用于两个结果集数量相同、长度相同的指标交换数据,不交换其他参数。失败抛出异常 */
147
+ void swap(IndicatorImp* other);
148
+ void swap(IndicatorImp* other, size_t other_result_idx, size_t self_result_idx);
149
+
140
150
  bool haveIndParam(const string& name) const;
141
151
  void setIndParam(const string& name, const Indicator& ind);
142
152
  void setIndParam(const string& name, const IndParam& ind);
@@ -151,28 +161,46 @@ public:
151
161
  // ===================
152
162
  virtual void _calculate(const Indicator&);
153
163
 
164
+ // ====== start 动态周期计算相关接口 ======
165
+ /** 动态周期计算,子类可重载该函数,默认不支持动态周期计算 */
154
166
  virtual void _dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {}
155
167
 
156
- /** 是否支持指标动态参数 */
157
- virtual bool supportIndParam() const {
158
- return false;
168
+ /** 是否必须串行计算 */
169
+ bool isSerial() const noexcept {
170
+ return m_is_serial;
159
171
  }
172
+ // ====== end 动态周期计算相关接口 ======
160
173
 
161
- /** 是否必须串行计算 */
162
- virtual bool isSerial() const {
163
- return false;
174
+ // ====== start 增量计算相关接口 =======
175
+ /** 是否支持增量计算 */
176
+ virtual bool supportIncrementCalculate() const;
177
+
178
+ virtual size_t min_increment_start() const {
179
+ return 0;
164
180
  }
165
181
 
182
+ virtual void _increment_calculate(const Indicator& ind, size_t start_pos) {}
183
+ // ====== end 增量计算相关接口 =======
184
+
166
185
  virtual IndicatorImpPtr _clone() {
167
186
  return make_shared<IndicatorImp>();
168
187
  }
169
188
 
170
- virtual bool isNeedContext() const {
171
- return false;
189
+ bool isNeedContext() const noexcept {
190
+ return m_need_context;
172
191
  }
173
192
 
174
193
  virtual void _dyn_calculate(const Indicator&);
175
194
 
195
+ public:
196
+ static void enableIncrementCalculate(bool flag) {
197
+ ms_enable_increment_calculate = flag;
198
+ }
199
+
200
+ static bool enableIncrementCalculate() {
201
+ return ms_enable_increment_calculate;
202
+ }
203
+
176
204
  public:
177
205
  // ===================
178
206
  // 内部特殊用途公共接口
@@ -184,21 +212,21 @@ public:
184
212
  /** 判断指标公式中是否包含指定名称的指标(特殊用途) */
185
213
  bool contains(const string& name) const;
186
214
 
187
- value_t* data(size_t result_idx = 0);
188
- value_t const* data(size_t result_idx = 0) const;
215
+ value_t* data(size_t result_idx = 0) noexcept;
216
+ value_t const* data(size_t result_idx = 0) const noexcept;
189
217
 
190
218
  void getAllSubNodes(vector<IndicatorImpPtr>& nodes) const;
191
219
 
192
- IndicatorImpPtr getRightNode() const;
193
- IndicatorImpPtr getLeftNode() const;
194
- IndicatorImpPtr getThreeNode() const;
220
+ IndicatorImpPtr getRightNode() const noexcept;
221
+ IndicatorImpPtr getLeftNode() const noexcept;
222
+ IndicatorImpPtr getThreeNode() const noexcept;
195
223
  void printTree(bool show_long_name = false) const;
196
224
  void printAllSubTrees(bool show_long_name = false) const;
197
225
  void printLeaves(bool show_long_name = false) const;
198
226
 
199
227
  /* 特殊指标需自己实现 selfAlike 函数的, needSelfAlikeCompare 应返回 true */
200
- virtual bool needSelfAlikeCompare() const noexcept {
201
- return false;
228
+ bool needSelfAlikeCompare() const noexcept {
229
+ return m_need_self_alike_compare;
202
230
  }
203
231
 
204
232
  // 特殊指标需自己实现 selfAlike 函数,返回true表示两个指标等效
@@ -213,8 +241,11 @@ public:
213
241
  virtual void getSeparateKTypeLeafSubNodes(vector<IndicatorImpPtr>& nodes) const {}
214
242
 
215
243
  private:
216
- void initContext();
217
244
  bool needCalculate();
245
+ bool can_inner_calculate();
246
+ bool can_increment_calculate();
247
+ bool increment_execute_leaf_or_op(const Indicator& ind);
248
+ size_t increment_execute();
218
249
  void execute_add();
219
250
  void execute_sub();
220
251
  void execute_mul();
@@ -230,6 +261,7 @@ private:
230
261
  void execute_or();
231
262
  void execute_weave();
232
263
  void execute_if();
264
+ size_t increment_execute_if();
233
265
 
234
266
  static void inner_repeatALikeNodes(vector<IndicatorImpPtr>& sub_nodes);
235
267
  void repeatALikeNodes();
@@ -252,19 +284,24 @@ private:
252
284
  protected:
253
285
  static size_t _get_step_start(size_t pos, size_t step, size_t discard);
254
286
 
255
- // 用于动态参数时,更新 discard
256
- void _update_discard();
257
-
258
- virtual bool isPythonObject() const;
287
+ void onlySetContext(const KData&);
259
288
 
260
289
  protected:
261
290
  string m_name;
262
- size_t m_discard;
263
- size_t m_result_num;
264
- vector<value_t>* m_pBuffer[MAX_RESULT_NUM];
265
-
266
- bool m_need_calculate;
267
- OPType m_optype;
291
+ size_t m_discard{0};
292
+ size_t m_result_num{0};
293
+ KData m_context;
294
+ KData m_old_context;
295
+
296
+ buffer_t* m_pBuffer[MAX_RESULT_NUM];
297
+
298
+ bool m_need_context{false};
299
+ bool m_is_python_object{false};
300
+ bool m_need_self_alike_compare{false};
301
+ bool m_is_serial{false};
302
+ bool m_need_calculate{true};
303
+ bool m_param_changed{true};
304
+ OPType m_optype{LEAF};
268
305
  IndicatorImpPtr m_left;
269
306
  IndicatorImpPtr m_right;
270
307
  IndicatorImpPtr m_three;
@@ -273,11 +310,11 @@ protected:
273
310
  IndicatorImp* m_parent{nullptr}; // can't use shared_from_this in python, so not weak_ptr
274
311
 
275
312
  public:
276
- static void initDynEngine();
277
- static void releaseDynEngine();
313
+ static void initEngine();
314
+ static void releaseEngine();
278
315
 
279
316
  protected:
280
- static ThreadPool* ms_tg;
317
+ static bool ms_enable_increment_calculate;
281
318
 
282
319
  #if HKU_SUPPORT_SERIALIZATION
283
320
  private:
@@ -289,7 +326,14 @@ private:
289
326
  ar& BOOST_SERIALIZATION_NVP(m_params);
290
327
  ar& BOOST_SERIALIZATION_NVP(m_discard);
291
328
  ar& BOOST_SERIALIZATION_NVP(m_result_num);
329
+ ar& BOOST_SERIALIZATION_NVP(m_context);
330
+ ar& BOOST_SERIALIZATION_NVP(m_old_context);
331
+ ar& BOOST_SERIALIZATION_NVP(m_need_context);
332
+ ar& BOOST_SERIALIZATION_NVP(m_is_python_object);
333
+ ar& BOOST_SERIALIZATION_NVP(m_need_self_alike_compare);
334
+ ar& BOOST_SERIALIZATION_NVP(m_is_serial);
292
335
  ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
336
+ ar& BOOST_SERIALIZATION_NVP(m_param_changed);
293
337
  ar& BOOST_SERIALIZATION_NVP(m_optype);
294
338
  ar& BOOST_SERIALIZATION_NVP(m_left);
295
339
  ar& BOOST_SERIALIZATION_NVP(m_right);
@@ -308,7 +352,7 @@ private:
308
352
  for (size_t i = 0; i < act_result_num; ++i) {
309
353
  size_t count = size();
310
354
  ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
311
- vector<value_t>& values = *m_pBuffer[i];
355
+ buffer_t& values = *m_pBuffer[i];
312
356
  for (size_t j = 0; j < count; j++) {
313
357
  if (std::isnan(values[j])) {
314
358
  ar& boost::serialization::make_nvp<string>("item", nan);
@@ -329,7 +373,14 @@ private:
329
373
  ar& BOOST_SERIALIZATION_NVP(m_params);
330
374
  ar& BOOST_SERIALIZATION_NVP(m_discard);
331
375
  ar& BOOST_SERIALIZATION_NVP(m_result_num);
376
+ ar& BOOST_SERIALIZATION_NVP(m_context);
377
+ ar& BOOST_SERIALIZATION_NVP(m_old_context);
378
+ ar& BOOST_SERIALIZATION_NVP(m_need_context);
379
+ ar& BOOST_SERIALIZATION_NVP(m_is_python_object);
380
+ ar& BOOST_SERIALIZATION_NVP(m_need_self_alike_compare);
381
+ ar& BOOST_SERIALIZATION_NVP(m_is_serial);
332
382
  ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
383
+ ar& BOOST_SERIALIZATION_NVP(m_param_changed);
333
384
  ar& BOOST_SERIALIZATION_NVP(m_optype);
334
385
  ar& BOOST_SERIALIZATION_NVP(m_left);
335
386
  ar& BOOST_SERIALIZATION_NVP(m_right);
@@ -342,7 +393,7 @@ private:
342
393
  for (size_t i = 0; i < act_result_num; ++i) {
343
394
  size_t count = 0;
344
395
  ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
345
- vector<value_t>& values = *m_pBuffer[i];
396
+ buffer_t& values = *m_pBuffer[i];
346
397
  values.resize(count);
347
398
  for (size_t j = 0; j < count; j++) {
348
399
  std::string vstr;
@@ -364,10 +415,6 @@ private:
364
415
  #endif
365
416
  };
366
417
 
367
- #if HKU_SUPPORT_SERIALIZATION
368
- BOOST_SERIALIZATION_ASSUME_ABSTRACT(IndicatorImp)
369
- #endif
370
-
371
418
  #if HKU_SUPPORT_SERIALIZATION
372
419
  #define INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION \
373
420
  private: \
@@ -387,21 +434,15 @@ public: \
387
434
  return make_shared<classname>(); \
388
435
  }
389
436
 
390
- #define INDICATOR_IMP_SUPPORT_DYNAMIC_STEP(classname) \
391
- public: \
392
- virtual void _calculate(const Indicator& ind) override; \
393
- virtual void _dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) override; \
394
- virtual bool supportIndParam() const override { \
395
- return true; \
396
- } \
397
- virtual IndicatorImpPtr _clone() override { \
398
- return make_shared<classname>(); \
399
- }
437
+ #define INDICATOR_IMP_SUPPORT_DYNAMIC_CYCLE \
438
+ public: \
439
+ virtual void _dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) override;
400
440
 
401
- #define INDICATOR_NEED_CONTEXT \
402
- public: \
403
- virtual bool isNeedContext() const override { \
404
- return true; \
441
+ #define INDICATOR_IMP_SUPPORT_INCREMENT \
442
+ public: \
443
+ virtual void _increment_calculate(const Indicator& ind, size_t start_pos) override; \
444
+ virtual bool supportIncrementCalculate() const override { \
445
+ return true; \
405
446
  }
406
447
 
407
448
  /** 获取 OPType 名称字符串 */
@@ -412,38 +453,49 @@ typedef shared_ptr<IndicatorImp> IndicatorImpPtr;
412
453
  HKU_API std::ostream& operator<<(std::ostream&, const IndicatorImp&);
413
454
  HKU_API std::ostream& operator<<(std::ostream&, const IndicatorImpPtr&);
414
455
 
415
- inline size_t IndicatorImp::getResultNumber() const {
456
+ inline IndicatorImp::OPType IndicatorImp::getOPType() const noexcept {
457
+ return m_optype;
458
+ }
459
+
460
+ inline size_t IndicatorImp::getResultNumber() const noexcept {
416
461
  return m_result_num;
417
462
  }
418
463
 
419
- inline size_t IndicatorImp::discard() const {
464
+ inline size_t IndicatorImp::discard() const noexcept {
420
465
  return m_discard;
421
466
  }
422
467
 
423
- inline size_t IndicatorImp::size() const {
468
+ inline size_t IndicatorImp::size() const noexcept {
424
469
  return m_pBuffer[0] ? m_pBuffer[0]->size() : 0;
425
470
  }
426
471
 
427
- inline const string& IndicatorImp::name() const {
472
+ inline const string& IndicatorImp::name() const noexcept {
428
473
  return m_name;
429
474
  }
430
475
 
431
- inline void IndicatorImp::name(const string& name) {
476
+ inline void IndicatorImp::name(const string& name) noexcept {
432
477
  m_name = name;
433
478
  }
434
479
 
435
- inline bool IndicatorImp::isLeaf() const {
480
+ inline bool IndicatorImp::isLeaf() const noexcept {
436
481
  return m_optype == LEAF ? true : false;
437
482
  }
438
483
 
439
- inline KData IndicatorImp::getContext() const {
440
- return getParam<KData>("kdata");
484
+ inline const KData& IndicatorImp::getContext() const {
485
+ return m_context;
441
486
  }
442
487
 
443
488
  inline void IndicatorImp::setContext(const Stock& stock, const KQuery& query) {
444
489
  setContext(stock.getKData(query));
445
490
  }
446
491
 
492
+ inline void IndicatorImp::onlySetContext(const KData& k) {
493
+ if (m_context != k) {
494
+ m_old_context = m_context;
495
+ m_context = k;
496
+ }
497
+ }
498
+
447
499
  inline const IndicatorImp::ind_param_map_t& IndicatorImp::getIndParams() const {
448
500
  return m_ind_params;
449
501
  }
@@ -452,11 +504,11 @@ inline bool IndicatorImp::haveIndParam(const string& name) const {
452
504
  return m_ind_params.find(name) != m_ind_params.end();
453
505
  }
454
506
 
455
- inline IndicatorImp::value_t* IndicatorImp::data(size_t result_idx) {
507
+ inline IndicatorImp::value_t* IndicatorImp::data(size_t result_idx) noexcept {
456
508
  return m_pBuffer[result_idx] ? m_pBuffer[result_idx]->data() : nullptr;
457
509
  }
458
510
 
459
- inline IndicatorImp::value_t const* IndicatorImp::data(size_t result_idx) const {
511
+ inline IndicatorImp::value_t const* IndicatorImp::data(size_t result_idx) const noexcept {
460
512
  return m_pBuffer[result_idx] ? m_pBuffer[result_idx]->data() : nullptr;
461
513
  }
462
514
 
@@ -464,22 +516,43 @@ inline size_t IndicatorImp::_get_step_start(size_t pos, size_t step, size_t disc
464
516
  return step == 0 || pos < discard + step ? discard : pos + 1 - step;
465
517
  }
466
518
 
467
- inline bool IndicatorImp::isPythonObject() const {
468
- return false;
519
+ inline bool IndicatorImp::isPythonObject() const noexcept {
520
+ return m_is_python_object;
469
521
  }
470
522
 
471
- inline IndicatorImpPtr IndicatorImp::getRightNode() const {
523
+ inline IndicatorImpPtr IndicatorImp::getRightNode() const noexcept {
472
524
  return m_right;
473
525
  }
474
526
 
475
- inline IndicatorImpPtr IndicatorImp::getLeftNode() const {
527
+ inline IndicatorImpPtr IndicatorImp::getLeftNode() const noexcept {
476
528
  return m_left;
477
529
  }
478
530
 
479
- inline IndicatorImpPtr IndicatorImp::getThreeNode() const {
531
+ inline IndicatorImpPtr IndicatorImp::getThreeNode() const noexcept {
480
532
  return m_three;
481
533
  }
482
534
 
535
+ inline std::ostream& operator<<(std::ostream& os, const IndicatorImp::buffer_t& p) {
536
+ if (p.empty()) {
537
+ os << "[]";
538
+ return os;
539
+ }
540
+
541
+ size_t len = p.size();
542
+ const size_t print = 3;
543
+ os << "[";
544
+ for (size_t i = 0; i < len; i++) {
545
+ if ((i < print) || (i + print >= len)) {
546
+ os << p[i];
547
+ if (i + 1 != len)
548
+ os << ", ";
549
+ } else if (i == 3)
550
+ os << "..., ";
551
+ }
552
+ os << "]";
553
+ return os;
554
+ }
555
+
483
556
  } /* namespace hku */
484
557
 
485
558
  #if FMT_VERSION >= 90000
@@ -24,10 +24,20 @@ Indicator HKU_API CONTEXT(const Indicator& ind, bool fill_null = false, bool use
24
24
  Indicator HKU_API CONTEXT(bool fill_null = false, bool use_self_ktype = false,
25
25
  bool use_self_recover_type = false);
26
26
 
27
+ /**
28
+ * @brief 通过指定股票,设置指标独立上下文指标
29
+ * @param ind 输入指标公式,如果自身携带上下文,将被忽略
30
+ * @param stk 指定股票
31
+ * @param fill_null 是否填充空值,默认为 false
32
+ * @return Indicator
33
+ */
34
+ Indicator HKU_API CONTEXT(const Indicator& ind, const Stock& stk, bool fill_null = false);
35
+
27
36
  /**
28
37
  * 获取指标上下文
29
38
  * @note Indicator::getContext()方法获取的是当前的上下文,但对于 CONTEXT
30
- * 独立上下文指标无法获取其指定的独立上下文,需用此方法获取
39
+ * 独立上下文指标无法获取其指定的独立上下文,需用此方法获取。
40
+ * 该指标一旦作为公式,参与计算,其上下文可能发生变化,但其stock保持不变,仅query范围发生改变
31
41
  * @param ind
32
42
  * @return KData
33
43
  */