hikyuu 2.1.5__cp38-none-win_amd64.whl → 2.2.1__cp38-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 (94) 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/core38.pyd +0 -0
  6. hikyuu/cpp/hikyuu.dll +0 -0
  7. hikyuu/cpp/sqlite3.dll +0 -0
  8. hikyuu/data/common.py +3 -3
  9. hikyuu/data/mysql_upgrade/0023.sql +4 -0
  10. hikyuu/data/pytdx_weight_to_mysql.py +14 -15
  11. hikyuu/data/pytdx_weight_to_sqlite.py +14 -15
  12. hikyuu/data/sqlite_upgrade/0024.sql +22 -0
  13. hikyuu/gui/HikyuuTDX.py +3 -2
  14. hikyuu/gui/data/ImportHistoryFinanceTask.py +7 -0
  15. hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -2
  16. hikyuu/gui/data/MainWindow.py +520 -424
  17. hikyuu/include/hikyuu/StockWeight.h +16 -10
  18. hikyuu/include/hikyuu/analysis/analysis_sys.h +42 -12
  19. hikyuu/include/hikyuu/data_driver/base_info/table/StockWeightTable.h +6 -4
  20. hikyuu/include/hikyuu/global/agent/SpotAgent.h +5 -6
  21. hikyuu/include/hikyuu/indicator/crt/IC.h +7 -6
  22. hikyuu/include/hikyuu/indicator/crt/ICIR.h +7 -4
  23. hikyuu/include/hikyuu/indicator/imp/IIc.h +1 -1
  24. hikyuu/include/hikyuu/serialization/StockWeight_serialization.h +5 -2
  25. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +27 -25
  26. hikyuu/include/hikyuu/strategy/Strategy.h +1 -2
  27. hikyuu/include/hikyuu/trade_manage/Performance.h +3 -0
  28. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +16 -6
  29. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
  30. hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +0 -3
  31. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +2 -2
  32. hikyuu/include/hikyuu/trade_sys/condition/build_in.h +1 -0
  33. hikyuu/include/hikyuu/trade_sys/condition/crt/CN_Manual.h +20 -0
  34. hikyuu/include/hikyuu/trade_sys/condition/imp/ManualCondition.h +23 -0
  35. hikyuu/include/hikyuu/trade_sys/condition/imp/{AddCondition.h → logic/AddCondition.h} +1 -1
  36. hikyuu/include/hikyuu/trade_sys/condition/imp/{AndCondition.h → logic/AndCondition.h} +1 -1
  37. hikyuu/include/hikyuu/trade_sys/condition/imp/{DivCondition.h → logic/DivCondition.h} +1 -1
  38. hikyuu/include/hikyuu/trade_sys/condition/imp/{MultiCondition.h → logic/MultiCondition.h} +1 -1
  39. hikyuu/include/hikyuu/trade_sys/condition/imp/{OrCondition.h → logic/OrCondition.h} +1 -1
  40. hikyuu/include/hikyuu/trade_sys/condition/imp/logic/__init__.py +1 -0
  41. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -6
  42. hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
  43. hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Manual.h +20 -0
  44. hikyuu/include/hikyuu/trade_sys/environment/imp/ManualEnvironment.h +23 -0
  45. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +1 -1
  46. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -1
  47. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +3 -2
  48. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -2
  49. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
  50. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
  51. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
  52. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +2 -2
  53. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +3 -1
  54. hikyuu/include/hikyuu/trade_sys/selector/build_in.h +2 -1
  55. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -1
  56. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +26 -0
  57. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSelector.h → logic/OperatorSelector.h} +1 -1
  58. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorValueSelector.h → logic/OperatorValueSelector.h} +1 -1
  59. hikyuu/include/hikyuu/trade_sys/selector/imp/logic/__init__.py +1 -0
  60. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/MaxFundsOptimalSelector.h +27 -0
  61. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +86 -0
  62. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +42 -0
  63. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/__init__.py +1 -0
  64. hikyuu/include/hikyuu/trade_sys/signal/build_in.h +1 -0
  65. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Manual.h +20 -0
  66. hikyuu/include/hikyuu/trade_sys/signal/imp/ManualSignal.h +23 -0
  67. hikyuu/include/hikyuu/trade_sys/system/System.h +30 -13
  68. hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +19 -11
  69. hikyuu/include/hikyuu/trade_sys/system/build_in.h +1 -0
  70. hikyuu/include/hikyuu/trade_sys/system/crt/SYS_WalkForward.h +27 -0
  71. hikyuu/include/hikyuu/trade_sys/system/imp/DelegateSystem.h +51 -0
  72. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +70 -0
  73. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +465 -0
  74. hikyuu/include/hikyuu/utilities/base64.h +25 -31
  75. hikyuu/include/hikyuu/version.h +5 -5
  76. hikyuu/strategy/strategy_demo1.py +2 -1
  77. hikyuu/trade_sys/trade_sys.py +28 -9
  78. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/METADATA +1 -1
  79. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/RECORD +94 -75
  80. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/top_level.txt +3 -0
  81. /hikyuu/include/hikyuu/trade_sys/selector/crt/{SE_Operator.h → SE_Logic.h} +0 -0
  82. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddSelector.h → logic/OperatorAddSelector.h} +0 -0
  83. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddValueSelector.h → logic/OperatorAddValueSelector.h} +0 -0
  84. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivSelector.h → logic/OperatorDivSelector.h} +0 -0
  85. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivValueSelector.h → logic/OperatorDivValueSelector.h} +0 -0
  86. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertDivValueSelector.h → logic/OperatorInvertDivValueSelector.h} +0 -0
  87. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertSubValueSelector.h → logic/OperatorInvertSubValueSelector.h} +0 -0
  88. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulSelector.h → logic/OperatorMulSelector.h} +0 -0
  89. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulValueSelector.h → logic/OperatorMulValueSelector.h} +0 -0
  90. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubSelector.h → logic/OperatorSubSelector.h} +0 -0
  91. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubValueSelector.h → logic/OperatorSubValueSelector.h} +0 -0
  92. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/LICENSE +0 -0
  93. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/WHEEL +0 -0
  94. {hikyuu-2.1.5.dist-info → hikyuu-2.2.1.dist-info}/entry_points.txt +0 -0
@@ -27,6 +27,7 @@ namespace hku {
27
27
 
28
28
  class HKU_API Portfolio;
29
29
  class HKU_API AllocateFundsBase;
30
+ class HKU_API WalkForwardSystem;
30
31
 
31
32
  /**
32
33
  * 交易系统基类
@@ -36,6 +37,7 @@ class HKU_API System {
36
37
  PARAMETER_SUPPORT_WITH_CHECK
37
38
  friend class HKU_API Portfolio;
38
39
  friend class HKU_API AllocateFundsBase;
40
+ friend class HKU_API WalkForwardSystem;
39
41
 
40
42
  public:
41
43
  /** 默认构造函数 */
@@ -63,6 +65,8 @@ public:
63
65
  const StoplossPtr& tp, const ProfitGoalPtr& pg, const SlippagePtr& sp,
64
66
  const string& name);
65
67
 
68
+ System(const System&) = default;
69
+
66
70
  /** 析构函数 */
67
71
  virtual ~System();
68
72
 
@@ -151,6 +155,9 @@ public:
151
155
  const TradeRequest& getSellShortTradeRequest() const;
152
156
  const TradeRequest& getBuyShortTradeRequest() const;
153
157
 
158
+ /** 将所有组件全部置为非共享 */
159
+ void setNotSharedAll();
160
+
154
161
  /**
155
162
  * 复位,但不包括已有的交易对象,以及共享的部件
156
163
  * @note 实际复位操作依赖于系统中各个部件的共享参数
@@ -196,48 +203,58 @@ public:
196
203
  * @param reset 执行前是否依据系统部件共享属性复位
197
204
  * @param resetAll 强制复位所有部件
198
205
  */
199
- void run(const KData& kdata, bool reset = true, bool resetAll = false);
206
+ virtual void run(const KData& kdata, bool reset = true, bool resetAll = false);
200
207
 
201
208
  /**
202
209
  * @brief 在指定的日期执行一步,仅由 PF 调用
203
210
  * @param datetime 指定的日期
204
211
  * @return TradeRecord
205
212
  */
206
- TradeRecord runMoment(const Datetime& datetime);
213
+ virtual TradeRecord runMoment(const Datetime& datetime);
207
214
 
208
215
  // 运行前准备工作, 失败将抛出异常
209
- void readyForRun();
210
-
211
- TradeRecord sell(const KRecord& today, const KRecord& src_today, Part from) {
212
- return _sell(today, src_today, from);
213
- }
216
+ virtual void readyForRun();
214
217
 
215
218
  // 由各个相关组件调用,用于组件参数变化时通知 sys,以便重算
216
219
  void partChangedNotify() {
217
220
  m_calculated = false;
218
221
  }
219
222
 
220
- private:
223
+ virtual void _reset() {}
224
+ virtual void _forceResetAll() {}
225
+
226
+ /** 子类克隆接口 */
227
+ virtual SystemPtr _clone() {
228
+ return make_shared<System>();
229
+ }
230
+
231
+ virtual string str() const;
232
+
233
+ public:
234
+ //-------------------------
235
+ // 仅供 PF/AF 内部调用
236
+ //-------------------------
237
+
221
238
  // 强制以开盘价卖出,仅供 PF/AF 内部调用
222
- TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) {
239
+ virtual TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) {
223
240
  HKU_ASSERT(from == PART_ALLOCATEFUNDS || from == PART_PORTFOLIO);
224
241
  return _sellForce(date, num, from, true);
225
242
  }
226
243
 
227
244
  // 强制以收盘价卖出,仅供 PF/AF 内部调用
228
- TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) {
245
+ virtual TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) {
229
246
  HKU_ASSERT(from == PART_ALLOCATEFUNDS || from == PART_PORTFOLIO);
230
247
  return _sellForce(date, num, from, false);
231
248
  }
232
249
 
233
250
  // 清除已有的交易请求,供Portfolio使用
234
- void clearDelayBuyRequest();
251
+ virtual void clearDelayBuyRequest();
235
252
 
236
253
  // 当前是否存在延迟的操作请求,供Portfolio
237
- bool haveDelaySellRequest() const;
254
+ virtual bool haveDelaySellRequest() const;
238
255
 
239
256
  // 处理延迟买入请求,仅供 PF 调用
240
- TradeRecord pfProcessDelaySellRequest(const Datetime& date);
257
+ virtual TradeRecord pfProcessDelaySellRequest(const Datetime& date);
241
258
 
242
259
  private:
243
260
  bool _environmentIsValid(const Datetime& datetime);
@@ -20,19 +20,19 @@ namespace hku {
20
20
  */
21
21
  class HKU_API TradeRequest {
22
22
  public:
23
- TradeRequest();
24
- void clear();
23
+ TradeRequest() = default;
24
+ void clear() noexcept;
25
25
 
26
- bool valid;
27
- BUSINESS business;
26
+ bool valid{false};
27
+ BUSINESS business{BUSINESS_INVALID};
28
28
  Datetime datetime;
29
- price_t stoploss;
30
- price_t goal;
31
- double number; //计划的买入/卖出数量,使用发出请求时刻的收盘价,
32
- //用于避免实际买入时需用重新计算数量时,人工执行速度较慢
33
- //可通过系统参数进行设置,是否使用
34
- SystemPart from; //记录SystemBase::Part
35
- int count; //因操作失败,连续延迟的次数
29
+ price_t stoploss{0.0};
30
+ price_t goal{0.0};
31
+ double number{0.0}; // 计划的买入/卖出数量,使用发出请求时刻的收盘价,
32
+ // 用于避免实际买入时需用重新计算数量时,人工执行速度较慢
33
+ // 可通过系统参数进行设置,是否使用
34
+ SystemPart from{PART_INVALID}; // 记录SystemBase::Part
35
+ int count{0}; // 因操作失败,连续延迟的次数
36
36
  KRecord krecord;
37
37
 
38
38
  //============================================
@@ -82,5 +82,13 @@ private:
82
82
  #endif /* HKU_SUPPORT_SERIALIZATION */
83
83
  };
84
84
 
85
+ HKU_API std::ostream& operator<<(std::ostream& os, const TradeRequest& tr);
86
+
85
87
  } /* namespace hku */
88
+
89
+ #if FMT_VERSION >= 90000
90
+ template <>
91
+ struct fmt::formatter<hku::TradeRequest> : ostream_formatter {};
92
+ #endif
93
+
86
94
  #endif /* TRADEREQUEST_H_ */
@@ -10,5 +10,6 @@
10
10
  #define SYSTEM_BUILD_IN_H_
11
11
 
12
12
  #include "crt/SYS_Simple.h"
13
+ #include "crt/SYS_WalkForward.h"
13
14
 
14
15
  #endif /* BUILD_IN_H_ */
@@ -0,0 +1,27 @@
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 "hikyuu/trade_sys/system/System.h"
11
+ #include "hikyuu/trade_sys/selector/crt/SE_Optimal.h"
12
+
13
+ namespace hku {
14
+
15
+ // SystemPtr HKU_API SYS_WalkForward(const SystemList& candidate_sys_list,
16
+ // const TradeManagerPtr& tm = TradeManagerPtr(),
17
+ // size_t train_len = 100, size_t test_len = 20,
18
+ // const string& key = "帐户平均年收益率%",
19
+ // const TradeManagerPtr& train_tm = TradeManagerPtr());
20
+
21
+ SystemPtr HKU_API SYS_WalkForward(const SystemList& candidate_sys_list,
22
+ const TradeManagerPtr& tm = TradeManagerPtr(),
23
+ size_t train_len = 100, size_t test_len = 20,
24
+ const SelectorPtr& se = SE_MaxFundsOptimal(),
25
+ const TradeManagerPtr& train_tm = TradeManagerPtr());
26
+
27
+ } // namespace hku
@@ -0,0 +1,51 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-13
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #include "../System.h"
10
+
11
+ namespace hku {
12
+
13
+ class HKU_API DelegateSystem : public System {
14
+ public:
15
+ DelegateSystem() = default;
16
+ explicit DelegateSystem(const string& name) : System(name) {}
17
+ explicit DelegateSystem(const SystemPtr& sys) : m_sys(sys) {}
18
+ virtual ~DelegateSystem() = default;
19
+
20
+ virtual void run(const KData& kdata, bool reset = true, bool resetAll = false) override;
21
+ virtual TradeRecord runMoment(const Datetime& datetime) override;
22
+
23
+ virtual void _reset() override;
24
+ virtual void _forceResetAll() override;
25
+ virtual SystemPtr _clone() override;
26
+
27
+ public:
28
+ virtual TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) override;
29
+ virtual TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) override;
30
+ virtual void clearDelayBuyRequest() override;
31
+ virtual bool haveDelaySellRequest() const override;
32
+ virtual TradeRecord pfProcessDelaySellRequest(const Datetime& date) override;
33
+
34
+ private:
35
+ SystemPtr m_sys;
36
+
37
+ //========================================
38
+ // 序列化支持
39
+ //========================================
40
+ #if HKU_SUPPORT_SERIALIZATION
41
+ private:
42
+ friend class boost::serialization::access;
43
+ template <class Archive>
44
+ void serialize(Archive& ar, const unsigned int version) {
45
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(System);
46
+ ar& BOOST_SERIALIZATION_NVP(m_sys);
47
+ }
48
+ #endif /* HKU_SUPPORT_SERIALIZATION */
49
+ };
50
+
51
+ } // namespace hku
@@ -0,0 +1,70 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-13
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/trade_sys/selector/SelectorBase.h"
11
+ #include "../System.h"
12
+
13
+ namespace hku {
14
+
15
+ class HKU_API WalkForwardSystem : public System {
16
+ CLASS_LOGGER_IMP(SYS_WalkForward)
17
+
18
+ public:
19
+ WalkForwardSystem();
20
+ WalkForwardSystem(const SystemList& candidate_sys_list, const SelectorPtr& se,
21
+ const TradeManagerPtr& train_tm);
22
+ virtual ~WalkForwardSystem() = default;
23
+
24
+ virtual void readyForRun() override;
25
+ virtual void run(const KData& kdata, bool reset = true, bool resetAll = false) override;
26
+ virtual TradeRecord runMoment(const Datetime& datetime) override;
27
+
28
+ virtual void _checkParam(const string& name) const override;
29
+ virtual void _reset() override;
30
+ virtual void _forceResetAll() override;
31
+ virtual SystemPtr _clone() override;
32
+
33
+ virtual string str() const override;
34
+
35
+ public:
36
+ virtual TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) override;
37
+ virtual TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) override;
38
+ virtual void clearDelayBuyRequest() override;
39
+ virtual bool haveDelaySellRequest() const override;
40
+ virtual TradeRecord pfProcessDelaySellRequest(const Datetime& date) override;
41
+
42
+ private:
43
+ void initParam();
44
+ void syncDataFromSystem(const SYSPtr&, bool isMoment);
45
+ void syncDataToSystem(const SYSPtr&);
46
+
47
+ private:
48
+ SEPtr m_se; // 寻优SE
49
+ TMPtr m_train_tm; // 用于优化评估计算的账户
50
+ SYSPtr m_cur_sys;
51
+ size_t m_cur_kdata{0};
52
+ vector<KData> m_train_kdata_list;
53
+ vector<RunRanges> m_run_ranges;
54
+
55
+ //========================================
56
+ // 序列化支持
57
+ //========================================
58
+ #if HKU_SUPPORT_SERIALIZATION
59
+ private:
60
+ friend class boost::serialization::access;
61
+ template <class Archive>
62
+ void serialize(Archive& ar, const unsigned int version) {
63
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(System);
64
+ ar& BOOST_SERIALIZATION_NVP(m_se);
65
+ ar& BOOST_SERIALIZATION_NVP(m_train_tm);
66
+ }
67
+ #endif /* HKU_SUPPORT_SERIALIZATION */
68
+ };
69
+
70
+ } // namespace hku