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
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-14
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../SelectorBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 账户资产最大寻优选择器
16
+ * @return SEPtr
17
+ */
18
+ SEPtr HKU_API SE_MaxFundsOptimal();
19
+
20
+ /**
21
+ * 使用 Performance 统计结果进行寻优的选择器
22
+ * @return SEPtr
23
+ */
24
+ SEPtr HKU_API SE_PerformanceOptimal(const string& key = "帐户平均年收益率%", int mode = 0);
25
+
26
+ } // namespace hku
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../SelectorBase.h"
10
+ #include "hikyuu/trade_sys/selector/SelectorBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -7,7 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
- #include "../SelectorBase.h"
10
+ #include "hikyuu/trade_sys/selector/SelectorBase.h"
11
11
 
12
12
  namespace hku {
13
13
 
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-22
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_
10
+ #define HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_
11
+
12
+ #include "OptimalSelectorBase.h"
13
+
14
+ namespace hku {
15
+
16
+ class MaxFundsOptimalSelector : public OptimalSelectorBase {
17
+ OPTIMAL_SELECTOR_IMP(MaxFundsOptimalSelector)
18
+ OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
19
+
20
+ public:
21
+ MaxFundsOptimalSelector();
22
+ virtual ~MaxFundsOptimalSelector();
23
+ };
24
+
25
+ } // namespace hku
26
+
27
+ #endif /* HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_ */
@@ -0,0 +1,86 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-13
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #include "hikyuu/trade_sys/selector/SelectorBase.h"
10
+
11
+ namespace hku {
12
+
13
+ //
14
+ // start ------ run_start --end
15
+ // | train_len | test_len
16
+ //
17
+ struct RunRanges {
18
+ Datetime start;
19
+ Datetime run_start;
20
+ Datetime end;
21
+
22
+ RunRanges(const Datetime& start_, const Datetime& run_start_, const Datetime end_)
23
+ : start(start_), run_start(run_start_), end(end_) {}
24
+ };
25
+
26
+ class HKU_API OptimalSelectorBase : public SelectorBase {
27
+ CLASS_LOGGER_IMP(SE_Optimal)
28
+ SELECTOR_IMP(OptimalSelectorBase)
29
+ SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
30
+
31
+ public:
32
+ OptimalSelectorBase();
33
+ explicit OptimalSelectorBase(const string& name);
34
+ virtual ~OptimalSelectorBase() = default;
35
+
36
+ virtual void _checkParam(const string& name) const override;
37
+ virtual void calculate(const SystemList& pf_realSysList, const KQuery& query) override;
38
+
39
+ virtual void _reset() override;
40
+
41
+ virtual string str() const override;
42
+
43
+ // 以便继承子类只需要实现 _clone 和 该接口即可
44
+ // 该接口实现系统绩效评估,getSelected 时将取评估结果最大的系统
45
+ // 使用 std::function 的话,在 C++ 中无法序列化,所以使用继承
46
+ virtual double evaluate(const SYSPtr& sys, const Datetime& endDate) noexcept {
47
+ return Null<double>();
48
+ }
49
+
50
+ const vector<RunRanges>& getRunRanges() const {
51
+ return m_run_ranges;
52
+ }
53
+
54
+ private:
55
+ void _initParams();
56
+ void _calculate_single(const vector<std::pair<size_t, size_t>>& train_ranges,
57
+ const DatetimeList& dates, size_t test_len, bool trace);
58
+
59
+ void _calculate_parallel(const vector<std::pair<size_t, size_t>>& train_ranges,
60
+ const DatetimeList& dates, size_t test_len, bool trace);
61
+
62
+ protected:
63
+ unordered_map<Datetime, std::shared_ptr<SystemWeightList>> m_sys_dict;
64
+ vector<RunRanges> m_run_ranges;
65
+ };
66
+
67
+ #if HKU_SUPPORT_SERIALIZATION
68
+ #define OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION \
69
+ private: \
70
+ friend class boost::serialization::access; \
71
+ template <class Archive> \
72
+ void serialize(Archive& ar, const unsigned int version) { \
73
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(SelectorBase); \
74
+ }
75
+ #else
76
+ #define OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
77
+ #endif
78
+
79
+ #define OPTIMAL_SELECTOR_IMP(classname) \
80
+ public: \
81
+ virtual SelectorPtr _clone() override { \
82
+ return std::make_shared<classname>(); \
83
+ } \
84
+ virtual double evaluate(const SYSPtr&, const Datetime& endDate) noexcept override;
85
+
86
+ } // namespace hku
@@ -0,0 +1,42 @@
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 "OptimalSelectorBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class PerformanceOptimalSelector : public OptimalSelectorBase {
15
+ CLASS_LOGGER_IMP(SE_Optimal)
16
+ OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ PerformanceOptimalSelector();
20
+ virtual ~PerformanceOptimalSelector() = default;
21
+
22
+ virtual void _checkParam(const string& name) const override;
23
+ virtual void calculate(const SystemList& pf_realSysList, const KQuery& query) override;
24
+
25
+ virtual SystemWeightList getSelected(Datetime date);
26
+ virtual SelectorPtr _clone() override;
27
+ virtual void _reset() override;
28
+
29
+ private:
30
+ void _calculate_single(const vector<std::pair<size_t, size_t>>& train_ranges,
31
+ const DatetimeList& dates, const string& key, int mode, size_t test_len,
32
+ bool trace);
33
+
34
+ void _calculate_parallel(const vector<std::pair<size_t, size_t>>& train_ranges,
35
+ const DatetimeList& dates, const string& key, int mode,
36
+ size_t test_len, bool trace);
37
+
38
+ private:
39
+ unordered_map<Datetime, SYSPtr> m_sys_dict;
40
+ };
41
+
42
+ } // namespace hku
@@ -17,5 +17,6 @@
17
17
  #include "crt/SG_Single.h"
18
18
  #include "crt/SG_Bool.h"
19
19
  #include "crt/SG_Band.h"
20
+ #include "crt/SG_Manual.h"
20
21
 
21
22
  #endif /* SIGNAL_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 "../SignalBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 仅能手动添加信号的信号指示器,用于测试或其他特殊用途
16
+ * @return SignalPtr
17
+ */
18
+ SignalPtr HKU_API SG_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 "../SignalBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class ManualSignal : public SignalBase {
15
+ SIGNAL_IMP(ManualSignal)
16
+ SIGNAL_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ ManualSignal();
20
+ virtual ~ManualSignal() = default;
21
+ };
22
+
23
+ } // namespace hku
@@ -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