hikyuu 2.5.2__py3-none-win_amd64.whl → 2.5.5__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 (90) hide show
  1. hikyuu/__init__.py +5 -1
  2. hikyuu/__init__.pyi +522 -511
  3. hikyuu/analysis/__init__.pyi +490 -485
  4. hikyuu/analysis/analysis.pyi +491 -486
  5. hikyuu/core.pyi +492 -487
  6. hikyuu/cpp/__init__.pyi +2 -2
  7. hikyuu/cpp/core310.pyd +0 -0
  8. hikyuu/cpp/core310.pyi +249 -26
  9. hikyuu/cpp/core311.pyd +0 -0
  10. hikyuu/cpp/core311.pyi +249 -26
  11. hikyuu/cpp/core312.pyd +0 -0
  12. hikyuu/cpp/core312.pyi +249 -26
  13. hikyuu/cpp/core313.pyd +0 -0
  14. hikyuu/cpp/core313.pyi +243 -26
  15. hikyuu/cpp/core38.pyd +0 -0
  16. hikyuu/cpp/core38.pyi +249 -26
  17. hikyuu/cpp/core39.pyd +0 -0
  18. hikyuu/cpp/core39.pyi +249 -26
  19. hikyuu/cpp/hikyuu.dll +0 -0
  20. hikyuu/cpp/hikyuu.lib +0 -0
  21. hikyuu/data/mysql_upgrade/0027.sql +6 -0
  22. hikyuu/data/pytdx_to_h5.py +7 -4
  23. hikyuu/data/pytdx_to_mysql.py +7 -4
  24. hikyuu/data/sqlite_upgrade/0027.sql +8 -0
  25. hikyuu/draw/drawplot/__init__.py +8 -1
  26. hikyuu/draw/drawplot/__init__.pyi +11 -7
  27. hikyuu/draw/drawplot/bokeh_draw.pyi +509 -500
  28. hikyuu/draw/drawplot/common.pyi +1 -1
  29. hikyuu/draw/drawplot/echarts_draw.pyi +511 -502
  30. hikyuu/draw/drawplot/matplotlib_draw.py +129 -8
  31. hikyuu/draw/drawplot/matplotlib_draw.pyi +571 -515
  32. hikyuu/draw/elder.pyi +11 -11
  33. hikyuu/draw/kaufman.pyi +18 -18
  34. hikyuu/draw/volume.pyi +10 -10
  35. hikyuu/extend.pyi +501 -495
  36. hikyuu/fetcher/stock/zh_block_em.py +18 -7
  37. hikyuu/hub.py +112 -6
  38. hikyuu/hub.pyi +39 -13
  39. hikyuu/include/hikyuu/DataType.h +1 -2
  40. hikyuu/include/hikyuu/StockManager.h +2 -1
  41. hikyuu/include/hikyuu/StrategyContext.h +12 -3
  42. hikyuu/include/hikyuu/indicator/Indicator.h +24 -0
  43. hikyuu/include/hikyuu/indicator/Indicator2InImp.h +1 -0
  44. hikyuu/include/hikyuu/indicator/build_in.h +2 -0
  45. hikyuu/include/hikyuu/indicator/crt/ATR.h +2 -13
  46. hikyuu/include/hikyuu/indicator/crt/BARSSINCE.h +14 -2
  47. hikyuu/include/hikyuu/indicator/crt/KALMAN.h +30 -0
  48. hikyuu/include/hikyuu/indicator/crt/TR.h +32 -0
  49. hikyuu/include/hikyuu/indicator/imp/IAtr.h +3 -1
  50. hikyuu/include/hikyuu/indicator/imp/IBarsSince.h +6 -0
  51. hikyuu/include/hikyuu/indicator/imp/IKalman.h +27 -0
  52. hikyuu/include/hikyuu/indicator/imp/ITr.h +35 -0
  53. hikyuu/include/hikyuu/python/convert_any.h +299 -0
  54. hikyuu/include/hikyuu/trade_manage/PositionRecord.h +5 -4
  55. hikyuu/include/hikyuu/trade_sys/allocatefunds/crt/AF_MultiFactor.h +1 -1
  56. hikyuu/include/hikyuu/trade_sys/allocatefunds/imp/MultiFactorAllocaterFunds.h +3 -0
  57. hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +4 -1
  58. hikyuu/include/hikyuu/trade_sys/condition/imp/{SubCondition.h → logic/SubCondition.h} +1 -1
  59. hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +20 -6
  60. hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
  61. hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Logic.h +35 -0
  62. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/AddEnvironment.h +42 -0
  63. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/AndEnvironment.h +42 -0
  64. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/DivEnvironment.h +42 -0
  65. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/MultiEnvironment.h +42 -0
  66. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/OrEnvironment.h +42 -0
  67. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/SubEnvironment.h +42 -0
  68. hikyuu/include/hikyuu/trade_sys/environment/imp/logic/__init__.py +1 -0
  69. hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +0 -4
  70. hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Logic.h +68 -7
  71. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/AndSignal.h +19 -0
  72. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorSignal.h +1 -0
  73. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OperatorValueSignal.h +1 -0
  74. hikyuu/include/hikyuu/trade_sys/signal/imp/logic/OrSignal.h +19 -0
  75. hikyuu/include/hikyuu/utilities/datetime/Datetime.h +2 -1
  76. hikyuu/include/hikyuu/version.h +4 -4
  77. hikyuu/indicator/indicator.py +1 -0
  78. hikyuu/trade_manage/__init__.pyi +506 -499
  79. hikyuu/trade_manage/broker.pyi +3 -3
  80. hikyuu/trade_manage/broker_easytrader.pyi +1 -1
  81. hikyuu/trade_manage/trade.pyi +506 -499
  82. hikyuu/trade_sys/trade_sys.py +4 -3
  83. hikyuu/util/__init__.pyi +1 -1
  84. hikyuu/util/singleton.pyi +1 -1
  85. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/METADATA +3 -2
  86. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/RECORD +90 -73
  87. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/top_level.txt +1 -0
  88. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/LICENSE +0 -0
  89. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/WHEEL +0 -0
  90. {hikyuu-2.5.2.dist-info → hikyuu-2.5.5.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,32 @@
1
+ /*
2
+ * TRG.h
3
+ *
4
+ * Created on: 2019年3月6日
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef INDICATOR_CRT_TR_H_
10
+ #define INDICATOR_CRT_TR_H_
11
+
12
+ #include "../Indicator.h"
13
+
14
+ namespace hku {
15
+
16
+ /**
17
+ * @brief 真实波动幅度(TR)
18
+ * @details
19
+ * <pre>
20
+ * 真实波动幅度(TR)是以下三个值中的最大值:
21
+ * 1. 当前周期最高价(H)与最低价(L)之差
22
+ * 2. 当前周期最高价与前一周期收盘价(PC)之差的绝对值
23
+ * 3. 当前周期最低价与前一周期收盘价之差的绝对值
24
+ * </pre>
25
+ * @ingroup Indicator
26
+ */
27
+ Indicator HKU_API TR();
28
+ Indicator HKU_API TR(const KData&);
29
+
30
+ } // namespace hku
31
+
32
+ #endif /* INDICATOR_CRT_TR_H_ */
@@ -14,11 +14,13 @@
14
14
  namespace hku {
15
15
 
16
16
  class IAtr : public IndicatorImp {
17
- INDICATOR_IMP_SUPPORT_DYNAMIC_STEP(IAtr)
17
+ INDICATOR_IMP(IAtr)
18
+ INDICATOR_NEED_CONTEXT
18
19
  INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
19
20
 
20
21
  public:
21
22
  IAtr();
23
+ explicit IAtr(const KData&, int n);
22
24
  virtual ~IAtr();
23
25
  virtual void _checkParam(const string& name) const override;
24
26
  };
@@ -15,6 +15,11 @@
15
15
 
16
16
  namespace hku {
17
17
 
18
+ /*
19
+ * N周期内首个条件成立位置, N为0时,为整个序列
20
+ * 用法:BARSSINCEN(X,N):N周期内第一次X不为0到现在的周期数,N为常量BARSSINCEN(X,N):
21
+ * 例如:BARSSINCEN(HIGH>10,10)表示10个周期内股价超过10元时到当前的周期数
22
+ */
18
23
  class IBarsSince : public IndicatorImp {
19
24
  INDICATOR_IMP(IBarsSince)
20
25
  INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
@@ -22,6 +27,7 @@ class IBarsSince : public IndicatorImp {
22
27
  public:
23
28
  IBarsSince();
24
29
  virtual ~IBarsSince();
30
+ virtual void _checkParam(const string& name) const override;
25
31
  };
26
32
 
27
33
  } /* namespace hku */
@@ -0,0 +1,27 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-03-02
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef INDICATOR_IMP_IKALMAN_H_
10
+ #define INDICATOR_IMP_IKALMAN_H_
11
+
12
+ #include "../Indicator.h"
13
+
14
+ namespace hku {
15
+
16
+ /* kalman滤波 */
17
+ class IKalman : public IndicatorImp {
18
+ INDICATOR_IMP(IKalman)
19
+ INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
20
+
21
+ public:
22
+ IKalman();
23
+ virtual ~IKalman();
24
+ };
25
+
26
+ } /* namespace hku */
27
+ #endif /* INDICATOR_IMP_IKALMAN_H_ */
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-03-05
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef INDICATOR_IMP_ITR_H_
10
+ #define INDICATOR_IMP_ITR_H_
11
+
12
+ #include "../Indicator.h"
13
+
14
+ namespace hku {
15
+
16
+ /*
17
+ * 真实波动幅度(TR)是以下三个值中的最大值:
18
+ * 1. 当前周期最高价与最低价之差
19
+ * 2. 当前周期最高价与前一周期收盘价之差的绝对值
20
+ * 3. 当前周期最低价与前一周期收盘价之差的绝对值
21
+ */
22
+ class ITr : public IndicatorImp {
23
+ INDICATOR_IMP(ITr)
24
+ INDICATOR_NEED_CONTEXT
25
+ INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
26
+
27
+ public:
28
+ ITr();
29
+ explicit ITr(const KData&);
30
+ virtual ~ITr();
31
+ };
32
+
33
+ } /* namespace hku */
34
+
35
+ #endif /* INDICATOR_IMP_ITR_H_ */
@@ -0,0 +1,299 @@
1
+ /*
2
+ * Copyright (c) 2019 hikyuu.org
3
+ *
4
+ * Created on: 2020-5-24
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+ #ifndef HIKYUU_PYTHON_CONVERT_ANY_H
10
+ #define HIKYUU_PYTHON_CONVERT_ANY_H
11
+
12
+ #include <string>
13
+ #include <pybind11/pybind11.h>
14
+ #include <pybind11/eval.h>
15
+ #include <hikyuu/hikyuu.h>
16
+ #include <datetime.h>
17
+ #include "bind_stl.h"
18
+
19
+ using namespace hku;
20
+
21
+ inline Datetime pydatetime_to_Datetime(const pybind11::object& source) {
22
+ Datetime value;
23
+ if (source.is_none()) {
24
+ return value;
25
+ }
26
+
27
+ if (pybind11::isinstance<Datetime>(source)) {
28
+ value = source.cast<Datetime>();
29
+ return value;
30
+ }
31
+
32
+ if (!PyDateTimeAPI) {
33
+ PyDateTime_IMPORT;
34
+ }
35
+
36
+ PyObject* src = source.ptr();
37
+
38
+ long year = 0, month = 0, day = 0, hour = 0, minute = 0, second = 0, microsecond = 0;
39
+ if (PyDateTime_Check(src)) {
40
+ second = PyDateTime_DATE_GET_SECOND(src);
41
+ minute = PyDateTime_DATE_GET_MINUTE(src);
42
+ hour = PyDateTime_DATE_GET_HOUR(src);
43
+ day = PyDateTime_GET_DAY(src);
44
+ month = PyDateTime_GET_MONTH(src);
45
+ year = PyDateTime_GET_YEAR(src);
46
+ microsecond = PyDateTime_DATE_GET_MICROSECOND(src);
47
+
48
+ } else if (PyDate_Check(src)) {
49
+ day = PyDateTime_GET_DAY(src);
50
+ month = PyDateTime_GET_MONTH(src);
51
+ year = PyDateTime_GET_YEAR(src);
52
+
53
+ } else if (PyTime_Check(src)) {
54
+ second = PyDateTime_TIME_GET_SECOND(src);
55
+ minute = PyDateTime_TIME_GET_MINUTE(src);
56
+ hour = PyDateTime_TIME_GET_HOUR(src);
57
+ day = 1; // This date (day, month, year) = (1, 0, 70)
58
+ month = 1; // represents 1-Jan-1940, which is the first
59
+ year = 1400; // earliest available date for Datetime, not Python datetime
60
+ microsecond = PyDateTime_TIME_GET_MICROSECOND(src);
61
+
62
+ } else {
63
+ throw std::invalid_argument("Can't convert this python object to Datetime!");
64
+ }
65
+
66
+ // Datetime 最小只到 1400年 1 月 1日,最大只到 9999 年 12月 31 日 0点
67
+ if (year < 1400) {
68
+ value = Datetime::min();
69
+ } else if (Datetime(year, month, day) == Datetime::max()) {
70
+ value = Datetime::max();
71
+ } else {
72
+ long millisecond = microsecond / 1000;
73
+ microsecond = microsecond - millisecond * 1000;
74
+ value = Datetime(year, month, day, hour, minute, second, millisecond, microsecond);
75
+ }
76
+
77
+ return value;
78
+ }
79
+
80
+ namespace pybind11 {
81
+ namespace detail {
82
+ template <>
83
+ struct type_caster<boost::any> {
84
+ public:
85
+ PYBIND11_TYPE_CASTER(boost::any, _("any"));
86
+
87
+ /**
88
+ * Conversion part 1 (Python->C++)
89
+ */
90
+ bool load(handle source, bool) {
91
+ if (source.is_none()) {
92
+ return false;
93
+ }
94
+
95
+ /* Extract PyObject from handle */
96
+ PyObject* src = source.ptr();
97
+
98
+ object obj = reinterpret_borrow<object>(source);
99
+ if (PyBool_Check(src)) {
100
+ // value = bool(PyLong_AsLong(src));
101
+ bool tmp = obj.cast<bool>();
102
+ value = tmp;
103
+ return true;
104
+ }
105
+
106
+ if (PyLong_Check(src)) {
107
+ int overflow;
108
+ long tmp = PyLong_AsLongAndOverflow(src, &overflow);
109
+ if (overflow == 0) {
110
+ value = static_cast<int>(tmp);
111
+ } else {
112
+ value = PyLong_AsLongLong(src);
113
+ }
114
+ return true;
115
+ }
116
+
117
+ if (PyFloat_Check(src)) {
118
+ value = PyFloat_AsDouble(src);
119
+ return true;
120
+ }
121
+
122
+ if (PyUnicode_Check(src)) {
123
+ object temp = reinterpret_borrow<object>(PyUnicode_AsUTF8String(src));
124
+ if (!temp)
125
+ pybind11_fail("Unable to extract string contents! (encoding issue)");
126
+ char* buffer;
127
+ ssize_t length;
128
+ if (PYBIND11_BYTES_AS_STRING_AND_SIZE(temp.ptr(), &buffer, &length))
129
+ pybind11_fail("Unable to extract string contents! (invalid type)");
130
+ value = std::string(buffer, (size_t)length);
131
+ return true;
132
+ }
133
+
134
+ if (isinstance<Stock>(obj)) {
135
+ value = obj.cast<Stock>();
136
+ return true;
137
+
138
+ } else if (isinstance<Block>(obj)) {
139
+ value = obj.cast<Block>();
140
+ return true;
141
+
142
+ } else if (isinstance<KQuery>(obj)) {
143
+ value = obj.cast<KQuery>();
144
+ return true;
145
+
146
+ } else if (isinstance<KData>(obj)) {
147
+ value = obj.cast<KData>();
148
+ return true;
149
+
150
+ } else if (isinstance<sequence>(obj)) {
151
+ sequence pyseq = obj.cast<sequence>();
152
+ size_t total = pyseq.size();
153
+ HKU_CHECK(total > 0, "Can't support empty sequence!");
154
+ if (isinstance<Datetime>(pyseq[0])) {
155
+ std::vector<Datetime> vect(total);
156
+ for (size_t i = 0; i < total; i++) {
157
+ vect[i] = pyseq[i].cast<Datetime>();
158
+ }
159
+ value = vect;
160
+
161
+ } else if (PyFloat_Check(pyseq[0].ptr()) || PyLong_Check(pyseq[0].ptr())) {
162
+ std::vector<price_t> vect(total);
163
+ for (size_t i = 0; i < total; i++) {
164
+ vect[i] = pyseq[i].cast<price_t>();
165
+ }
166
+ value = vect;
167
+
168
+ } else {
169
+ // 尝试 python 原生 datetime 的转换
170
+ std::vector<Datetime> vect(total);
171
+ for (size_t i = 0; i < total; i++) {
172
+ vect[i] = pydatetime_to_Datetime(pyseq[i]);
173
+ }
174
+ value = vect;
175
+ }
176
+ return true;
177
+ }
178
+
179
+ HKU_THROW_EXCEPTION(std::logic_error,
180
+ "Faile convert this value to boost::any, it may be not supported!");
181
+ return false;
182
+ }
183
+
184
+ /**
185
+ * Conversion part 2 (C++ -> Python)
186
+ */
187
+ static handle cast(boost::any x, return_value_policy /* policy */, handle /* parent */) {
188
+ if (x.type() == typeid(bool)) {
189
+ bool tmp = boost::any_cast<bool>(x);
190
+ if (tmp) {
191
+ Py_RETURN_TRUE;
192
+ } else {
193
+ Py_RETURN_FALSE;
194
+ }
195
+ } else if (x.type() == typeid(int)) {
196
+ return Py_BuildValue("n", boost::any_cast<int>(x));
197
+ } else if (x.type() == typeid(double)) {
198
+ return Py_BuildValue("d", boost::any_cast<double>(x));
199
+ } else if (x.type() == typeid(std::string)) {
200
+ std::string s(boost::any_cast<std::string>(x));
201
+ return Py_BuildValue("s", s.c_str());
202
+
203
+ } else if (x.type() == typeid(KData)) {
204
+ const KData& k = boost::any_cast<KData>(x);
205
+ std::stringstream cmd;
206
+ if (k == Null<KData>()) {
207
+ cmd << "KData()";
208
+ } else {
209
+ auto stk = k.getStock();
210
+ auto query = k.getQuery();
211
+ std::stringstream q_cmd;
212
+ if (query.queryType() == KQuery::INDEX) {
213
+ q_cmd << "Query(" << query.start() << "," << query.end() << ", Query."
214
+ << KQuery::getKTypeName(query.kType()) << ", Query."
215
+ << KQuery::getRecoverTypeName(query.recoverType()) << ")";
216
+ } else {
217
+ q_cmd << "Query(Datetime('" << query.startDatetime() << "'), Datetime('"
218
+ << query.endDatetime() << "'), " << "Query."
219
+ << KQuery::getKTypeName(query.kType()) << ", Query."
220
+ << KQuery::getRecoverTypeName(query.recoverType()) << ")";
221
+ }
222
+ cmd << "KData(get_stock('" << stk.market_code() << "'), " << q_cmd.str() << ")";
223
+ }
224
+ object o = eval(cmd.str());
225
+ o.inc_ref();
226
+ return o;
227
+
228
+ } else if (x.type() == typeid(Stock)) {
229
+ const Stock& stk = boost::any_cast<Stock>(x);
230
+ std::stringstream cmd;
231
+ if (stk.isNull()) {
232
+ cmd << "Stock()";
233
+ } else {
234
+ cmd << "get_stock('" << stk.market_code() << "')";
235
+ }
236
+ object o = eval(cmd.str());
237
+ o.inc_ref();
238
+ return o;
239
+
240
+ } else if (x.type() == typeid(Block)) {
241
+ const Block& blk = boost::any_cast<const Block&>(x);
242
+ std::stringstream cmd;
243
+ object o;
244
+ if (blk == Null<Block>()) {
245
+ cmd << "Block()";
246
+ o = eval(cmd.str());
247
+ o.inc_ref();
248
+ } else {
249
+ cmd << "Block('" << blk.category() << "','" << blk.name() << "')";
250
+ o = eval(cmd.str());
251
+ o.inc_ref();
252
+ Block out = o.cast<Block>();
253
+ out.add(blk.getStockList());
254
+ }
255
+ return o;
256
+
257
+ } else if (x.type() == typeid(KQuery)) {
258
+ const KQuery& query = boost::any_cast<KQuery>(x);
259
+ std::stringstream cmd;
260
+ if (query.queryType() == KQuery::INDEX) {
261
+ cmd << "Query(" << query.start() << "," << query.end() << ", Query."
262
+ << KQuery::getKTypeName(query.kType()) << ", Query."
263
+ << KQuery::getRecoverTypeName(query.recoverType()) << ")";
264
+ } else {
265
+ cmd << "Query(Datetime('" << query.startDatetime() << "'), Datetime('"
266
+ << query.endDatetime() << "'), " << "Query."
267
+ << KQuery::getKTypeName(query.kType()) << ", Query."
268
+ << KQuery::getRecoverTypeName(query.recoverType()) << ")";
269
+ }
270
+ object o = eval(cmd.str());
271
+ o.inc_ref();
272
+ return o;
273
+
274
+ } else if (x.type() == typeid(PriceList)) {
275
+ PriceList price_list = boost::any_cast<PriceList>(x);
276
+ list o;
277
+ for (auto iter = price_list.begin(); iter != price_list.end(); ++iter) {
278
+ o.append(*iter);
279
+ }
280
+ o.inc_ref();
281
+ return o;
282
+
283
+ } else if (x.type() == typeid(DatetimeList)) {
284
+ const DatetimeList& date_list = boost::any_cast<DatetimeList>(x);
285
+ list o;
286
+ for (auto iter = date_list.begin(); iter != date_list.end(); ++iter) {
287
+ o.append(*iter);
288
+ }
289
+ o.inc_ref();
290
+ return o;
291
+ }
292
+
293
+ HKU_THROW_EXCEPTION(std::runtime_error, "convert failed! Unkown type!!");
294
+ }
295
+ };
296
+ } // namespace detail
297
+ } // namespace pybind11
298
+
299
+ #endif /* HIKYUU_PYTHON_CONVERT_ANY_H */
@@ -28,10 +28,11 @@ public:
28
28
  /** 仅用于python的__str__ */
29
29
  string str() const;
30
30
 
31
- /** 盈利 = 买入资金 - 累计交易总成本 - 卖出资金 */
32
- price_t totalProfit() const {
33
- return buyMoney - totalCost - sellMoney;
34
- }
31
+ /**
32
+ * @brief 盈亏 = 买入资金 - 累计交易总成本 - 卖出资金
33
+ * @note 只对已清仓的记录有效,未清仓将返回0.0
34
+ */
35
+ price_t totalProfit() const;
35
36
 
36
37
  Stock stock; ///< 交易对象
37
38
  Datetime takeDatetime; ///< 初次建仓日期
@@ -12,7 +12,7 @@
12
12
  namespace hku {
13
13
 
14
14
  /**
15
- * 创建 MultiFactor 评分权重的资产分配算法实例
15
+ * 创建 MultiFactor 评分权重的资产分配算法实例,即直接以SE返回的评分作为权重。
16
16
  * @return AFPtr
17
17
  * @ingroup AllocateFunds
18
18
  */
@@ -11,6 +11,9 @@
11
11
 
12
12
  namespace hku {
13
13
 
14
+ /*
15
+ * 创建 MultiFactor 评分权重的资产分配算法实例, 即直接以SE返回的评分作为权重。
16
+ */
14
17
  class MultiFactorAllocaterFunds : public AllocateFundsBase {
15
18
  ALLOCATEFUNDS_IMP(MultiFactorAllocaterFunds)
16
19
  ALLOCATEFUNDS_NO_PRIVATE_MEMBER_SERIALIZATION
@@ -66,7 +66,10 @@ public:
66
66
  /** 获取系统有效的日期列表,注意:和交易对象不等长 */
67
67
  DatetimeList getDatetimeList() const;
68
68
 
69
- /** 以指标的形式获取实际值,与交易对象等长,0表示无效,1表示系统有效 */
69
+ /**
70
+ * 以指标的形式获取实际值,与交易对象等长,<=0表示无效,>0表示系统有效
71
+ * @note 带日期的时间序列指标
72
+ */
70
73
  Indicator getValues() const;
71
74
 
72
75
  /**
@@ -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
 
@@ -13,6 +13,7 @@
13
13
  #include <shared_mutex>
14
14
  #include "../../KQuery.h"
15
15
  #include "../../utilities/Parameter.h"
16
+ #include "hikyuu/indicator/Indicator.h"
16
17
 
17
18
  namespace hku {
18
19
 
@@ -64,15 +65,24 @@ public:
64
65
  /**
65
66
  * 加入有效时间,在_calculate中调用
66
67
  * @param datetime 系统有效日期
68
+ * @param value 默认为1.0,大于0表示有效,小于等于0表示无效
67
69
  */
68
- void _addValid(const Datetime& datetime);
70
+ void _addValid(const Datetime& datetime, price_t value = 1.0);
69
71
 
70
72
  /**
71
73
  * 判断指定日期的外部环境是否有效
72
74
  * @param datetime 指定日期
73
75
  * @return true 有效 | false 无效
74
76
  */
75
- bool isValid(const Datetime& datetime);
77
+ bool isValid(const Datetime& datetime) const;
78
+
79
+ price_t getValue(const Datetime& datetime) const;
80
+
81
+ /**
82
+ * 以指标的形式获取实际值,与交易对象等长,<=0表示无效,>0表示系统有效
83
+ * @note 带日期的时间序列指标
84
+ */
85
+ Indicator getValues() const;
76
86
 
77
87
  /** 子类计算接口 */
78
88
  virtual void _calculate() = 0;
@@ -86,8 +96,9 @@ public:
86
96
  protected:
87
97
  string m_name;
88
98
  KQuery m_query;
89
- std::set<Datetime> m_valid;
90
- std::shared_mutex m_mutex;
99
+ map<Datetime, size_t> m_date_index;
100
+ vector<price_t> m_values;
101
+ mutable std::shared_mutex m_mutex;
91
102
 
92
103
  //============================================
93
104
  // 序列化支持
@@ -101,14 +112,17 @@ private:
101
112
  ar& BOOST_SERIALIZATION_NVP(m_params);
102
113
  // ev可能多个系统共享,保留m_query可能用于查错
103
114
  ar& BOOST_SERIALIZATION_NVP(m_query);
104
- ar& BOOST_SERIALIZATION_NVP(m_valid);
115
+ ar& BOOST_SERIALIZATION_NVP(m_date_index);
116
+ ar& BOOST_SERIALIZATION_NVP(m_values);
105
117
  }
106
118
 
107
119
  template <class Archive>
108
120
  void load(Archive& ar, const unsigned int version) {
109
121
  ar& BOOST_SERIALIZATION_NVP(m_name);
122
+ ar& BOOST_SERIALIZATION_NVP(m_params);
110
123
  ar& BOOST_SERIALIZATION_NVP(m_query);
111
- ar& BOOST_SERIALIZATION_NVP(m_valid);
124
+ ar& BOOST_SERIALIZATION_NVP(m_date_index);
125
+ ar& BOOST_SERIALIZATION_NVP(m_values);
112
126
  }
113
127
 
114
128
  BOOST_SERIALIZATION_SPLIT_MEMBER()
@@ -12,5 +12,6 @@
12
12
  #include "crt/EV_TwoLine.h"
13
13
  #include "crt/EV_Bool.h"
14
14
  #include "crt/EV_Manual.h"
15
+ #include "crt/EV_Logic.h"
15
16
 
16
17
  #endif /* ENVIRONMENT_BUILD_IN_H */
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-03-06
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/trade_sys/environment/EnvironmentBase.h"
11
+
12
+ namespace hku {
13
+
14
+ /**
15
+ * 两个市场环境判定相与,等效于两者的交集
16
+ * @param ev1 市场环境判定1
17
+ * @param ev2 市场环境判定2
18
+ * @return AndCondition 实例指针
19
+ */
20
+ HKU_API EnvironmentPtr operator&(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
21
+
22
+ /**
23
+ * 两个市场环境判定相或,等效于两者的并集
24
+ * @param ev1 市场环境判定1
25
+ * @param ev2 市场环境判定2
26
+ * @return OrCondition 实例指针
27
+ */
28
+ HKU_API EnvironmentPtr operator|(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
29
+
30
+ HKU_API EnvironmentPtr operator+(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
31
+ HKU_API EnvironmentPtr operator-(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
32
+ HKU_API EnvironmentPtr operator*(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
33
+ HKU_API EnvironmentPtr operator/(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
34
+
35
+ } // namespace hku
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-03-06
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/trade_sys/environment/EnvironmentBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class HKU_API AddEnvironment : public EnvironmentBase {
15
+ public:
16
+ AddEnvironment();
17
+ AddEnvironment(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
18
+ virtual ~AddEnvironment();
19
+
20
+ virtual void _calculate() override;
21
+ virtual void _reset() override;
22
+ virtual EnvironmentPtr _clone() override;
23
+
24
+ private:
25
+ EnvironmentPtr m_ev1;
26
+ EnvironmentPtr m_ev2;
27
+
28
+ //============================================
29
+ // 序列化支持
30
+ //============================================
31
+ #if HKU_SUPPORT_SERIALIZATION
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(EnvironmentBase);
36
+ ar& BOOST_SERIALIZATION_NVP(m_ev1);
37
+ ar& BOOST_SERIALIZATION_NVP(m_ev2);
38
+ }
39
+ #endif
40
+ };
41
+
42
+ } // namespace hku
@@ -0,0 +1,42 @@
1
+ /*
2
+ * Copyright (c) 2025 hikyuu.org
3
+ *
4
+ * Created on: 2025-03-06
5
+ * Author: fasiondog
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include "hikyuu/trade_sys/environment/EnvironmentBase.h"
11
+
12
+ namespace hku {
13
+
14
+ class HKU_API AndEnvironment : public EnvironmentBase {
15
+ public:
16
+ AndEnvironment();
17
+ AndEnvironment(const EnvironmentPtr& ev1, const EnvironmentPtr& ev2);
18
+ virtual ~AndEnvironment();
19
+
20
+ virtual void _calculate() override;
21
+ virtual void _reset() override;
22
+ virtual EnvironmentPtr _clone() override;
23
+
24
+ private:
25
+ EnvironmentPtr m_ev1;
26
+ EnvironmentPtr m_ev2;
27
+
28
+ //============================================
29
+ // 序列化支持
30
+ //============================================
31
+ #if HKU_SUPPORT_SERIALIZATION
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(EnvironmentBase);
36
+ ar& BOOST_SERIALIZATION_NVP(m_ev1);
37
+ ar& BOOST_SERIALIZATION_NVP(m_ev2);
38
+ }
39
+ #endif
40
+ };
41
+
42
+ } // namespace hku