hikyuu 2.1.4__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 (99) 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/0022.sql +5 -0
  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/0023.sql +7 -0
  13. hikyuu/data/sqlite_upgrade/0024.sql +22 -0
  14. hikyuu/fetcher/stock/zh_stock_a_pytdx.py +3 -3
  15. hikyuu/gui/HikyuuTDX.py +3 -2
  16. hikyuu/gui/data/ImportHistoryFinanceTask.py +7 -0
  17. hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -2
  18. hikyuu/gui/data/MainWindow.py +1 -1
  19. hikyuu/gui/start_qmt.py +99 -13
  20. hikyuu/include/hikyuu/StockWeight.h +16 -10
  21. hikyuu/include/hikyuu/analysis/analysis_sys.h +42 -12
  22. hikyuu/include/hikyuu/data_driver/base_info/table/StockWeightTable.h +6 -4
  23. hikyuu/include/hikyuu/global/agent/SpotAgent.h +5 -6
  24. hikyuu/include/hikyuu/indicator/crt/DMA.h +1 -7
  25. hikyuu/include/hikyuu/indicator/crt/IC.h +7 -6
  26. hikyuu/include/hikyuu/indicator/crt/ICIR.h +7 -4
  27. hikyuu/include/hikyuu/indicator/imp/IDma.h +47 -0
  28. hikyuu/include/hikyuu/indicator/imp/IIc.h +1 -1
  29. hikyuu/include/hikyuu/serialization/StockWeight_serialization.h +5 -2
  30. hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +27 -25
  31. hikyuu/include/hikyuu/strategy/Strategy.h +1 -2
  32. hikyuu/include/hikyuu/trade_manage/Performance.h +3 -0
  33. hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +16 -6
  34. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
  35. hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +0 -3
  36. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +2 -2
  37. hikyuu/include/hikyuu/trade_sys/condition/build_in.h +1 -0
  38. hikyuu/include/hikyuu/trade_sys/condition/crt/CN_Manual.h +20 -0
  39. hikyuu/include/hikyuu/trade_sys/condition/imp/ManualCondition.h +23 -0
  40. hikyuu/include/hikyuu/trade_sys/condition/imp/{AddCondition.h → logic/AddCondition.h} +1 -1
  41. hikyuu/include/hikyuu/trade_sys/condition/imp/{AndCondition.h → logic/AndCondition.h} +1 -1
  42. hikyuu/include/hikyuu/trade_sys/condition/imp/{DivCondition.h → logic/DivCondition.h} +1 -1
  43. hikyuu/include/hikyuu/trade_sys/condition/imp/{MultiCondition.h → logic/MultiCondition.h} +1 -1
  44. hikyuu/include/hikyuu/trade_sys/condition/imp/{OrCondition.h → logic/OrCondition.h} +1 -1
  45. hikyuu/include/hikyuu/trade_sys/condition/imp/logic/__init__.py +1 -0
  46. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -6
  47. hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
  48. hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Manual.h +20 -0
  49. hikyuu/include/hikyuu/trade_sys/environment/imp/ManualEnvironment.h +23 -0
  50. hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +1 -1
  51. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -1
  52. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +3 -2
  53. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -2
  54. hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
  55. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
  56. hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
  57. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +2 -2
  58. hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +3 -1
  59. hikyuu/include/hikyuu/trade_sys/selector/build_in.h +2 -1
  60. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -1
  61. hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +26 -0
  62. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSelector.h → logic/OperatorSelector.h} +1 -1
  63. hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorValueSelector.h → logic/OperatorValueSelector.h} +1 -1
  64. hikyuu/include/hikyuu/trade_sys/selector/imp/logic/__init__.py +1 -0
  65. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/MaxFundsOptimalSelector.h +27 -0
  66. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +86 -0
  67. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +42 -0
  68. hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/__init__.py +1 -0
  69. hikyuu/include/hikyuu/trade_sys/signal/build_in.h +1 -0
  70. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Manual.h +20 -0
  71. hikyuu/include/hikyuu/trade_sys/signal/imp/ManualSignal.h +23 -0
  72. hikyuu/include/hikyuu/trade_sys/system/System.h +30 -13
  73. hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +19 -11
  74. hikyuu/include/hikyuu/trade_sys/system/build_in.h +1 -0
  75. hikyuu/include/hikyuu/trade_sys/system/crt/SYS_WalkForward.h +27 -0
  76. hikyuu/include/hikyuu/trade_sys/system/imp/DelegateSystem.h +51 -0
  77. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +70 -0
  78. hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +465 -0
  79. hikyuu/include/hikyuu/utilities/base64.h +25 -31
  80. hikyuu/include/hikyuu/version.h +5 -5
  81. hikyuu/strategy/strategy_demo1.py +2 -1
  82. hikyuu/trade_sys/trade_sys.py +28 -9
  83. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/METADATA +1 -1
  84. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/RECORD +99 -77
  85. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/top_level.txt +3 -0
  86. /hikyuu/include/hikyuu/trade_sys/selector/crt/{SE_Operator.h → SE_Logic.h} +0 -0
  87. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddSelector.h → logic/OperatorAddSelector.h} +0 -0
  88. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddValueSelector.h → logic/OperatorAddValueSelector.h} +0 -0
  89. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivSelector.h → logic/OperatorDivSelector.h} +0 -0
  90. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivValueSelector.h → logic/OperatorDivValueSelector.h} +0 -0
  91. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertDivValueSelector.h → logic/OperatorInvertDivValueSelector.h} +0 -0
  92. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertSubValueSelector.h → logic/OperatorInvertSubValueSelector.h} +0 -0
  93. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulSelector.h → logic/OperatorMulSelector.h} +0 -0
  94. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulValueSelector.h → logic/OperatorMulValueSelector.h} +0 -0
  95. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubSelector.h → logic/OperatorSubSelector.h} +0 -0
  96. /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubValueSelector.h → logic/OperatorSubValueSelector.h} +0 -0
  97. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/LICENSE +0 -0
  98. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/WHEEL +0 -0
  99. {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/entry_points.txt +0 -0
@@ -16,8 +16,8 @@
16
16
  namespace hku {
17
17
 
18
18
  class StockWeightTable {
19
- TABLE_BIND9(StockWeightTable, stkweight, stockid, date, countAsGift, countForSell, priceForSell,
20
- bonus, countOfIncreasement, totalCount, freeCount)
19
+ TABLE_BIND10(StockWeightTable, stkweight, stockid, date, countAsGift, countForSell,
20
+ priceForSell, bonus, countOfIncreasement, totalCount, freeCount, suogu)
21
21
 
22
22
  public:
23
23
  uint64_t stockid{0};
@@ -29,11 +29,12 @@ public:
29
29
  double countOfIncreasement{0.};
30
30
  double totalCount{0.};
31
31
  double freeCount{0.};
32
+ double suogu{0.};
32
33
  };
33
34
 
34
35
  struct StockWeightTableView {
35
- TABLE_BIND9(StockWeightTableView, stkweight, market_code, date, countAsGift, countForSell,
36
- priceForSell, bonus, countOfIncreasement, totalCount, freeCount)
36
+ TABLE_BIND10(StockWeightTableView, stkweight, market_code, date, countAsGift, countForSell,
37
+ priceForSell, bonus, countOfIncreasement, totalCount, freeCount, suogu)
37
38
  string market_code;
38
39
  uint64_t date{0};
39
40
  double countAsGift{0.};
@@ -43,6 +44,7 @@ struct StockWeightTableView {
43
44
  double countOfIncreasement{0.};
44
45
  double totalCount{0.};
45
46
  double freeCount{0.};
47
+ double suogu{0.0};
46
48
  };
47
49
 
48
50
  } // namespace hku
@@ -125,12 +125,11 @@ private:
125
125
  enum STATUS m_status = WAITING; // 当前内部状态
126
126
  std::atomic_bool m_stop = true; // 结束代理工作标识
127
127
 
128
- int m_revTimeout = 100; // 连接数据服务超时时长(毫秒)
129
- size_t m_batch_count = 0; // 记录本次批次接收的数据数量
130
- std::thread m_receiveThread; // 数据接收线程
131
- std::unique_ptr<ThreadPool> m_tg; // 数据处理任务线程池
132
- size_t m_work_num = 1; // 数据处理任务线程池线程数
133
- vector<std::future<void>> m_process_task_list;
128
+ int m_revTimeout = 100; // 连接数据服务超时时长(毫秒)
129
+ std::thread m_receiveThread; // 数据接收线程
130
+ std::unique_ptr<ThreadPool> m_tg; // 数据处理任务线程池
131
+ size_t m_work_num = 1; // 数据处理任务线程池线程数
132
+ std::unique_ptr<ThreadPool> m_receive_data_tg; // 数据接收任务组
134
133
 
135
134
  bool m_print = true; // 是否打印连接信息
136
135
  string m_server_addr; // 服务器地址
@@ -27,13 +27,7 @@ namespace hku {
27
27
  * @param a 动态系数
28
28
  * @ingroup Indicator
29
29
  */
30
- Indicator DMA(const Indicator& ind1, const Indicator& a);
31
-
32
- inline Indicator DMA(const Indicator& ind1, const Indicator& a) {
33
- Indicator dma = a * ind1 + (1 - a) * REF(ind1, 1);
34
- dma.name("DMA");
35
- return dma;
36
- }
30
+ Indicator HKU_API DMA(const Indicator& x, const Indicator& a);
37
31
 
38
32
  } // namespace hku
39
33
 
@@ -18,23 +18,24 @@ namespace hku {
18
18
  * @param query 查询条件
19
19
  * @param ref_stk 参照证券,默认 sh000300 沪深300
20
20
  * @param n 时间窗口 (对应 n 日收益率)
21
+ * @param spearman 使用 spearman 相关系数,否则为 pearson
21
22
  * @return Indicator
22
23
  * @ingroup Indicator
23
24
  */
24
25
  Indicator HKU_API IC(const StockList& stks, const KQuery& query,
25
- const Stock& ref_stk = getStock("sh000300"), int n = 1);
26
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
26
27
 
27
28
  Indicator HKU_API IC(const Block& blk, const KQuery& query,
28
- const Stock& ref_stk = getStock("sh000300"), int n = 1);
29
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true);
29
30
 
30
31
  inline Indicator IC(const Indicator& ind, const StockList& stks, const KQuery& query,
31
- const Stock& ref_stk = getStock("sh000300"), int n = 1) {
32
- return IC(stks, query, ref_stk, n)(ind);
32
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
33
+ return IC(stks, query, ref_stk, n, spearman)(ind);
33
34
  }
34
35
 
35
36
  inline Indicator IC(const Indicator& ind, const Block& blk, const KQuery& query,
36
- const Stock& ref_stk = getStock("sh000300"), int n = 1) {
37
- return IC(blk, query, ref_stk, n)(ind);
37
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true) {
38
+ return IC(blk, query, ref_stk, n, spearman)(ind);
38
39
  }
39
40
 
40
41
  } // namespace hku
@@ -22,12 +22,14 @@ namespace hku {
22
22
  * @param ref_stk 参照证券,默认 sh000300 沪深300
23
23
  * @param n IC对应的N日收益率
24
24
  * @param rolling_n 滚动时间窗口
25
+ * @param spearman 使用 spearman 相关系数,否则为 pearson
25
26
  * @return Indicator
26
27
  * @ingroup Indicator
27
28
  */
28
29
  inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery& query,
29
- const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120) {
30
- Indicator ic = IC(ind, stks, query, ref_stk, n);
30
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
31
+ bool spearman = true) {
32
+ Indicator ic = IC(ind, stks, query, ref_stk, n, spearman);
31
33
  Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
32
34
  x.name("ICIR");
33
35
  x.setParam<int>("n", n);
@@ -36,8 +38,9 @@ inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery&
36
38
  }
37
39
 
38
40
  inline Indicator ICIR(const Indicator& ind, const Block& blk, const KQuery& query,
39
- const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120) {
40
- Indicator ic = IC(ind, blk, query, ref_stk, n);
41
+ const Stock& ref_stk = getStock("sh000300"), int n = 1, int rolling_n = 120,
42
+ bool spearman = true) {
43
+ Indicator ic = IC(ind, blk, query, ref_stk, n, spearman);
41
44
  Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
42
45
  x.name("ICIR");
43
46
  x.setParam<int>("n", n);
@@ -0,0 +1,47 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-09-09
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../Indicator.h"
11
+
12
+ namespace hku {
13
+
14
+ /*
15
+ * 动态移动平均
16
+ * 用法:DMA(X,A),求X的动态移动平均。
17
+ * 算法:若Y=DMA(X,A) 则 Y=A*X+(1-A)*Y',其中Y'表示上一周期Y值。
18
+ * 例如:DMA(CLOSE,VOL/CAPITAL)表示求以换手率作平滑因子的平均价
19
+ */
20
+ class IDma : public IndicatorImp {
21
+ public:
22
+ IDma();
23
+ explicit IDma(const Indicator& ref_a);
24
+ virtual ~IDma();
25
+
26
+ virtual void _checkParam(const string& name) const override;
27
+ virtual void _calculate(const Indicator& data) override;
28
+ virtual IndicatorImpPtr _clone() override;
29
+
30
+ private:
31
+ Indicator m_ref_a;
32
+
33
+ //============================================
34
+ // 序列化支持
35
+ //============================================
36
+ #if HKU_SUPPORT_SERIALIZATION
37
+ private:
38
+ friend class boost::serialization::access;
39
+ template <class Archive>
40
+ void serialize(Archive& ar, const unsigned int version) {
41
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(IndicatorImp);
42
+ ar& BOOST_SERIALIZATION_NVP(m_ref_a);
43
+ }
44
+ #endif
45
+ };
46
+
47
+ }
@@ -14,7 +14,7 @@ namespace hku {
14
14
  class IIc : public IndicatorImp {
15
15
  public:
16
16
  IIc();
17
- IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk);
17
+ IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman);
18
18
  virtual ~IIc();
19
19
 
20
20
  virtual void _checkParam(const string& name) const override;
@@ -26,6 +26,7 @@ void save(Archive& ar, const hku::StockWeight& record, unsigned int version) {
26
26
  hku::price_t increasement = record.increasement();
27
27
  hku::price_t totalCount = record.totalCount();
28
28
  hku::price_t freeCount = record.freeCount();
29
+ hku::price_t suogu = record.suogu();
29
30
  ar& BOOST_SERIALIZATION_NVP(datetime);
30
31
  ar& BOOST_SERIALIZATION_NVP(countAsGift);
31
32
  ar& BOOST_SERIALIZATION_NVP(countForSell);
@@ -34,13 +35,14 @@ void save(Archive& ar, const hku::StockWeight& record, unsigned int version) {
34
35
  ar& BOOST_SERIALIZATION_NVP(increasement);
35
36
  ar& BOOST_SERIALIZATION_NVP(totalCount);
36
37
  ar& BOOST_SERIALIZATION_NVP(freeCount);
38
+ ar& BOOST_SERIALIZATION_NVP(suogu);
37
39
  }
38
40
 
39
41
  template <class Archive>
40
42
  void load(Archive& ar, hku::StockWeight& record, unsigned int version) {
41
43
  hku::uint64_t datetime;
42
44
  hku::price_t countAsGift, countForSell, priceForSell, bonus;
43
- hku::price_t increasement, totalCount, freeCount;
45
+ hku::price_t increasement, totalCount, freeCount, suogu;
44
46
  ar& BOOST_SERIALIZATION_NVP(datetime);
45
47
  ar& BOOST_SERIALIZATION_NVP(countAsGift);
46
48
  ar& BOOST_SERIALIZATION_NVP(countForSell);
@@ -49,8 +51,9 @@ void load(Archive& ar, hku::StockWeight& record, unsigned int version) {
49
51
  ar& BOOST_SERIALIZATION_NVP(increasement);
50
52
  ar& BOOST_SERIALIZATION_NVP(totalCount);
51
53
  ar& BOOST_SERIALIZATION_NVP(freeCount);
54
+ ar& BOOST_SERIALIZATION_NVP(suogu);
52
55
  record = hku::StockWeight(hku::Datetime(datetime), countAsGift, countForSell, priceForSell,
53
- bonus, increasement, totalCount, freeCount);
56
+ bonus, increasement, totalCount, freeCount, suogu);
54
57
  }
55
58
  } // namespace serialization
56
59
  } // namespace boost
@@ -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