hikyuu 2.6.1__py3-none-win_amd64.whl → 2.6.3__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 (91) hide show
  1. hikyuu/__init__.py +1 -1
  2. hikyuu/__init__.pyi +22 -6
  3. hikyuu/analysis/__init__.pyi +16 -0
  4. hikyuu/analysis/analysis.pyi +17 -1
  5. hikyuu/core.pyi +18 -2
  6. hikyuu/cpp/core310.pyd +0 -0
  7. hikyuu/cpp/core310.pyi +391 -45
  8. hikyuu/cpp/core311.pyd +0 -0
  9. hikyuu/cpp/core311.pyi +391 -45
  10. hikyuu/cpp/core312.pyd +0 -0
  11. hikyuu/cpp/core312.pyi +391 -45
  12. hikyuu/cpp/core313.pyd +0 -0
  13. hikyuu/cpp/core313.pyi +391 -45
  14. hikyuu/cpp/core39.pyd +0 -0
  15. hikyuu/cpp/core39.pyi +391 -45
  16. hikyuu/cpp/hikyuu.dll +0 -0
  17. hikyuu/cpp/hikyuu.lib +0 -0
  18. hikyuu/cpp/sqlite3.dll +0 -0
  19. hikyuu/draw/__init__.pyi +1 -1
  20. hikyuu/draw/drawplot/__init__.pyi +1 -1
  21. hikyuu/draw/drawplot/bokeh_draw.pyi +19 -3
  22. hikyuu/draw/drawplot/echarts_draw.pyi +19 -3
  23. hikyuu/draw/drawplot/matplotlib_draw.py +22 -0
  24. hikyuu/draw/drawplot/matplotlib_draw.pyi +19 -3
  25. hikyuu/draw/kaufman.py +2 -2
  26. hikyuu/draw/kaufman.pyi +2 -2
  27. hikyuu/extend.py +0 -14
  28. hikyuu/extend.pyi +19 -6
  29. hikyuu/hub.pyi +6 -6
  30. hikyuu/include/hikyuu/Block.h +20 -0
  31. hikyuu/include/hikyuu/KQuery.h +8 -0
  32. hikyuu/include/hikyuu/Stock.h +1 -1
  33. hikyuu/include/hikyuu/StockManager.h +6 -0
  34. hikyuu/include/hikyuu/indicator/Indicator.h +5 -0
  35. hikyuu/include/hikyuu/indicator/IndicatorImp.h +8 -3
  36. hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +6 -2
  37. hikyuu/include/hikyuu/indicator/crt/INSUM.h +5 -10
  38. hikyuu/include/hikyuu/indicator/crt/RSI.h +2 -18
  39. hikyuu/include/hikyuu/plugin/backtest.h +3 -2
  40. hikyuu/include/hikyuu/plugin/extind.h +150 -0
  41. hikyuu/include/hikyuu/plugin/interface/BackTestPluginInterface.h +2 -1
  42. hikyuu/include/hikyuu/plugin/interface/ExtendIndicatorsPluginInterface.h +26 -0
  43. hikyuu/include/hikyuu/plugin/interface/plugins.h +2 -0
  44. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +7 -5
  45. hikyuu/include/hikyuu/strategy/Strategy.h +22 -9
  46. hikyuu/include/hikyuu/trade_manage/OrderBrokerBase.h +11 -4
  47. hikyuu/include/hikyuu/trade_manage/TradeManager.h +8 -5
  48. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +6 -4
  49. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +9 -1
  50. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +8 -5
  51. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +4 -1
  52. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +4 -1
  53. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -1
  54. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +4 -1
  55. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +2 -1
  56. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +2 -1
  57. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +2 -1
  58. hikyuu/include/hikyuu/trade_sys/multifactor/imp/WeightMultiFactor.h +1 -1
  59. hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +7 -4
  60. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +17 -13
  61. hikyuu/include/hikyuu/utilities/thread/{MQStealThreadPool.h → GlobalMQStealThreadPool.h} +12 -12
  62. hikyuu/include/hikyuu/utilities/thread/GlobalMQThreadPool.h +271 -0
  63. hikyuu/include/hikyuu/utilities/thread/{StealThreadPool.h → GlobalStealThreadPool.h} +11 -10
  64. hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +224 -0
  65. hikyuu/include/hikyuu/utilities/thread/InterruptFlag.h +16 -0
  66. hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +27 -70
  67. hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +18 -53
  68. hikyuu/include/hikyuu/utilities/thread/ThreadSafeQueue.h +4 -0
  69. hikyuu/include/hikyuu/utilities/thread/algorithm.h +9 -9
  70. hikyuu/include/hikyuu/utilities/thread/thread.h +4 -0
  71. hikyuu/include/hikyuu/version.h +4 -4
  72. hikyuu/plugin/backtest.dll +0 -0
  73. hikyuu/plugin/dataserver.dll +0 -0
  74. hikyuu/plugin/device.dll +0 -0
  75. hikyuu/plugin/extind.dll +0 -0
  76. hikyuu/plugin/import2hdf5.dll +0 -0
  77. hikyuu/trade_manage/__init__.pyi +19 -3
  78. hikyuu/trade_manage/broker.py +8 -8
  79. hikyuu/trade_manage/broker.pyi +4 -4
  80. hikyuu/trade_manage/broker_easytrader.py +3 -3
  81. hikyuu/trade_manage/broker_easytrader.pyi +2 -2
  82. hikyuu/trade_manage/broker_mail.py +2 -2
  83. hikyuu/trade_manage/broker_mail.pyi +2 -2
  84. hikyuu/trade_manage/trade.pyi +19 -3
  85. hikyuu/util/singleton.pyi +1 -1
  86. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/METADATA +1 -1
  87. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/RECORD +91 -86
  88. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/LICENSE +0 -0
  89. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/WHEEL +0 -0
  90. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/entry_points.txt +0 -0
  91. {hikyuu-2.6.1.dist-info → hikyuu-2.6.3.dist-info}/top_level.txt +0 -0
@@ -128,6 +128,24 @@ public:
128
128
  KData getLastKData(const Stock& stk, size_t lastnum, const KQuery::KType& ktype,
129
129
  KQuery::RecoverType recover_type = KQuery::NO_RECOVER) const;
130
130
 
131
+ /**
132
+ * @brief 按股下单,+正数买入,-负数卖出
133
+ * @param stk 交易标的
134
+ * @param num 交易数量
135
+ * @param remark 交易备注
136
+ * @return TradeRecord
137
+ */
138
+ virtual TradeRecord order(const Stock& stk, double num, const string& remark = "");
139
+
140
+ /**
141
+ * @brief 按价值下单,即买入指定资金数量的股票
142
+ * @param stk 交易标的
143
+ * @param value 价值
144
+ * @param remark 交易备注
145
+ * @return TradeRecord
146
+ */
147
+ virtual TradeRecord orderValue(const Stock& stk, price_t value, const string& remark = "");
148
+
131
149
  virtual KData getKData(const Stock& stk, const Datetime& start_date, const Datetime& end_date,
132
150
  const KQuery::KType& ktype,
133
151
  KQuery::RecoverType recover_type = KQuery::NO_RECOVER) const;
@@ -144,18 +162,13 @@ public:
144
162
  }
145
163
 
146
164
  virtual TradeRecord buy(const Stock& stk, price_t price, double num, double stoploss = 0.0,
147
- double goal_price = 0.0,
148
- SystemPart part_from = SystemPart::PART_SIGNAL) {
149
- HKU_ASSERT(m_tm);
150
- return m_tm->buy(Datetime::now(), stk, price, num, stoploss, goal_price, price, part_from);
151
- }
165
+ double goal_price = 0.0, SystemPart part_from = SystemPart::PART_SIGNAL,
166
+ const string& remark = "");
152
167
 
153
168
  virtual TradeRecord sell(const Stock& stk, price_t price, double num, price_t stoploss = 0.0,
154
169
  price_t goal_price = 0.0,
155
- SystemPart part_from = SystemPart::PART_SIGNAL) {
156
- HKU_ASSERT(m_tm);
157
- return m_tm->sell(Datetime::now(), stk, price, num, stoploss, goal_price, price, part_from);
158
- }
170
+ SystemPart part_from = SystemPart::PART_SIGNAL,
171
+ const string& remark = "");
159
172
 
160
173
  virtual bool isBacktesting() const {
161
174
  return false;
@@ -71,9 +71,10 @@ public:
71
71
  * @param stoploss 预期的止损价
72
72
  * @param goalPrice 预期的目标价位
73
73
  * @param from 系统部件来源
74
+ * @param remark 备注信息
74
75
  */
75
76
  void buy(Datetime datetime, const string& market, const string& code, price_t price, double num,
76
- price_t stoploss, price_t goalPrice, SystemPart from) noexcept;
77
+ price_t stoploss, price_t goalPrice, SystemPart from, const string& remark) noexcept;
77
78
 
78
79
  /**
79
80
  * 执行卖出操作
@@ -85,9 +86,11 @@ public:
85
86
  * @param stoploss 新的预期止损价
86
87
  * @param goalPrice 新的预期目标价位
87
88
  * @param from 系统部件来源
89
+ * @param remark 备注信息
88
90
  */
89
91
  void sell(Datetime datetime, const string& market, const string& code, price_t price,
90
- double num, price_t stoploss, price_t goalPrice, SystemPart from) noexcept;
92
+ double num, price_t stoploss, price_t goalPrice, SystemPart from,
93
+ const string& remark) noexcept;
91
94
 
92
95
  /**
93
96
  * 获取当前资产信息
@@ -123,9 +126,11 @@ public:
123
126
  * @param stoploss 预期的止损价
124
127
  * @param goalPrice 预期的目标价位
125
128
  * @param from 系统部件来源
129
+ * @param remark 备注信息
126
130
  */
127
131
  virtual void _buy(Datetime datetime, const string& market, const string& code, price_t price,
128
- double num, price_t stoploss, price_t goalPrice, SystemPart from) = 0;
132
+ double num, price_t stoploss, price_t goalPrice, SystemPart from,
133
+ const string& remark) = 0;
129
134
 
130
135
  /**
131
136
  * 子类实现接口,执行实际卖出操作
@@ -137,9 +142,11 @@ public:
137
142
  * @param stoploss 新预期的止损价
138
143
  * @param goalPrice 新预期的目标价位
139
144
  * @param from 系统部件来源
145
+ * @param remark 备注信息
140
146
  */
141
147
  virtual void _sell(Datetime datetime, const string& market, const string& code, price_t price,
142
- double num, price_t stoploss, price_t goalPrice, SystemPart from) = 0;
148
+ double num, price_t stoploss, price_t goalPrice, SystemPart from,
149
+ const string& remark) = 0;
143
150
 
144
151
  virtual string _getAssetInfo() {
145
152
  return string();
@@ -229,7 +229,8 @@ public:
229
229
  */
230
230
  virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
231
231
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
232
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) override;
232
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
233
+ const string& remark = "") override;
233
234
 
234
235
  /**
235
236
  * 卖出操作
@@ -246,7 +247,7 @@ public:
246
247
  virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
247
248
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
248
249
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
249
- SystemPart from = PART_INVALID) override;
250
+ SystemPart from = PART_INVALID, const string& remark = "") override;
250
251
 
251
252
  /**
252
253
  * 卖空
@@ -262,7 +263,8 @@ public:
262
263
  */
263
264
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
264
265
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
265
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) override;
266
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
267
+ const string& remark = "") override;
266
268
 
267
269
  /**
268
270
  * 卖空后回补
@@ -279,7 +281,8 @@ public:
279
281
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
280
282
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
281
283
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
282
- SystemPart from = PART_INVALID) override;
284
+ SystemPart from = PART_INVALID,
285
+ const string& remark = "") override;
283
286
 
284
287
  /**
285
288
  * 借入资金,从其他来源借取的资金,如融资
@@ -400,7 +403,7 @@ private:
400
403
  TradeRecordList m_trade_list; // 交易记录
401
404
 
402
405
  typedef map<uint64_t, PositionRecord> position_map_type;
403
- position_map_type m_position; // 当前持仓交易对象的持仓记录 ["sh000001"-> ]
406
+ position_map_type m_position; // 当前持仓交易对象的持仓记录 ["sh000001"-> ]
404
407
  PositionRecordList m_position_history; // 持仓历史记录
405
408
  position_map_type m_short_position; // 空头仓位记录
406
409
  PositionRecordList m_short_position_history; // 空头仓位历史记录
@@ -522,7 +522,8 @@ public:
522
522
  */
523
523
  virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
524
524
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
525
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) {
525
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
526
+ const string& remark = "") {
526
527
  HKU_WARN("The subclass does not implement this method");
527
528
  return TradeRecord();
528
529
  }
@@ -542,7 +543,7 @@ public:
542
543
  virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
543
544
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
544
545
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
545
- SystemPart from = PART_INVALID) {
546
+ SystemPart from = PART_INVALID, const string& remark = "") {
546
547
  HKU_WARN("The subclass does not implement this method");
547
548
  return TradeRecord();
548
549
  }
@@ -561,7 +562,8 @@ public:
561
562
  */
562
563
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
563
564
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
564
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) {
565
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
566
+ const string& remark = "") {
565
567
  HKU_WARN("The subclass does not implement this method");
566
568
  return TradeRecord();
567
569
  }
@@ -581,7 +583,7 @@ public:
581
583
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
582
584
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
583
585
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
584
- SystemPart from = PART_INVALID) {
586
+ SystemPart from = PART_INVALID, const string& remark = "") {
585
587
  HKU_WARN("The subclass does not implement this method");
586
588
  return TradeRecord();
587
589
  }
@@ -61,7 +61,12 @@ public:
61
61
  TradeRecord();
62
62
  TradeRecord(const Stock& stock, const Datetime& datetime, BUSINESS business, price_t planPrice,
63
63
  price_t realPrice, price_t goalPrice, double number, const CostRecord& cost,
64
- price_t stoploss, price_t cash, SystemPart from);
64
+ price_t stoploss, price_t cash, SystemPart from, const string& remark = "");
65
+ TradeRecord(const TradeRecord&) = default;
66
+ TradeRecord& operator=(const TradeRecord&) = default;
67
+
68
+ TradeRecord(TradeRecord&&);
69
+ TradeRecord& operator=(TradeRecord&&);
65
70
 
66
71
  /** 仅用于python的__str__ */
67
72
  string toString() const;
@@ -79,6 +84,7 @@ public:
79
84
  price_t stoploss; ///< 止损价
80
85
  price_t cash; ///< 现金余额
81
86
  SystemPart from; ///< 辅助记录交易系统部件,区别是哪个部件发出的指示,Null<int>()表示无效
87
+ string remark; ///< 备注
82
88
 
83
89
  #if HKU_SUPPORT_SERIALIZATION
84
90
  private:
@@ -98,6 +104,7 @@ private:
98
104
  ar& BOOST_SERIALIZATION_NVP(cost);
99
105
  ar& BOOST_SERIALIZATION_NVP(stoploss);
100
106
  ar& BOOST_SERIALIZATION_NVP(cash);
107
+ ar& BOOST_SERIALIZATION_NVP(remark);
101
108
  string part_name(getSystemPartName(from));
102
109
  ar& bs::make_nvp<string>("from", part_name);
103
110
  }
@@ -119,6 +126,7 @@ private:
119
126
  ar& BOOST_SERIALIZATION_NVP(cost);
120
127
  ar& BOOST_SERIALIZATION_NVP(stoploss);
121
128
  ar& BOOST_SERIALIZATION_NVP(cash);
129
+ ar& BOOST_SERIALIZATION_NVP(remark);
122
130
  string part_name;
123
131
  ar& bs::make_nvp<string>("from", part_name);
124
132
  from = getSystemPartEnum(part_name);
@@ -29,7 +29,8 @@ public:
29
29
  MultiFactorBase();
30
30
  explicit MultiFactorBase(const string& name);
31
31
  MultiFactorBase(const IndicatorList& inds, const StockList& stks, const KQuery& query,
32
- const Stock& ref_stk, const string& name, int ic_n, bool spearman);
32
+ const Stock& ref_stk, const string& name, int ic_n, bool spearman, int mode,
33
+ bool save_all_factors);
33
34
  MultiFactorBase(const MultiFactorBase&);
34
35
  virtual ~MultiFactorBase() = default;
35
36
 
@@ -44,9 +45,7 @@ public:
44
45
  }
45
46
 
46
47
  /** 获取参考日期列表 */
47
- const DatetimeList& getDatetimeList() const {
48
- return m_ref_dates;
49
- }
48
+ const DatetimeList& getDatetimeList();
50
49
 
51
50
  /** 获取查询范围 */
52
51
  const KQuery& getQuery() const {
@@ -153,7 +152,11 @@ private:
153
152
  void initParam();
154
153
 
155
154
  protected:
156
- void _buildIndex(); // 计算完成后创建截面索引
155
+ void _buildIndex(); // 计算完成后创建截面索引
156
+ void _buildIndexDesc(); // 创建降序排列的索引
157
+ void _buildIndexAsc(); // 创建升序排列的索引
158
+ void _buildIndexNone(); // build index when no index
159
+
157
160
  IndicatorList _getAllReturns(int ndays) const;
158
161
  void _checkData();
159
162
 
@@ -18,11 +18,14 @@ namespace hku {
18
18
  * @param ref_stk 参考证券
19
19
  * @param ic_n 默认 IC 对应的 N 日收益率
20
20
  * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
21
+ * @param mode 获取截面数据时排序模式: 0-降序, 1-升序, 2-不排序
22
+ * @param save_all_factors 是否保留因子数据
21
23
  * @return MultiFactorPtr
22
24
  */
23
25
  MultiFactorPtr HKU_API MF_EqualWeight(const IndicatorList& inds, const StockList& stks,
24
26
  const KQuery& query, const Stock& ref_stk, int ic_n = 5,
25
- bool spearman = true);
27
+ bool spearman = true, int mode = 0,
28
+ bool save_all_factors = false);
26
29
 
27
30
  MultiFactorPtr HKU_API MF_EqualWeight();
28
31
 
@@ -20,11 +20,14 @@ namespace hku {
20
20
  * @param ic_n 默认 IC 对应的 N 日收益率
21
21
  * @param ic_rolling_n IC 滚动窗口
22
22
  * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
23
+ * @param mode 获取截面数据时排序模式: 0-降序, 1-升序, 2-不排序
24
+ * @param save_all_factors 是否保留因子数据
23
25
  * @return MultiFactorPtr
24
26
  */
25
27
  MultiFactorPtr HKU_API MF_ICIRWeight(const IndicatorList& inds, const StockList& stks,
26
28
  const KQuery& query, const Stock& ref_stk, int ic_n = 5,
27
- int ic_rolling_n = 120, bool spearman = true);
29
+ int ic_rolling_n = 120, bool spearman = true, int mode = 0,
30
+ bool save_all_factors = false);
28
31
 
29
32
  MultiFactorPtr HKU_API MF_ICIRWeight();
30
33
  } // namespace hku
@@ -20,11 +20,14 @@ namespace hku {
20
20
  * @param ic_n 默认 IC 对应的 N 日收益率
21
21
  * @param ic_rolling_n IC 滚动窗口
22
22
  * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
23
+ * @param mode 获取截面数据时排序模式: 0-降序, 1-升序, 2-不排序
24
+ * @param save_all_factors 是否保留因子数据
23
25
  * @return MultiFactorPtr
24
26
  */
25
27
  MultiFactorPtr HKU_API MF_ICWeight(const IndicatorList& inds, const StockList& stks,
26
28
  const KQuery& query, const Stock& ref_stk, int ic_n = 5,
27
- int ic_rolling_n = 120, bool spearman = true);
29
+ int ic_rolling_n = 120, bool spearman = true, int mode = 0,
30
+ bool save_all_factors = false);
28
31
  MultiFactorPtr HKU_API MF_ICWeight();
29
32
 
30
33
  } // namespace hku
@@ -19,11 +19,14 @@ namespace hku {
19
19
  * @param ref_stk 参考证券
20
20
  * @param ic_n 默认 IC 对应的 N 日收益率
21
21
  * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
22
+ * @param mode 获取截面数据时排序模式: 0-降序, 1-升序, 2-不排序
23
+ * @param save_all_factors 是否保留因子数据
22
24
  * @return MultiFactorPtr
23
25
  */
24
26
  MultiFactorPtr HKU_API MF_Weight(const IndicatorList& inds, const PriceList& weights,
25
27
  const StockList& stks, const KQuery& query, const Stock& ref_stk,
26
- int ic_n = 5, bool spearman = true);
28
+ int ic_n = 5, bool spearman = true, int mode = 0,
29
+ bool save_all_factors = false);
27
30
 
28
31
  MultiFactorPtr HKU_API MF_Weight();
29
32
 
@@ -18,7 +18,8 @@ class EqualWeightMultiFactor : public MultiFactorBase {
18
18
  public:
19
19
  EqualWeightMultiFactor();
20
20
  EqualWeightMultiFactor(const vector<Indicator>& inds, const StockList& stks,
21
- const KQuery& query, const Stock& ref_stk, int ic_n, bool spearman);
21
+ const KQuery& query, const Stock& ref_stk, int ic_n, bool spearman,
22
+ int mode, bool save_all_factors);
22
23
  virtual ~EqualWeightMultiFactor() = default;
23
24
  };
24
25
 
@@ -18,7 +18,8 @@ class ICIRMultiFactor : public MultiFactorBase {
18
18
  public:
19
19
  ICIRMultiFactor();
20
20
  ICIRMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
21
- const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
21
+ const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman, int mode,
22
+ bool save_all_factors);
22
23
  virtual ~ICIRMultiFactor() = default;
23
24
 
24
25
  virtual void _checkParam(const string& name) const override;
@@ -18,7 +18,8 @@ class ICMultiFactor : public MultiFactorBase {
18
18
  public:
19
19
  ICMultiFactor();
20
20
  ICMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
21
- const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
21
+ const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman, int mode,
22
+ bool save_all_factors);
22
23
  virtual ~ICMultiFactor() = default;
23
24
 
24
25
  virtual void _checkParam(const string& name) const override;
@@ -21,7 +21,7 @@ public:
21
21
  WeightMultiFactor();
22
22
  WeightMultiFactor(const vector<Indicator>& inds, const PriceList& weights,
23
23
  const StockList& stks, const KQuery& query, const Stock& ref_stk, int ic_n,
24
- bool spearman);
24
+ bool spearman, int mode, bool save_all_factors);
25
25
  virtual ~WeightMultiFactor() = default;
26
26
 
27
27
  private:
@@ -28,11 +28,12 @@ public:
28
28
  Datetime datetime;
29
29
  price_t stoploss{0.0};
30
30
  price_t goal{0.0};
31
- double number{0.0}; // 计划的买入/卖出数量,使用发出请求时刻的收盘价,
32
- // 用于避免实际买入时需用重新计算数量时,人工执行速度较慢
33
- // 可通过系统参数进行设置,是否使用
31
+ double number{0.0}; // 计划的买入/卖出数量,使用发出请求时刻的收盘价,
32
+ // 用于避免实际买入时需用重新计算数量时,人工执行速度较慢
33
+ // 可通过系统参数进行设置,是否使用
34
34
  SystemPart from{PART_INVALID}; // 记录SystemBase::Part
35
- int count{0}; // 因操作失败,连续延迟的次数
35
+ string remark;
36
+ int count{0}; // 因操作失败,连续延迟的次数
36
37
  KRecord krecord;
37
38
 
38
39
  //============================================
@@ -54,6 +55,7 @@ private:
54
55
  ar& BOOST_SERIALIZATION_NVP(number);
55
56
  string from_name(getSystemPartName(from));
56
57
  ar& bs::make_nvp<string>("from", from_name);
58
+ ar& BOOST_SERIALIZATION_NVP(remark);
57
59
  ar& BOOST_SERIALIZATION_NVP(count);
58
60
  ar& BOOST_SERIALIZATION_NVP(krecord);
59
61
  }
@@ -74,6 +76,7 @@ private:
74
76
  string from_name;
75
77
  ar& bs::make_nvp<string>("from", from_name);
76
78
  from = getSystemPartEnum(from_name);
79
+ ar& BOOST_SERIALIZATION_NVP(remark);
77
80
  ar& BOOST_SERIALIZATION_NVP(count);
78
81
  ar& BOOST_SERIALIZATION_NVP(krecord);
79
82
  }
@@ -262,9 +262,10 @@ public:
262
262
  */
263
263
  virtual TradeRecord buy(const Datetime& datetime, const Stock& stock, price_t realPrice,
264
264
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
265
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) override {
265
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
266
+ const string& remark = "") override {
266
267
  return (datetime >= m_run_start) ? m_tm->buy(datetime, stock, realPrice, number, stoploss,
267
- goalPrice, planPrice, from)
268
+ goalPrice, planPrice, from, remark)
268
269
  : TradeRecord();
269
270
  }
270
271
 
@@ -283,9 +284,9 @@ public:
283
284
  virtual TradeRecord sell(const Datetime& datetime, const Stock& stock, price_t realPrice,
284
285
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
285
286
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
286
- SystemPart from = PART_INVALID) override {
287
+ SystemPart from = PART_INVALID, const string& remark = "") override {
287
288
  return (datetime >= m_run_start) ? m_tm->sell(datetime, stock, realPrice, number, stoploss,
288
- goalPrice, planPrice, from)
289
+ goalPrice, planPrice, from, remark)
289
290
  : TradeRecord();
290
291
  }
291
292
 
@@ -303,11 +304,12 @@ public:
303
304
  */
304
305
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
305
306
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
306
- price_t planPrice = 0.0,
307
- SystemPart from = PART_INVALID) override {
308
- return (datetime >= m_run_start) ? m_tm->sellShort(datetime, stock, realPrice, number,
309
- stoploss, goalPrice, planPrice, from)
310
- : TradeRecord();
307
+ price_t planPrice = 0.0, SystemPart from = PART_INVALID,
308
+ const string& remark = "") override {
309
+ return (datetime >= m_run_start)
310
+ ? m_tm->sellShort(datetime, stock, realPrice, number, stoploss, goalPrice,
311
+ planPrice, from, remark)
312
+ : TradeRecord();
311
313
  }
312
314
 
313
315
  /**
@@ -325,10 +327,12 @@ public:
325
327
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
326
328
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
327
329
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
328
- SystemPart from = PART_INVALID) override {
329
- return (datetime >= m_run_start) ? m_tm->buyShort(datetime, stock, realPrice, number,
330
- stoploss, goalPrice, planPrice, from)
331
- : TradeRecord();
330
+ SystemPart from = PART_INVALID,
331
+ const string& remark = "") override {
332
+ return (datetime >= m_run_start)
333
+ ? m_tm->buyShort(datetime, stock, realPrice, number, stoploss, goalPrice,
334
+ planPrice, from, remark)
335
+ : TradeRecord();
332
336
  }
333
337
 
334
338
  /**
@@ -1,5 +1,5 @@
1
1
  /*
2
- * StealMQStealThreadPool.h
2
+ * StealGlobalMQStealThreadPool.h
3
3
  *
4
4
  * Copyright (c) 2019 hikyuu.org
5
5
  *
@@ -30,25 +30,25 @@ namespace hku {
30
30
 
31
31
  /**
32
32
  * @brief 无集中队列多队列偷取任务池
33
- * @ingroup MQStealThreadPool
33
+ * @ingroup GlobalMQStealThreadPool
34
34
  */
35
35
  #ifdef _MSC_VER
36
- class MQStealThreadPool {
36
+ class GlobalMQStealThreadPool {
37
37
  #else
38
- class HKU_UTILS_API MQStealThreadPool {
38
+ class HKU_UTILS_API GlobalMQStealThreadPool {
39
39
  #endif
40
40
  public:
41
41
  /**
42
42
  * 默认构造函数,创建和当前系统CPU数一致的线程数
43
43
  */
44
- MQStealThreadPool() : MQStealThreadPool(std::thread::hardware_concurrency()) {}
44
+ GlobalMQStealThreadPool() : GlobalMQStealThreadPool(std::thread::hardware_concurrency()) {}
45
45
 
46
46
  /**
47
47
  * 构造函数,创建指定数量的线程
48
48
  * @param n 指定的线程数
49
49
  * @param until_empty 任务队列为空时,自动停止运行
50
50
  */
51
- explicit MQStealThreadPool(size_t n, bool until_empty = true)
51
+ explicit GlobalMQStealThreadPool(size_t n, bool until_empty = true)
52
52
  : m_done(false), m_worker_num(n), m_runnging_until_empty(until_empty) {
53
53
  try {
54
54
  m_interrupt_flags.resize(m_worker_num, nullptr);
@@ -58,7 +58,7 @@ public:
58
58
  }
59
59
  // 初始完毕所有线程资源后再启动线程
60
60
  for (int i = 0; i < m_worker_num; i++) {
61
- m_threads.emplace_back(&MQStealThreadPool::worker_thread, this, i);
61
+ m_threads.emplace_back(&GlobalMQStealThreadPool::worker_thread, this, i);
62
62
  }
63
63
  } catch (...) {
64
64
  m_done = true;
@@ -69,7 +69,7 @@ public:
69
69
  /**
70
70
  * 析构函数,等待并阻塞至线程池内所有任务完成
71
71
  */
72
- ~MQStealThreadPool() {
72
+ ~GlobalMQStealThreadPool() {
73
73
  if (!m_done) {
74
74
  join();
75
75
  }
@@ -106,7 +106,8 @@ public:
106
106
  template <typename FunctionType>
107
107
  auto submit(FunctionType f) {
108
108
  if (m_thread_need_stop.isSet() || m_done) {
109
- throw std::logic_error("You can't submit a task to the stopped MQStealThreadPool!");
109
+ throw std::logic_error(
110
+ "You can't submit a task to the stopped GlobalMQStealThreadPool!");
110
111
  }
111
112
 
112
113
  typedef typename std::invoke_result<FunctionType>::type result_type;
@@ -256,13 +257,12 @@ private:
256
257
  void worker_thread(int index) {
257
258
  m_index = index;
258
259
  m_interrupt_flags[index] = &m_thread_need_stop;
259
- m_local_work_queue = m_queues[m_index].get();
260
+ m_local_work_queue = m_queues[index].get();
260
261
  while (!m_thread_need_stop.isSet() && !m_done) {
261
262
  run_pending_task();
262
263
  }
263
- m_interrupt_flags[m_index] = nullptr;
264
+ m_interrupt_flags[index] = nullptr;
264
265
  m_local_work_queue = nullptr;
265
- // printf("%zu thread (%lld) finished!\n", m_index, std::this_thread::get_id());
266
266
  }
267
267
 
268
268
  void run_pending_task() {