hikyuu 2.1.5__cp312-none-win_amd64.whl → 2.2.0__cp312-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 (93) hide show
  1. hikyuu/analysis/analysis.py +20 -0
  2. hikyuu/cpp/boost_date_time-mt.dll +0 -0
  3. hikyuu/cpp/boost_serialization-mt.dll +0 -0
  4. hikyuu/cpp/boost_wserialization-mt.dll +0 -0
  5. hikyuu/cpp/core312.pyd +0 -0
  6. hikyuu/cpp/hikyuu.dll +0 -0
  7. hikyuu/data/common.py +3 -3
  8. hikyuu/data/mysql_upgrade/0023.sql +4 -0
  9. hikyuu/data/pytdx_weight_to_mysql.py +14 -15
  10. hikyuu/data/pytdx_weight_to_sqlite.py +14 -15
  11. hikyuu/data/sqlite_upgrade/0024.sql +22 -0
  12. hikyuu/gui/HikyuuTDX.py +3 -2
  13. hikyuu/gui/data/ImportHistoryFinanceTask.py +7 -0
  14. hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -2
  15. hikyuu/gui/data/MainWindow.py +1 -1
  16. hikyuu/include/hikyuu/StockWeight.h +16 -10
  17. hikyuu/include/hikyuu/analysis/analysis_sys.h +42 -12
  18. hikyuu/include/hikyuu/data_driver/base_info/table/StockWeightTable.h +6 -4
  19. hikyuu/include/hikyuu/global/agent/SpotAgent.h +5 -6
  20. hikyuu/include/hikyuu/indicator/crt/IC.h +7 -6
  21. hikyuu/include/hikyuu/indicator/crt/ICIR.h +7 -4
  22. hikyuu/include/hikyuu/indicator/imp/IIc.h +1 -1
  23. hikyuu/include/hikyuu/serialization/StockWeight_serialization.h +5 -2
  24. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +27 -25
  25. hikyuu/include/hikyuu/strategy/Strategy.h +1 -2
  26. hikyuu/include/hikyuu/trade_manage/Performance.h +3 -0
  27. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +16 -6
  28. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
  29. hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +0 -3
  30. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +2 -2
  31. hikyuu/include/hikyuu/trade_sys/condition/build_in.h +1 -0
  32. hikyuu/include/hikyuu/trade_sys/condition/crt/CN_Manual.h +20 -0
  33. hikyuu/include/hikyuu/trade_sys/condition/imp/ManualCondition.h +23 -0
  34. hikyuu/include/hikyuu/trade_sys/condition/imp/{AddCondition.h → logic/AddCondition.h} +1 -1
  35. hikyuu/include/hikyuu/trade_sys/condition/imp/{AndCondition.h → logic/AndCondition.h} +1 -1
  36. hikyuu/include/hikyuu/trade_sys/condition/imp/{DivCondition.h → logic/DivCondition.h} +1 -1
  37. hikyuu/include/hikyuu/trade_sys/condition/imp/{MultiCondition.h → logic/MultiCondition.h} +1 -1
  38. hikyuu/include/hikyuu/trade_sys/condition/imp/{OrCondition.h → logic/OrCondition.h} +1 -1
  39. hikyuu/include/hikyuu/trade_sys/condition/imp/logic/__init__.py +1 -0
  40. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -6
  41. hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
  42. hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Manual.h +20 -0
  43. hikyuu/include/hikyuu/trade_sys/environment/imp/ManualEnvironment.h +23 -0
  44. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +1 -1
  45. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -1
  46. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +3 -2
  47. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -2
  48. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
  49. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
  50. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
  51. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +2 -2
  52. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +3 -1
  53. hikyuu/include/hikyuu/trade_sys/selector/build_in.h +2 -1
  54. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -1
  55. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +26 -0
  56. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSelector.h → logic/OperatorSelector.h} +1 -1
  57. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorValueSelector.h → logic/OperatorValueSelector.h} +1 -1
  58. hikyuu/include/hikyuu/trade_sys/selector/imp/logic/__init__.py +1 -0
  59. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/MaxFundsOptimalSelector.h +27 -0
  60. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +86 -0
  61. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +42 -0
  62. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/__init__.py +1 -0
  63. hikyuu/include/hikyuu/trade_sys/signal/build_in.h +1 -0
  64. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Manual.h +20 -0
  65. hikyuu/include/hikyuu/trade_sys/signal/imp/ManualSignal.h +23 -0
  66. hikyuu/include/hikyuu/trade_sys/system/System.h +30 -13
  67. hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +19 -11
  68. hikyuu/include/hikyuu/trade_sys/system/build_in.h +1 -0
  69. hikyuu/include/hikyuu/trade_sys/system/crt/SYS_WalkForward.h +27 -0
  70. hikyuu/include/hikyuu/trade_sys/system/imp/DelegateSystem.h +51 -0
  71. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +70 -0
  72. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +465 -0
  73. hikyuu/include/hikyuu/utilities/base64.h +25 -31
  74. hikyuu/include/hikyuu/version.h +5 -5
  75. hikyuu/strategy/strategy_demo1.py +2 -1
  76. hikyuu/trade_sys/trade_sys.py +28 -9
  77. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/METADATA +1 -1
  78. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/RECORD +93 -74
  79. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/top_level.txt +3 -0
  80. /hikyuu/include/hikyuu/trade_sys/selector/crt/{SE_Operator.h → SE_Logic.h} +0 -0
  81. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddSelector.h → logic/OperatorAddSelector.h} +0 -0
  82. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddValueSelector.h → logic/OperatorAddValueSelector.h} +0 -0
  83. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivSelector.h → logic/OperatorDivSelector.h} +0 -0
  84. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivValueSelector.h → logic/OperatorDivValueSelector.h} +0 -0
  85. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertDivValueSelector.h → logic/OperatorInvertDivValueSelector.h} +0 -0
  86. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertSubValueSelector.h → logic/OperatorInvertSubValueSelector.h} +0 -0
  87. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulSelector.h → logic/OperatorMulSelector.h} +0 -0
  88. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulValueSelector.h → logic/OperatorMulValueSelector.h} +0 -0
  89. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubSelector.h → logic/OperatorSubSelector.h} +0 -0
  90. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubValueSelector.h → logic/OperatorSubValueSelector.h} +0 -0
  91. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/LICENSE +0 -0
  92. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/WHEEL +0 -0
  93. {hikyuu-2.1.5.dist-info → hikyuu-2.2.0.dist-info}/entry_points.txt +0 -0
@@ -94,48 +94,48 @@ public:
94
94
  * @param stock 指定证券
95
95
  * @return true 是 | false 否
96
96
  */
97
- virtual bool haveShort(const Stock& stock) const {
97
+ virtual bool haveShort(const Stock& stock) const override {
98
98
  HKU_WARN("The subclass does not implement this method");
99
99
  return false;
100
100
  }
101
101
 
102
102
  /** 当前持有的证券种类数量 */
103
- virtual size_t getStockNumber() const {
103
+ virtual size_t getStockNumber() const override {
104
104
  return m_position.size();
105
105
  }
106
106
 
107
107
  /** 当前空头持有的证券种类数量 */
108
- virtual size_t getShortStockNumber() const {
108
+ virtual size_t getShortStockNumber() const override {
109
109
  HKU_WARN("The subclass does not implement this method");
110
110
  return 0;
111
111
  }
112
112
 
113
113
  /** 获取指定时刻的某证券持有数量 */
114
- virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) {
114
+ virtual double getHoldNumber(const Datetime& datetime, const Stock& stock) override {
115
115
  HKU_WARN("The subclass does not implement this method");
116
116
  return 0.0;
117
117
  }
118
118
 
119
119
  /** 获取指定时刻的空头某证券持有数量 */
120
- virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) {
120
+ virtual double getShortHoldNumber(const Datetime& datetime, const Stock& stock) override {
121
121
  HKU_WARN("The subclass does not implement this method");
122
122
  return 0.0;
123
123
  }
124
124
 
125
125
  /** 获取指定时刻已借入的股票数量 */
126
- virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) {
126
+ virtual double getDebtNumber(const Datetime& datetime, const Stock& stock) override {
127
127
  HKU_WARN("The subclass does not implement this method");
128
128
  return 0.0;
129
129
  }
130
130
 
131
131
  /** 获取指定时刻已借入的现金额 */
132
- virtual price_t getDebtCash(const Datetime& datetime) {
132
+ virtual price_t getDebtCash(const Datetime& datetime) override {
133
133
  HKU_WARN("The subclass does not implement this method");
134
134
  return 0.0;
135
135
  }
136
136
 
137
137
  /** 获取全部交易记录 */
138
- virtual TradeRecordList getTradeList() const {
138
+ virtual TradeRecordList getTradeList() const override {
139
139
  HKU_WARN("The subclass does not implement this method");
140
140
  return TradeRecordList();
141
141
  }
@@ -146,7 +146,8 @@ public:
146
146
  * @param end 结束日期
147
147
  * @return 交易记录列表
148
148
  */
149
- virtual TradeRecordList getTradeList(const Datetime& start, const Datetime& end) const {
149
+ virtual TradeRecordList getTradeList(const Datetime& start,
150
+ const Datetime& end) const override {
150
151
  HKU_WARN("The subclass does not implement this method");
151
152
  return TradeRecordList();
152
153
  }
@@ -155,19 +156,19 @@ public:
155
156
  virtual PositionRecordList getPositionList() const override;
156
157
 
157
158
  /** 获取全部历史持仓记录,即已平仓记录 */
158
- virtual PositionRecordList getHistoryPositionList() const {
159
+ virtual PositionRecordList getHistoryPositionList() const override {
159
160
  HKU_WARN("The subclass does not implement this method");
160
161
  return PositionRecordList();
161
162
  }
162
163
 
163
164
  /** 获取当前全部空头仓位记录 */
164
- virtual PositionRecordList getShortPositionList() const {
165
+ virtual PositionRecordList getShortPositionList() const override {
165
166
  HKU_WARN("The subclass does not implement this method");
166
167
  return PositionRecordList();
167
168
  }
168
169
 
169
170
  /** 获取全部空头历史仓位记录 */
170
- virtual PositionRecordList getShortHistoryPositionList() const {
171
+ virtual PositionRecordList getShortHistoryPositionList() const override {
171
172
  HKU_WARN("The subclass does not implement this method");
172
173
  return PositionRecordList();
173
174
  }
@@ -183,13 +184,13 @@ public:
183
184
  * 获取指定证券的空头持仓记录
184
185
  * @param stock 指定的证券
185
186
  */
186
- virtual PositionRecord getShortPosition(const Stock& stock) const {
187
+ virtual PositionRecord getShortPosition(const Stock& stock) const override {
187
188
  HKU_WARN("The subclass does not implement this method");
188
189
  return PositionRecord();
189
190
  }
190
191
 
191
192
  /** 获取当前借入的股票列表 */
192
- virtual BorrowRecordList getBorrowStockList() const {
193
+ virtual BorrowRecordList getBorrowStockList() const override {
193
194
  HKU_WARN("The subclass does not implement this method");
194
195
  return BorrowRecordList();
195
196
  }
@@ -222,7 +223,7 @@ public:
222
223
  * @return true | false
223
224
  */
224
225
  virtual bool checkinStock(const Datetime& datetime, const Stock& stock, price_t price,
225
- double number) {
226
+ double number) override {
226
227
  HKU_WARN("The subclass does not implement this method");
227
228
  return false;
228
229
  }
@@ -237,7 +238,7 @@ public:
237
238
  * @note 应该不会被用到
238
239
  */
239
240
  virtual bool checkoutStock(const Datetime& datetime, const Stock& stock, price_t price,
240
- double number) {
241
+ double number) override {
241
242
  HKU_WARN("The subclass does not implement this method");
242
243
  return false;
243
244
  }
@@ -289,7 +290,8 @@ public:
289
290
  */
290
291
  virtual TradeRecord sellShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
291
292
  double number, price_t stoploss = 0.0, price_t goalPrice = 0.0,
292
- price_t planPrice = 0.0, SystemPart from = PART_INVALID) {
293
+ price_t planPrice = 0.0,
294
+ SystemPart from = PART_INVALID) override {
293
295
  HKU_WARN("The subclass does not implement this method");
294
296
  return TradeRecord();
295
297
  }
@@ -309,7 +311,7 @@ public:
309
311
  virtual TradeRecord buyShort(const Datetime& datetime, const Stock& stock, price_t realPrice,
310
312
  double number = MAX_DOUBLE, price_t stoploss = 0.0,
311
313
  price_t goalPrice = 0.0, price_t planPrice = 0.0,
312
- SystemPart from = PART_INVALID) {
314
+ SystemPart from = PART_INVALID) override {
313
315
  HKU_WARN("The subclass does not implement this method");
314
316
  return TradeRecord();
315
317
  }
@@ -320,7 +322,7 @@ public:
320
322
  * @param cash 借入的现金
321
323
  * @return true | false
322
324
  */
323
- virtual bool borrowCash(const Datetime& datetime, price_t cash) {
325
+ virtual bool borrowCash(const Datetime& datetime, price_t cash) override {
324
326
  HKU_WARN("The subclass does not implement this method");
325
327
  return false;
326
328
  }
@@ -331,7 +333,7 @@ public:
331
333
  * @param cash 归还现金
332
334
  * @return true | false
333
335
  */
334
- virtual bool returnCash(const Datetime& datetime, price_t cash) {
336
+ virtual bool returnCash(const Datetime& datetime, price_t cash) override {
335
337
  HKU_WARN("The subclass does not implement this method");
336
338
  return false;
337
339
  }
@@ -345,7 +347,7 @@ public:
345
347
  * @return true | false
346
348
  */
347
349
  virtual bool borrowStock(const Datetime& datetime, const Stock& stock, price_t price,
348
- double number) {
350
+ double number) override {
349
351
  HKU_WARN("The subclass does not implement this method");
350
352
  return false;
351
353
  }
@@ -359,7 +361,7 @@ public:
359
361
  * @return true | false
360
362
  */
361
363
  virtual bool returnStock(const Datetime& datetime, const Stock& stock, price_t price,
362
- double number) {
364
+ double number) override {
363
365
  HKU_WARN("The subclass does not implement this method");
364
366
  return false;
365
367
  }
@@ -387,7 +389,7 @@ public:
387
389
  * @param tr 待加入的交易记录
388
390
  * @return bool true 成功 | false 失败
389
391
  */
390
- virtual bool addTradeRecord(const TradeRecord& tr) {
392
+ virtual bool addTradeRecord(const TradeRecord& tr) override {
391
393
  HKU_WARN("The subclass does not implement this method");
392
394
  return false;
393
395
  }
@@ -398,7 +400,7 @@ public:
398
400
  * @return true 成功
399
401
  * @return false 失败
400
402
  */
401
- virtual bool addPosition(const PositionRecord& pr) {
403
+ virtual bool addPosition(const PositionRecord& pr) override {
402
404
  HKU_WARN("The subclass does not implement this method");
403
405
  return false;
404
406
  }
@@ -410,7 +412,7 @@ public:
410
412
  * 以csv格式输出交易记录、未平仓记录、已平仓记录、资产净值曲线
411
413
  * @param path 输出文件所在目录
412
414
  */
413
- virtual void tocsv(const string& path) {
415
+ virtual void tocsv(const string& path) override {
414
416
  HKU_WARN("The subclass does not implement this method");
415
417
  }
416
418
 
@@ -106,8 +106,7 @@ private:
106
106
  string m_run_daily_market;
107
107
  bool m_ignoreMarket{false};
108
108
 
109
- std::function<void()> m_run_daily_at_func;
110
- TimeDelta m_run_daily_at_delta;
109
+ std::map<TimeDelta, std::function<void()>> m_run_daily_at_funcs;
111
110
 
112
111
  private:
113
112
  void _initParam();
@@ -29,6 +29,9 @@ public:
29
29
  Performance& operator=(const Performance& other);
30
30
  Performance& operator=(Performance&& other);
31
31
 
32
+ /** 是否为合法的统计项 */
33
+ static bool exist(const string& key);
34
+
32
35
  /** 复位,清除已计算的结果 */
33
36
  void reset();
34
37
 
@@ -168,6 +168,7 @@ public:
168
168
  p->m_name = m_name;
169
169
  p->m_broker_last_datetime = m_broker_last_datetime;
170
170
  p->m_costfunc = m_costfunc;
171
+ p->m_broker_list = m_broker_list;
171
172
  return p;
172
173
  }
173
174
 
@@ -197,7 +198,7 @@ public:
197
198
  * @param ktype K线类型,必须与日期列表匹配,默认KQuery::DAY
198
199
  * @return 日资产记录列表
199
200
  */
200
- FundsList getFundsList(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) {
201
+ FundsList getFundsList(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) {
201
202
  size_t total = dates.size();
202
203
  FundsList result(total);
203
204
  HKU_IF_RETURN(total == 0, result);
@@ -213,7 +214,7 @@ public:
213
214
  * @param ktype K线类型,必须与日期列表匹配,默认KQuery::DAY
214
215
  * @return 资产净值列表
215
216
  */
216
- PriceList getFundsCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) {
217
+ PriceList getFundsCurve(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) {
217
218
  FundsList funds_list = getFundsList(dates, ktype);
218
219
  PriceList ret(funds_list.size());
219
220
  int precision = getParam<int>("precision");
@@ -229,7 +230,7 @@ public:
229
230
  * @param ktype K线类型,必须与日期列表匹配,默认为KQuery::DAY
230
231
  * @return 收益曲线
231
232
  */
232
- PriceList getProfitCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) {
233
+ PriceList getProfitCurve(const DatetimeList& dates, const KQuery::KType& ktype = KQuery::DAY) {
233
234
  FundsList funds_list = getFundsList(dates, ktype);
234
235
  PriceList ret(funds_list.size());
235
236
  int precision = getParam<int>("precision");
@@ -246,7 +247,7 @@ public:
246
247
  * @return 收益率曲线
247
248
  */
248
249
  PriceList getProfitCumChangeCurve(const DatetimeList& dates,
249
- KQuery::KType ktype = KQuery::DAY) {
250
+ const KQuery::KType& ktype = KQuery::DAY) {
250
251
  FundsList funds_list = getFundsList(dates, ktype);
251
252
  PriceList ret(funds_list.size());
252
253
  for (size_t i = 0, total = funds_list.size(); i < total; i++) {
@@ -261,7 +262,8 @@ public:
261
262
  * @param ktype K线类型,必须与日期列表匹配,默认为KQuery::DAY
262
263
  * @return 价格曲线
263
264
  */
264
- PriceList getBaseAssetsCurve(const DatetimeList& dates, KQuery::KType ktype = KQuery::DAY) {
265
+ PriceList getBaseAssetsCurve(const DatetimeList& dates,
266
+ const KQuery::KType& ktype = KQuery::DAY) {
265
267
  FundsList funds_list = getFundsList(dates, ktype);
266
268
  PriceList ret(funds_list.size());
267
269
  for (size_t i = 0, total = funds_list.size(); i < total; i++) {
@@ -769,4 +771,12 @@ inline std::ostream& operator<<(std::ostream& os, const TradeManagerPtr& ptm) {
769
771
  return os;
770
772
  }
771
773
 
772
- } // namespace hku
774
+ } // namespace hku
775
+
776
+ #if FMT_VERSION >= 90000
777
+ template <>
778
+ struct fmt::formatter<hku::TradeManagerBase> : ostream_formatter {};
779
+
780
+ template <>
781
+ struct fmt::formatter<hku::TradeManagerPtr> : ostream_formatter {};
782
+ #endif
@@ -73,7 +73,7 @@ public:
73
73
  BUSINESS business; ///< 业务类型
74
74
  price_t planPrice; ///< 计划交易价格
75
75
  price_t realPrice; ///< 实际交易价格
76
- price_t goalPrice; ///< 目标价位,如果为0表示未限定目标
76
+ price_t goalPrice; ///< 目标价位,如果为0或Null表示未限定目标
77
77
  double number; ///< 成交数量
78
78
  CostRecord cost; ///< 交易成本
79
79
  price_t stoploss; ///< 止损价
@@ -112,9 +112,6 @@ private:
112
112
  void _adjust_without_running(const Datetime& date, const SystemWeightList& se_list,
113
113
  const std::unordered_set<SYSPtr>& running_list);
114
114
 
115
- /* 检查分配的权重是否在 0 和 1 之间,如果存在错误,抛出异常,仅在 trace 时生效*/
116
- void _check_weight(const SystemWeightList&);
117
-
118
115
  private:
119
116
  string m_name; // 组件名称
120
117
  KQuery m_query; // 查询条件
@@ -180,10 +180,10 @@ typedef shared_ptr<ConditionBase> CNPtr;
180
180
 
181
181
  #define CONDITION_IMP(classname) \
182
182
  public: \
183
- virtual ConditionPtr _clone() { \
183
+ virtual ConditionPtr _clone() override { \
184
184
  return std::make_shared<classname>(); \
185
185
  } \
186
- virtual void _calculate();
186
+ virtual void _calculate() override;
187
187
 
188
188
  HKU_API std::ostream& operator<<(std::ostream&, const ConditionPtr&);
189
189
  HKU_API std::ostream& operator<<(std::ostream&, const ConditionBase&);
@@ -12,5 +12,6 @@
12
12
  #include "crt/CN_Bool.h"
13
13
  #include "crt/CN_OPLine.h"
14
14
  #include "crt/CN_Logic.h"
15
+ #include "crt/CN_Manual.h"
15
16
 
16
17
  #endif /* CONDITION_BUILD_IN_H */
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) 2019~2023, hikyuu.org
3
+ *
4
+ * History:
5
+ * 1. 20240916 added by fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../ConditionBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 仅能手工添加有效性的CN,用于测试或其他特殊用途
16
+ * @return CNPtr
17
+ */
18
+ CNPtr HKU_API CN_Manual();
19
+
20
+ } // namespace hku
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2019~2023, hikyuu.org
3
+ *
4
+ * History:
5
+ * 1. 20240916 added by fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../ConditionBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class ManualCondition : public ConditionBase {
15
+ CONDITION_IMP(ManualCondition)
16
+ CONDITION_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ ManualCondition();
20
+ virtual ~ManualCondition() = default;
21
+ };
22
+
23
+ } // namespace hku
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../ConditionBase.h"
10
+ #include "hikyuu/trade_sys/condition/ConditionBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../ConditionBase.h"
10
+ #include "hikyuu/trade_sys/condition/ConditionBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../ConditionBase.h"
10
+ #include "hikyuu/trade_sys/condition/ConditionBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../ConditionBase.h"
10
+ #include "hikyuu/trade_sys/condition/ConditionBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../ConditionBase.h"
10
+ #include "hikyuu/trade_sys/condition/ConditionBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -151,12 +151,12 @@ private: \
151
151
  typedef shared_ptr<EnvironmentBase> EnvironmentPtr;
152
152
  typedef shared_ptr<EnvironmentBase> EVPtr;
153
153
 
154
- #define ENVIRONMENT_IMP(classname) \
155
- public: \
156
- virtual EnvironmentPtr _clone() { \
157
- return std::make_shared<classname>(); \
158
- } \
159
- virtual void _calculate();
154
+ #define ENVIRONMENT_IMP(classname) \
155
+ public: \
156
+ virtual EnvironmentPtr _clone() override { \
157
+ return std::make_shared<classname>(); \
158
+ } \
159
+ virtual void _calculate() override;
160
160
 
161
161
  /**
162
162
  * 输出Environment信息,如:Environment(name, params[...])
@@ -11,5 +11,6 @@
11
11
 
12
12
  #include "crt/EV_TwoLine.h"
13
13
  #include "crt/EV_Bool.h"
14
+ #include "crt/EV_Manual.h"
14
15
 
15
16
  #endif /* ENVIRONMENT_BUILD_IN_H */
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright (c) 2019~2023, hikyuu.org
3
+ *
4
+ * History:
5
+ * 1. 20240916 added by fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../EnvironmentBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 仅能手工添加系统环境有效性的EV,用于测试或其他用途
16
+ * @return EVPtr
17
+ */
18
+ EVPtr HKU_API EV_Manual();
19
+
20
+ } // namespace hku
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2019~2023, hikyuu.org
3
+ *
4
+ * History:
5
+ * 1. 20240916 added by fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../EnvironmentBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class ManualEnvironment : public EnvironmentBase {
15
+ ENVIRONMENT_IMP(ManualEnvironment)
16
+ ENVIRONMENT_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ ManualEnvironment();
20
+ virtual ~ManualEnvironment() = default;
21
+ };
22
+
23
+ } // namespace hku
@@ -29,7 +29,7 @@ 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);
32
+ const Stock& ref_stk, const string& name, int ic_n, bool spearman);
33
33
  MultiFactorBase(const MultiFactorBase&);
34
34
  virtual ~MultiFactorBase() = default;
35
35
 
@@ -17,10 +17,12 @@ namespace hku {
17
17
  * @param query 日期范围
18
18
  * @param ref_stk 参考证券
19
19
  * @param ic_n 默认 IC 对应的 N 日收益率
20
+ * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
20
21
  * @return MultiFactorPtr
21
22
  */
22
23
  MultiFactorPtr HKU_API MF_EqualWeight(const IndicatorList& inds, const StockList& stks,
23
- const KQuery& query, const Stock& ref_stk, int ic_n = 5);
24
+ const KQuery& query, const Stock& ref_stk, int ic_n = 5,
25
+ bool spearman = true);
24
26
 
25
27
  MultiFactorPtr HKU_API MF_EqualWeight();
26
28
 
@@ -19,11 +19,12 @@ namespace hku {
19
19
  * @param ref_stk 参考证券
20
20
  * @param ic_n 默认 IC 对应的 N 日收益率
21
21
  * @param ic_rolling_n IC 滚动窗口
22
+ * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
22
23
  * @return MultiFactorPtr
23
24
  */
24
25
  MultiFactorPtr HKU_API MF_ICIRWeight(const IndicatorList& inds, const StockList& stks,
25
26
  const KQuery& query, const Stock& ref_stk, int ic_n = 5,
26
- int ic_rolling_n = 120);
27
+ int ic_rolling_n = 120, bool spearman = true);
27
28
 
28
29
  MultiFactorPtr HKU_API MF_ICIRWeight();
29
- }
30
+ } // namespace hku
@@ -19,10 +19,12 @@ namespace hku {
19
19
  * @param ref_stk 参考证券
20
20
  * @param ic_n 默认 IC 对应的 N 日收益率
21
21
  * @param ic_rolling_n IC 滚动窗口
22
+ * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
22
23
  * @return MultiFactorPtr
23
24
  */
24
25
  MultiFactorPtr HKU_API MF_ICWeight(const IndicatorList& inds, const StockList& stks,
25
26
  const KQuery& query, const Stock& ref_stk, int ic_n = 5,
26
- int ic_rolling_n = 120);
27
+ int ic_rolling_n = 120, bool spearman = true);
27
28
  MultiFactorPtr HKU_API MF_ICWeight();
28
- }
29
+
30
+ } // namespace hku
@@ -18,7 +18,7 @@ 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);
21
+ const KQuery& query, const Stock& ref_stk, int ic_n, bool spearman);
22
22
  virtual ~EqualWeightMultiFactor() = default;
23
23
  };
24
24
 
@@ -18,7 +18,7 @@ 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);
21
+ const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
22
22
  virtual ~ICIRMultiFactor() = default;
23
23
 
24
24
  virtual void _checkParam(const string& name) const override;
@@ -18,7 +18,7 @@ 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);
21
+ const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
22
22
  virtual ~ICMultiFactor() = default;
23
23
 
24
24
  virtual void _checkParam(const string& name) const override;
@@ -34,10 +34,10 @@ public:
34
34
  /**
35
35
  * @brief 构造函数
36
36
  * @param tm 账户
37
- * @param st 选择器
37
+ * @param se 选择器
38
38
  * @param af 资产分配算法
39
39
  */
40
- Portfolio(const TradeManagerPtr& tm, const SelectorPtr& st, const AFPtr& af);
40
+ Portfolio(const TradeManagerPtr& tm, const SelectorPtr& se, const AFPtr& af);
41
41
 
42
42
  /** 析构函数 */
43
43
  virtual ~Portfolio();
@@ -122,13 +122,15 @@ public:
122
122
  virtual void _removeAll() {}
123
123
 
124
124
  /* 仅供PF调用,由PF通知其实际运行的系统列表,并启动计算 */
125
- void calculate(const SystemList& pf_realSysList, const KQuery& query);
125
+ virtual void calculate(const SystemList& pf_realSysList, const KQuery& query);
126
126
 
127
127
  /* 仅供PF调用,建立实际系统到原型系统映射 */
128
128
  virtual void bindRealToProto(const SYSPtr& real, const SYSPtr& proto) {}
129
129
 
130
130
  void calculate_proto(const KQuery& query);
131
131
 
132
+ virtual string str() const;
133
+
132
134
  private:
133
135
  void initParam();
134
136
 
@@ -11,7 +11,8 @@
11
11
 
12
12
  #include "crt/SE_Fixed.h"
13
13
  #include "crt/SE_MultiFactor.h"
14
- #include "crt/SE_Operator.h"
14
+ #include "crt/SE_Logic.h"
15
+ #include "crt/SE_Optimal.h"
15
16
  #include "crt/SE_Signal.h"
16
17
 
17
18
  #endif /* TRADE_SYS_SELECTOR_BUILD_IN_H_ */
@@ -28,12 +28,13 @@ SelectorPtr HKU_API SE_MultiFactor(const MFPtr& mf, int topn = 10);
28
28
  * @param ic_n ic 对应的 ic_n 日收益率
29
29
  * @param ic_rolling_n 计算滚动 IC (即 IC 的 n 日移动平均)周期
30
30
  * @param ref_stk 参照对比证券,未指定时,默认使用 sh000300 沪深300指数
31
+ * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
31
32
  * @param mode "MF_ICIRWeight" | "MF_ICWeight" | "MF_EqualWeight" 因子合成算法名称
32
33
  * @return SelectorPtr
33
34
  * @ingroup Selector
34
35
  */
35
36
  SelectorPtr HKU_API SE_MultiFactor(const IndicatorList& src_inds, int topn = 10, int ic_n = 5,
36
37
  int ic_rolling_n = 120, const Stock& ref_stk = Stock(),
37
- const string& mode = "MF_ICIRWeight");
38
+ bool spearman = true, const string& mode = "MF_ICIRWeight");
38
39
 
39
40
  } // namespace hku