hikyuu 2.3.0__py3-none-win_amd64.whl → 2.5.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. hikyuu/__init__.py +438 -6
  2. hikyuu/__init__.pyi +791 -0
  3. hikyuu/analysis/__init__.pyi +487 -0
  4. hikyuu/analysis/analysis.pyi +517 -0
  5. hikyuu/core.pyi +482 -0
  6. hikyuu/cpp/__init__.pyi +3 -0
  7. hikyuu/cpp/boost_date_time-mt.dll +0 -0
  8. hikyuu/cpp/boost_serialization-mt.dll +0 -0
  9. hikyuu/cpp/boost_wserialization-mt.dll +0 -0
  10. hikyuu/cpp/core310.pyd +0 -0
  11. hikyuu/cpp/core311.pyd +0 -0
  12. hikyuu/cpp/core312.pyd +0 -0
  13. hikyuu/cpp/core312.pyi +12867 -0
  14. hikyuu/cpp/core313.pyd +0 -0
  15. hikyuu/cpp/core38.pyd +0 -0
  16. hikyuu/cpp/core39.pyd +0 -0
  17. hikyuu/cpp/hikyuu.dll +0 -0
  18. hikyuu/cpp/hikyuu.lib +0 -0
  19. hikyuu/cpp/sqlite3.dll +0 -0
  20. hikyuu/data/common_mysql.py +24 -7
  21. hikyuu/data/common_pytdx.py +17 -1
  22. hikyuu/data/em_block_to_mysql.py +3 -2
  23. hikyuu/data/em_block_to_sqlite.py +8 -3
  24. hikyuu/data/mysql_upgrade/0025.sql +61 -0
  25. hikyuu/data/mysql_upgrade/0026.sql +9 -0
  26. hikyuu/data/sqlite_upgrade/0025.sql +63 -0
  27. hikyuu/data/sqlite_upgrade/0026.sql +10 -0
  28. hikyuu/draw/__init__.pyi +35 -0
  29. hikyuu/draw/drawplot/__init__.py +3 -0
  30. hikyuu/draw/drawplot/__init__.pyi +134 -0
  31. hikyuu/draw/drawplot/bokeh_draw.pyi +796 -0
  32. hikyuu/draw/drawplot/common.pyi +10 -0
  33. hikyuu/draw/drawplot/echarts_draw.py +219 -24
  34. hikyuu/draw/drawplot/echarts_draw.pyi +682 -0
  35. hikyuu/draw/drawplot/matplotlib_draw.py +18 -3
  36. hikyuu/draw/drawplot/matplotlib_draw.pyi +1101 -0
  37. hikyuu/draw/elder.pyi +44 -0
  38. hikyuu/draw/kaufman.pyi +38 -0
  39. hikyuu/draw/volume.pyi +31 -0
  40. hikyuu/examples/notebook/Demo/Demo2.ipynb +1 -1
  41. hikyuu/extend.py +9 -3
  42. hikyuu/extend.pyi +636 -0
  43. hikyuu/fetcher/stock/zh_block_em.py +118 -51
  44. hikyuu/gui/data/EscapetimeThread.py +4 -4
  45. hikyuu/gui/data/ImportBlockInfoTask.py +3 -2
  46. hikyuu/gui/data/ImportHistoryFinanceTask.py +2 -0
  47. hikyuu/gui/data/MainWindow.py +48 -42
  48. hikyuu/gui/importdata.py +13 -26
  49. hikyuu/hub.py +2 -4
  50. hikyuu/hub.pyi +254 -0
  51. hikyuu/include/hikyuu/DataType.h +5 -0
  52. hikyuu/include/hikyuu/Stock.h +7 -0
  53. hikyuu/include/hikyuu/indicator/Indicator.h +8 -1
  54. hikyuu/include/hikyuu/indicator/Indicator2InImp.h +65 -0
  55. hikyuu/include/hikyuu/indicator/IndicatorImp.h +4 -3
  56. hikyuu/include/hikyuu/indicator/build_in.h +12 -0
  57. hikyuu/include/hikyuu/indicator/crt/ADVANCE.h +3 -1
  58. hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +2 -2
  59. hikyuu/include/hikyuu/indicator/crt/CORR.h +4 -2
  60. hikyuu/include/hikyuu/indicator/crt/COST.h +3 -0
  61. hikyuu/include/hikyuu/indicator/crt/CYCLE.h +24 -0
  62. hikyuu/include/hikyuu/indicator/crt/DECLINE.h +3 -1
  63. hikyuu/include/hikyuu/indicator/crt/DISCARD.h +27 -0
  64. hikyuu/include/hikyuu/indicator/crt/DMA.h +2 -1
  65. hikyuu/include/hikyuu/indicator/crt/HSL.h +1 -13
  66. hikyuu/include/hikyuu/indicator/crt/INBLOCK.h +31 -0
  67. hikyuu/include/hikyuu/indicator/crt/INDEX.h +60 -0
  68. hikyuu/include/hikyuu/indicator/crt/INSUM.h +5 -2
  69. hikyuu/include/hikyuu/indicator/crt/ISINF.h +28 -0
  70. hikyuu/include/hikyuu/indicator/crt/ISINFA.h +28 -0
  71. hikyuu/include/hikyuu/indicator/crt/ISNA.h +29 -0
  72. hikyuu/include/hikyuu/indicator/crt/JUMPDOWN.h +24 -0
  73. hikyuu/include/hikyuu/indicator/crt/JUMPUP.h +24 -0
  74. hikyuu/include/hikyuu/indicator/crt/LASTVALUE.h +29 -0
  75. hikyuu/include/hikyuu/indicator/crt/LIUTONGPAN.h +1 -0
  76. hikyuu/include/hikyuu/indicator/crt/REPLACE.h +29 -0
  77. hikyuu/include/hikyuu/indicator/crt/SPEARMAN.h +3 -2
  78. hikyuu/include/hikyuu/indicator/crt/WINNER.h +38 -0
  79. hikyuu/include/hikyuu/indicator/imp/IContext.h +1 -1
  80. hikyuu/include/hikyuu/indicator/imp/ICorr.h +7 -22
  81. hikyuu/include/hikyuu/indicator/imp/ICost.h +31 -0
  82. hikyuu/include/hikyuu/indicator/imp/ICycle.h +30 -0
  83. hikyuu/include/hikyuu/indicator/imp/IDiscard.h +28 -0
  84. hikyuu/include/hikyuu/indicator/imp/IDma.h +7 -24
  85. hikyuu/include/hikyuu/indicator/imp/IHsl.h +30 -0
  86. hikyuu/include/hikyuu/indicator/imp/IInBlock.h +30 -0
  87. hikyuu/include/hikyuu/indicator/imp/IIndex.h +26 -0
  88. hikyuu/include/hikyuu/indicator/imp/IIsInf.h +26 -0
  89. hikyuu/include/hikyuu/indicator/imp/IIsInfa.h +26 -0
  90. hikyuu/include/hikyuu/indicator/imp/IIsNa.h +26 -0
  91. hikyuu/include/hikyuu/indicator/imp/IJumpDown.h +24 -0
  92. hikyuu/include/hikyuu/indicator/imp/IJumpUp.h +24 -0
  93. hikyuu/include/hikyuu/indicator/imp/ILastValue.h +26 -0
  94. hikyuu/include/hikyuu/indicator/imp/IReplace.h +26 -0
  95. hikyuu/include/hikyuu/indicator/imp/ISpearman.h +6 -21
  96. hikyuu/include/hikyuu/indicator/imp/IWinner.h +26 -0
  97. hikyuu/include/hikyuu/indicator_talib/imp/TaMavp.h +6 -20
  98. hikyuu/include/hikyuu/indicator_talib/imp/ta_defines.h +14 -65
  99. hikyuu/include/hikyuu/indicator_talib/imp/ta_imp.h +54 -90
  100. hikyuu/include/hikyuu/indicator_talib/ta_crt.h +11 -9
  101. hikyuu/include/hikyuu/strategy/RunPortfolioInStrategy.h +3 -4
  102. hikyuu/include/hikyuu/strategy/Strategy.h +4 -5
  103. hikyuu/include/hikyuu/trade_manage/TradeRecord.h +5 -1
  104. hikyuu/include/hikyuu/trade_sys/allocatefunds/build_in.h +1 -0
  105. hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_FixedWeightList.h +22 -0
  106. hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/FixedWeightListAllocateFunds.h +25 -0
  107. hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +17 -4
  108. hikyuu/include/hikyuu/trade_sys/moneymanager/build_in.h +2 -0
  109. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapital.h +6 -0
  110. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCapitalFunds.h +26 -0
  111. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedCountTps.h +27 -0
  112. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedRisk.h +6 -0
  113. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_FixedUnits.h +6 -0
  114. hikyuu/include/hikyuu/trade_sys/moneymanager/crt/MM_WilliamsFixedRisk.h +7 -0
  115. hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCapitalFundsMM.h +28 -0
  116. hikyuu/include/hikyuu/trade_sys/moneymanager/imp/FixedCountTpsMM.h +44 -0
  117. hikyuu/include/hikyuu/trade_sys/multifactor/build_in.h +1 -0
  118. hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_Weight.h +30 -0
  119. hikyuu/include/hikyuu/trade_sys/multifactor/imp/WeightMultiFactor.h +41 -0
  120. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +38 -37
  121. hikyuu/include/hikyuu/trade_sys/portfolio/build_in.h +1 -0
  122. hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_Simple.h +25 -1
  123. hikyuu/include/hikyuu/trade_sys/portfolio/crt/PF_WithoutAF.h +50 -0
  124. hikyuu/include/hikyuu/trade_sys/portfolio/imp/SimplePortfolio.h +53 -0
  125. hikyuu/include/hikyuu/trade_sys/portfolio/imp/WithoutAFPortfolio.h +57 -0
  126. hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +7 -0
  127. hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +51 -5
  128. hikyuu/include/hikyuu/trade_sys/signal/build_in.h +2 -0
  129. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Bool.h +2 -1
  130. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Logic.h +37 -0
  131. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_OneSide.h +28 -0
  132. hikyuu/include/hikyuu/trade_sys/signal/imp/OneSideSignal.h +46 -0
  133. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddSignal.h +19 -0
  134. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AddValueSignal.h +19 -0
  135. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivSignal.h +19 -0
  136. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/DivValueSignal.h +22 -0
  137. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulSignal.h +19 -0
  138. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/MulValueSignal.h +19 -0
  139. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +68 -0
  140. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +67 -0
  141. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubSignal.h +19 -0
  142. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/SubValueSignal.h +22 -0
  143. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/__init__.py +1 -0
  144. hikyuu/include/hikyuu/trade_sys/stoploss/crt/ST_Indicator.h +1 -1
  145. hikyuu/include/hikyuu/trade_sys/stoploss/imp/IndicatorStoploss.h +3 -4
  146. hikyuu/include/hikyuu/utilities/FilterNode.h +2 -2
  147. hikyuu/include/hikyuu/utilities/Log.h +42 -15
  148. hikyuu/include/hikyuu/utilities/datetime/Datetime.h +1 -1
  149. hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +2 -2
  150. hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +4 -0
  151. hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +2 -2
  152. hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +5 -1
  153. hikyuu/include/hikyuu/utilities/node/NodeServer.h +4 -4
  154. hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +2 -2
  155. hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +2 -2
  156. hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +5 -5
  157. hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +2 -2
  158. hikyuu/include/hikyuu/utilities/thread/algorithm.h +16 -10
  159. hikyuu/include/hikyuu/version.h +4 -4
  160. hikyuu/indicator/indicator.py +1 -0
  161. hikyuu/interactive.py +3 -266
  162. hikyuu/trade_manage/__init__.pyi +584 -0
  163. hikyuu/trade_manage/broker.pyi +54 -0
  164. hikyuu/trade_manage/broker_easytrader.pyi +21 -0
  165. hikyuu/trade_manage/broker_mail.pyi +55 -0
  166. hikyuu/trade_manage/trade.pyi +590 -0
  167. hikyuu/util/__init__.pyi +55 -0
  168. hikyuu/util/check.pyi +59 -0
  169. hikyuu/util/mylog.pyi +70 -0
  170. hikyuu/util/notebook.pyi +23 -0
  171. hikyuu/util/singleton.pyi +18 -0
  172. hikyuu/util/slice.pyi +8 -0
  173. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/METADATA +3 -2
  174. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/RECORD +178 -95
  175. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/top_level.txt +1 -0
  176. hikyuu/deprecated.py +0 -651
  177. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/LICENSE +0 -0
  178. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/WHEEL +0 -0
  179. {hikyuu-2.3.0.dist-info → hikyuu-2.5.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright (c) 2019 hikyuu.org
3
+ *
4
+ * Created on: 2018年2月8日
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../AllocateFundsBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * @brief 固定比例资产分配
16
+ * @param weights 指定的资产比例列表
17
+ * @return AFPtr
18
+ * @ingroup AllocateFunds
19
+ */
20
+ AFPtr HKU_API AF_FixedWeightList(const vector<double>& weights);
21
+
22
+ } /* namespace hku */
@@ -0,0 +1,25 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-02-07
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../AllocateFundsBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class FixedWeightListAllocateFunds : public AllocateFundsBase {
15
+ ALLOCATEFUNDS_IMP(FixedWeightListAllocateFunds)
16
+ ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION
17
+
18
+ public:
19
+ FixedWeightListAllocateFunds();
20
+ explicit FixedWeightListAllocateFunds(const PriceList& weights);
21
+ virtual ~FixedWeightListAllocateFunds();
22
+ virtual void _checkParam(const string& name) const override;
23
+ };
24
+
25
+ } /* namespace hku */
@@ -71,11 +71,17 @@ public:
71
71
  /** 克隆操作 */
72
72
  MoneyManagerPtr clone();
73
73
 
74
- /** 接收实际交易变化情况,一般存在多次增减仓的情况才需要重载 */
75
- virtual void buyNotify(const TradeRecord&);
74
+ /** 接收实际交易变化情况 */
75
+ void buyNotify(const TradeRecord& tr);
76
76
 
77
- /** 接收实际交易变化情况,一般存在多次增减仓的情况才需要重载 */
78
- virtual void sellNotify(const TradeRecord&);
77
+ /** 子类接收实际交易变化情况接口,一般存在多次增减仓的情况才需要重载 */
78
+ virtual void _buyNotify(const TradeRecord&) {}
79
+
80
+ /** 接收实际交易变化情况 */
81
+ void sellNotify(const TradeRecord& tr);
82
+
83
+ /** 子类接收实际交易变化情况接口,一般存在多次增减仓的情况才需要重载 */
84
+ virtual void _sellNotify(const TradeRecord&) {}
79
85
 
80
86
  /**
81
87
  * 获取指定交易对象可卖出的数量
@@ -122,6 +128,12 @@ public:
122
128
  double getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price, price_t risk,
123
129
  SystemPart from);
124
130
 
131
+ /** 当前买入交易次数, 连续买入计数,一旦接收卖出将恢复置0 */
132
+ size_t currentBuyCount(const Stock&) const;
133
+
134
+ /** 当前卖出交易次数,连续卖出计数,一旦接收买入将恢复置0 */
135
+ size_t currentSellCount(const Stock&) const;
136
+
125
137
  virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
126
138
  price_t risk, SystemPart from) = 0;
127
139
 
@@ -144,6 +156,7 @@ protected:
144
156
  string m_name;
145
157
  KQuery m_query;
146
158
  TradeManagerPtr m_tm;
159
+ unordered_map<Stock, std::pair<size_t, size_t>> m_buy_sell_counts;
147
160
 
148
161
  //============================================
149
162
  // 序列化支持
@@ -13,7 +13,9 @@
13
13
  #include "crt/MM_FixedPercent.h"
14
14
  #include "crt/MM_FixedRisk.h"
15
15
  #include "crt/MM_FixedCapital.h"
16
+ #include "crt/MM_FixedCapitalFunds.h"
16
17
  #include "crt/MM_FixedCount.h"
18
+ #include "crt/MM_FixedCountTps.h"
17
19
  #include "crt/MM_FixedUnits.h"
18
20
  #include "crt/MM_WilliamsFixedRisk.h"
19
21
 
@@ -13,6 +13,12 @@
13
13
 
14
14
  namespace hku {
15
15
 
16
+ /**
17
+ * 固定资金管理策略
18
+ * 公式: 买入数量 = 当前现金 / capital
19
+ * @param capital
20
+ * @return MoneyManagerPtr
21
+ */
16
22
  MoneyManagerPtr HKU_API MM_FixedCapital(double capital = 10000.00);
17
23
 
18
24
  } /* namespace hku */
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-02-19
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_
10
+ #define TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_
11
+
12
+ #include "../MoneyManagerBase.h"
13
+
14
+ namespace hku {
15
+
16
+ /**
17
+ * 固定资本管理策略
18
+ * 公式: 买入数量 = 当前总资产 / capital
19
+ * @param capital
20
+ * @return MoneyManagerPtr
21
+ */
22
+ MoneyManagerPtr HKU_API MM_FixedCapitalFunds(double capital = 10000.00);
23
+
24
+ } /* namespace hku */
25
+
26
+ #endif /* TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCAPITALFUNDS_H_ */
@@ -0,0 +1,27 @@
1
+ /*
2
+ * MM_FixedCapital.h
3
+ *
4
+ * Created on: 2016年5月3日
5
+ * Author: Administrator
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_
10
+ #define TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_
11
+
12
+ #include "../MoneyManagerBase.h"
13
+
14
+ namespace hku {
15
+
16
+ /**
17
+ * @brief 连续买入/卖出固定数量资金管理策略。
18
+ * @param buy_counts 依次买入数量
19
+ * @param sell_counts 依次卖出数量
20
+ * @return MoneyManagerPtr
21
+ */
22
+ MoneyManagerPtr HKU_API MM_FixedCountTps(const vector<double>& buy_counts,
23
+ const vector<double>& sell_counts);
24
+
25
+ } /* namespace hku */
26
+
27
+ #endif /* TRADE_SYS_MONEYMANAGER_CRT_MM_FIXEDCOUNT_TPS_H_ */
@@ -13,6 +13,12 @@
13
13
 
14
14
  namespace hku {
15
15
 
16
+ /**
17
+ * 固定风险资金管理策略对每笔交易限定一个预先确定的或者固定的资金风险,如每笔交易固定风险1000元。
18
+ * 公式:交易数量 = 固定风险 / 交易风险。
19
+ * @param risk
20
+ * @return MoneyManagerPtr
21
+ */
16
22
  MoneyManagerPtr HKU_API MM_FixedRisk(double risk = 1000.00);
17
23
 
18
24
  } /* namespace hku */
@@ -13,6 +13,12 @@
13
13
 
14
14
  namespace hku {
15
15
 
16
+ /**
17
+ * 固定单位资金管理策略
18
+ * 公式: 买入数量 = 当前现金 / n / 当前风险risk
19
+ * @param n
20
+ * @return MoneyManagerPtr
21
+ */
16
22
  MoneyManagerPtr HKU_API MM_FixedUnits(int n = 33);
17
23
 
18
24
  } // namespace hku
@@ -13,6 +13,13 @@
13
13
 
14
14
  namespace hku {
15
15
 
16
+ /**
17
+ * @brief 威廉斯固定风险资金管理策略
18
+ * 买入数量 =(账户余额 × 风险百分比p)÷ 最大损失(max_loss)
19
+ * @param p 风险百分比
20
+ * @param max_loss 最大损失
21
+ * @return MoneyManagerPtr
22
+ */
16
23
  MoneyManagerPtr HKU_API MM_WilliamsFixedRisk(double p = 0.1, price_t max_loss = 1000.0);
17
24
 
18
25
  } // namespace hku
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-02-19
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
10
+ #define TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
11
+
12
+ #include "../MoneyManagerBase.h"
13
+
14
+ namespace hku {
15
+
16
+ class FixedCapitalFundsMM : public MoneyManagerBase {
17
+ MONEY_MANAGER_IMP(FixedCapitalFundsMM)
18
+ MONEY_MANAGER_NO_PRIVATE_MEMBER_SERIALIZATION
19
+
20
+ public:
21
+ FixedCapitalFundsMM();
22
+ virtual ~FixedCapitalFundsMM();
23
+ virtual void _checkParam(const string& name) const override;
24
+ };
25
+
26
+ } /* namespace hku */
27
+
28
+ #endif /* TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_ */
@@ -0,0 +1,44 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-02-20
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
10
+ #define TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_
11
+
12
+ #include "../MoneyManagerBase.h"
13
+
14
+ namespace hku {
15
+
16
+ class FixedCountTpsMM : public MoneyManagerBase {
17
+ public:
18
+ FixedCountTpsMM();
19
+ FixedCountTpsMM(const vector<double>& buy_counts, const vector<double>& sell_counts);
20
+ virtual ~FixedCountTpsMM();
21
+
22
+ virtual MoneyManagerPtr _clone() override;
23
+ virtual double _getBuyNumber(const Datetime& datetime, const Stock& stock, price_t price,
24
+ price_t risk, SystemPart from) override;
25
+ virtual double _getSellNumber(const Datetime& datetime, const Stock& stock, price_t price,
26
+ price_t risk, SystemPart from) override;
27
+
28
+ private:
29
+ vector<double> m_buy_counts;
30
+ vector<double> m_sell_counts;
31
+
32
+ #if HKU_SUPPORT_SERIALIZATION
33
+ private:
34
+ friend class boost::serialization::access;
35
+ template <class Archive>
36
+ void serialize(Archive& ar, const unsigned int version) {
37
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(MoneyManagerBase);
38
+ }
39
+ #endif
40
+ };
41
+
42
+ } /* namespace hku */
43
+
44
+ #endif /* TRADE_SYS_MONEYMANAGER_IMP_FIXEDCAPITAL_FUNDS_MM_H_ */
@@ -7,6 +7,7 @@
7
7
 
8
8
  #pragma once
9
9
 
10
+ #include "crt/MF_Weight.h"
10
11
  #include "crt/MF_EqualWeight.h"
11
12
  #include "crt/MF_ICWeight.h"
12
13
  #include "crt/MF_ICIRWeight.h"
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-03-13
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #include "../MultiFactorBase.h"
10
+
11
+ namespace hku {
12
+
13
+ /**
14
+ * @brief 指定权重合成因子 = ind1 * w1 + ind2 * w2 + ... + indn * wn
15
+ * @param inds 原始因子列表
16
+ * @param weights 权重列表
17
+ * @param stks 计算证券列表
18
+ * @param query 日期范围
19
+ * @param ref_stk 参考证券
20
+ * @param ic_n 默认 IC 对应的 N 日收益率
21
+ * @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
22
+ * @return MultiFactorPtr
23
+ */
24
+ MultiFactorPtr HKU_API MF_Weight(const IndicatorList& inds, const PriceList& weights,
25
+ const StockList& stks, const KQuery& query, const Stock& ref_stk,
26
+ int ic_n = 5, bool spearman = true);
27
+
28
+ MultiFactorPtr HKU_API MF_Weight();
29
+
30
+ } // namespace hku
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Copyright (c) 2024 hikyuu.org
3
+ *
4
+ * Created on: 2024-03-13
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "../MultiFactorBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 指定指标权重评分板,证券得分为其个指标的权重之和
16
+ */
17
+ class WeightMultiFactor : public MultiFactorBase {
18
+ MULTIFACTOR_IMP(WeightMultiFactor)
19
+
20
+ public:
21
+ WeightMultiFactor();
22
+ WeightMultiFactor(const vector<Indicator>& inds, const PriceList& weights,
23
+ const StockList& stks, const KQuery& query, const Stock& ref_stk, int ic_n,
24
+ bool spearman);
25
+ virtual ~WeightMultiFactor() = default;
26
+
27
+ private:
28
+ PriceList m_weights; // 每个指标权重,与输入 inds 列表等长
29
+
30
+ #if HKU_SUPPORT_SERIALIZATION
31
+ private:
32
+ friend class boost::serialization::access;
33
+ template <class Archive>
34
+ void serialize(Archive& ar, const unsigned int version) {
35
+ ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(MultiFactorBase);
36
+ ar& BOOST_SERIALIZATION_NVP(m_weights);
37
+ }
38
+ #endif
39
+ };
40
+
41
+ } // namespace hku
@@ -33,11 +33,13 @@ public:
33
33
 
34
34
  /**
35
35
  * @brief 构造函数
36
+ * @param name 组合名称
36
37
  * @param tm 账户
37
38
  * @param se 选择器
38
39
  * @param af 资产分配算法
39
40
  */
40
- Portfolio(const TradeManagerPtr& tm, const SelectorPtr& se, const AFPtr& af);
41
+ Portfolio(const string& name, const TradeManagerPtr& tm, const SelectorPtr& se,
42
+ const AFPtr& af);
41
43
 
42
44
  /** 析构函数 */
43
45
  virtual ~Portfolio();
@@ -50,28 +52,10 @@ public:
50
52
 
51
53
  /**
52
54
  * @brief 运行资产组合
53
- * @details
54
- * <pre>
55
- * 调仓模式 adjust_mode 说明:
56
- * - "query" 模式,跟随输入参数 query 中的 ktype,此时 adjust_cycle 为以 query 中的 ktype
57
- * 决定周期间隔;
58
- * - "day" 模式,adjust_cycle 为调仓间隔天数
59
- * - "week" | "month" | "quarter" | "year" 模式时,adjust_cycle
60
- * 为对应的每周第N日、每月第n日、每季度第n日、每年第n日,在 delay_to_trading_day 为 false 时
61
- * 如果当日不是交易日将会被跳过调仓;当 delay_to_trading_day 为 true时,如果当日不是交易日
62
- * 将会顺延至当前周期内的第一个交易日,如指定每月第1日调仓,但当月1日不是交易日,则将顺延至当月
63
- * 的第一个交易日
64
- * </pre>
65
- * @note
66
- * 由于各个组件可能存在参数变化的情况,无法自动感知判断是否需要重新计算,此时需要手工指定强制计算
67
55
  * @param query 查询条件, 其 KType 必须为 KQuery::DAY
68
- * @param adjust_cycle 调仓周期(受 adjust_mode 影响), 默认为1
69
56
  * @param force 是否强制重计算
70
- * @param adjust_mode 调仓模式 "query" | "day" | "week" | "month" | "year"
71
- * @param delay_to_trading_day true 时,如果当日不是交易日将会被顺延至当前周期内的第一个交易日
72
57
  */
73
- void run(const KQuery& query, int adjust_cycle = 1, bool force = false,
74
- const string& adjust_mode = "query", bool delay_to_trading_day = true);
58
+ void run(const KQuery& query, bool force = false);
75
59
 
76
60
  /** 修改查询条件 */
77
61
  void setQuery(const KQuery& query);
@@ -97,33 +81,43 @@ public:
97
81
  /** 设置资产分配算法 */
98
82
  void setAF(const AFPtr& af);
99
83
 
84
+ const SystemList& getRealSystemList() const;
85
+
100
86
  /** 复位操作 */
101
87
  void reset();
102
88
 
89
+ /** 克隆操作 */
103
90
  typedef shared_ptr<Portfolio> PortfolioPtr;
91
+ PortfolioPtr clone() const;
104
92
 
105
- /** 克隆操作 */
106
- PortfolioPtr clone();
93
+ /** 运行前准备 */
94
+ void readyForRun();
107
95
 
108
- /** 获取所有原型系统列表,与 SE */
109
- const SystemList& getSystemList() const;
96
+ void runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust);
110
97
 
111
- /** 获取所有实际运行的系统列表,与 SE 同 */
112
- const SystemList& getRealSystemList() const;
98
+ /** 用于打印输出 */
99
+ virtual string str() const;
113
100
 
114
- private:
115
- void initParam();
101
+ virtual void _reset() {}
102
+ virtual PortfolioPtr _clone() const {
103
+ return std::make_shared<Portfolio>();
104
+ }
116
105
 
117
- /** 运行前准备 */
118
- void _readyForRun();
106
+ virtual void _readyForRun() {}
107
+ virtual void _runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust) {}
119
108
 
120
- void _runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust);
109
+ private:
110
+ void initParam();
121
111
 
122
112
  void _runOnMode(const DatetimeList& datelist, int adjust_cycle, const string& mode);
123
113
 
124
114
  void _runOnModeDelayToTradingDay(const DatetimeList& datelist, int adjust_cycle,
125
115
  const string& mode);
126
116
 
117
+ protected:
118
+ // 跟踪打印当前TM持仓情况
119
+ void traceMomentTM(const Datetime& date);
120
+
127
121
  protected:
128
122
  string m_name;
129
123
  TMPtr m_tm;
@@ -138,10 +132,6 @@ protected:
138
132
 
139
133
  // 用于中间计算的临时数据
140
134
  std::unordered_set<SYSPtr> m_running_sys_set;
141
- SystemList m_dlist_sys_list; // 因证券退市,无法执行买入的系统(资产全部损失)
142
- SystemWeightList m_delay_adjust_sys_list; // 延迟调仓卖出的系统列表
143
- SystemWeightList m_tmp_selected_list;
144
- SystemWeightList m_tmp_will_remove_sys;
145
135
 
146
136
  //============================================
147
137
  // 序列化支持
@@ -158,7 +148,6 @@ private:
158
148
  ar& BOOST_SERIALIZATION_NVP(m_se);
159
149
  ar& BOOST_SERIALIZATION_NVP(m_af);
160
150
  ar& BOOST_SERIALIZATION_NVP(m_query);
161
- ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
162
151
  }
163
152
 
164
153
  template <class Archive>
@@ -170,13 +159,25 @@ private:
170
159
  ar& BOOST_SERIALIZATION_NVP(m_se);
171
160
  ar& BOOST_SERIALIZATION_NVP(m_af);
172
161
  ar& BOOST_SERIALIZATION_NVP(m_query);
173
- ar& BOOST_SERIALIZATION_NVP(m_need_calculate);
174
162
  }
175
163
 
176
164
  BOOST_SERIALIZATION_SPLIT_MEMBER()
177
165
  #endif /* HKU_SUPPORT_SERIALIZATION */
178
166
  };
179
167
 
168
+ #if HKU_SUPPORT_SERIALIZATION
169
+ BOOST_SERIALIZATION_ASSUME_ABSTRACT(Portfolio)
170
+ #endif
171
+
172
+ #define PORTFOLIO_IMP(classname) \
173
+ public: \
174
+ virtual PortfolioPtr _clone() const override { \
175
+ return std::make_shared<classname>(); \
176
+ } \
177
+ virtual void _reset() override; \
178
+ virtual void _readyForRun() override; \
179
+ virtual void _runMoment(const Datetime& date, const Datetime& nextCycle, bool adjust) override;
180
+
180
181
  /**
181
182
  * 客户程序都应使用该指针类型
182
183
  * @ingroup Selector
@@ -10,5 +10,6 @@
10
10
  #define TRADE_SYS_PORTFOLIO_BUILD_IN_H_
11
11
 
12
12
  #include "crt/PF_Simple.h"
13
+ #include "crt/PF_WithoutAF.h"
13
14
 
14
15
  #endif /* TRADE_SYS_PORTFOLIO_BUILD_IN_H_ */
@@ -15,8 +15,32 @@
15
15
 
16
16
  namespace hku {
17
17
 
18
+ /**
19
+ * @brief 创建资产组合
20
+ * @details
21
+ * <pre>
22
+ * 调仓模式 adjust_mode 说明:
23
+ * - "query" 模式,跟随输入参数 query 中的 ktype,此时 adjust_cycle 为以 query 中的 ktype
24
+ * 决定周期间隔;
25
+ * - "day" 模式,adjust_cycle 为调仓间隔天数
26
+ * - "week" | "month" | "quarter" | "year" 模式时,adjust_cycle
27
+ * 为对应的每周第N日、每月第n日、每季度第n日、每年第n日,在 delay_to_trading_day 为 false 时
28
+ * 如果当日不是交易日将会被跳过调仓;当 delay_to_trading_day 为 true时,如果当日不是交易日
29
+ * 将会顺延至当前周期内的第一个交易日,如指定每月第1日调仓,但当月1日不是交易日,则将顺延至当月
30
+ * 的第一个交易日
31
+ * </pre>
32
+ * @param tm 交易账户
33
+ * @param se 系统选择器
34
+ * @param af 资金分配算法
35
+ * @param adjust_cycle 调仓周期(受 adjust_mode 影响), 默认为1
36
+ * @param adjust_mode 调仓模式 "query" | "day" | "week" | "month" | "year"
37
+ * @param delay_to_trading_day true 时,如果调仓日不是交易日将会被顺延至当前周期内的第一个交易日
38
+ * @return 组合实例
39
+ */
18
40
  PortfolioPtr HKU_API PF_Simple(const TMPtr& tm = TradeManagerPtr(), const SEPtr& se = SE_Fixed(),
19
- const AFPtr& af = AF_EqualWeight());
41
+ const AFPtr& af = AF_EqualWeight(), int adjust_cycle = 1,
42
+ const string& adjust_mode = "query",
43
+ bool delay_to_trading_day = true);
20
44
 
21
45
  } /* namespace hku */
22
46
 
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-02-18
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef TRADE_SYS_PORTFOLIO_IMP_PF_WITHOUTAF_H_
10
+ #define TRADE_SYS_PORTFOLIO_IMP_PF_WITHOUTAF_H_
11
+
12
+ #include "../Portfolio.h"
13
+ #include "../../selector/crt/SE_Fixed.h"
14
+ #include "../../allocatefunds/crt/AF_EqualWeight.h"
15
+
16
+ namespace hku {
17
+
18
+ /**
19
+ * @brief 无资金分配算法的投资组合
20
+ * @details
21
+ * <pre>
22
+ * 调仓模式 adjust_mode 说明:
23
+ * - "query" 模式,跟随输入参数 query 中的 ktype,此时 adjust_cycle 为以 query 中的 ktype
24
+ * 决定周期间隔;
25
+ * - "day" 模式,adjust_cycle 为调仓间隔天数
26
+ * - "week" | "month" | "quarter" | "year" 模式时,adjust_cycle
27
+ * 为对应的每周第N日、每月第n日、每季度第n日、每年第n日,在 delay_to_trading_day 为 false 时
28
+ * 如果当日不是交易日将会被跳过调仓;当 delay_to_trading_day 为 true时,如果当日不是交易日
29
+ * 将会顺延至当前周期内的第一个交易日,如指定每月第1日调仓,但当月1日不是交易日,则将顺延至当月
30
+ * 的第一个交易日
31
+ * </pre>
32
+ * @note 无资金分配算法模式下,仅支持全部在开盘时买卖或全部在收盘时买卖!
33
+ * @param tm 交易账户
34
+ * @param se 系统选择器
35
+ * @param adjust_cycle 调仓周期(受 adjust_mode 影响), 默认为1
36
+ * @param adjust_mode 调仓模式 "query" | "day" | "week" | "month" | "year"
37
+ * @param delay_to_trading_day true 时,如果当日不是交易日将会被顺延至当前周期内的第一个交易日
38
+ * @param trade_on_close 在收盘时执行交易
39
+ * @param sys_use_self_tm 使用原型系统自身交易账户进行计算(仅在无资金分配模式下有效),默认 false
40
+ * @param sell_at_not_selected 调仓日未选中的股票是否强制卖出,默认 false
41
+ * @return 组合实例
42
+ */
43
+ PortfolioPtr HKU_API PF_WithoutAF(const TMPtr& tm = TradeManagerPtr(), const SEPtr& se = SE_Fixed(),
44
+ int adjust_cycle = 1, const string& adjust_mode = "query",
45
+ bool delay_to_trading_day = true, bool trade_on_close = true,
46
+ bool sys_use_self_tm = false, bool sell_at_not_selected = false);
47
+
48
+ } /* namespace hku */
49
+
50
+ #endif /* TRADE_SYS_PORTFOLIO_IMP_PF_WITHOUTAF_H_ */
@@ -0,0 +1,53 @@
1
+ /*
2
+ * SimplePortfolio.h
3
+ *
4
+ * Created on: 2016年2月21日
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #ifndef TRADE_SYS_PORTFOLIO_SIMPLE_H_
11
+ #define TRADE_SYS_PORTFOLIO_SIMPLE_H_
12
+
13
+ #include "hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h"
14
+ #include "hikyuu/trade_sys/selector/SelectorBase.h"
15
+ #include "hikyuu/trade_sys/portfolio/Portfolio.h"
16
+
17
+ namespace hku {
18
+
19
+ /*
20
+ * 资产组合
21
+ * @ingroup SimplePortfolio
22
+ */
23
+ class HKU_API SimplePortfolio : public Portfolio {
24
+ PORTFOLIO_IMP(SimplePortfolio)
25
+
26
+ public:
27
+ SimplePortfolio();
28
+ SimplePortfolio(const TradeManagerPtr& tm, const SelectorPtr& se, const AFPtr& af);
29
+ virtual ~SimplePortfolio();
30
+
31
+ private:
32
+ SystemList m_dlist_sys_list; // 因证券退市,无法执行卖出的系统(资产全部损失)
33
+ SystemWeightList m_delay_adjust_sys_list; // 延迟调仓卖出的系统列表
34
+ SystemWeightList m_tmp_selected_list;
35
+ SystemWeightList m_tmp_will_remove_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(Portfolio);
46
+ }
47
+
48
+ #endif /* HKU_SUPPORT_SERIALIZATION */
49
+ };
50
+
51
+ } /* namespace hku */
52
+
53
+ #endif /* TRADE_SYS_PORTFOLIO_SIMPLE_H_ */