hikyuu 2.6.7__py3-none-win_amd64.whl → 2.6.8.2__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.
- hikyuu/__init__.py +6 -2
- hikyuu/__init__.pyi +37 -10
- hikyuu/analysis/__init__.pyi +24 -0
- hikyuu/analysis/analysis.pyi +25 -1
- hikyuu/core.pyi +26 -2
- hikyuu/cpp/concrt140.dll +0 -0
- hikyuu/cpp/core310.pyd +0 -0
- hikyuu/cpp/core310.pyi +419 -31
- hikyuu/cpp/core311.pyd +0 -0
- hikyuu/cpp/core311.pyi +419 -31
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/core312.pyi +419 -31
- hikyuu/cpp/core313.pyd +0 -0
- hikyuu/cpp/core313.pyi +419 -31
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/core39.pyi +419 -31
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/hikyuu.lib +0 -0
- hikyuu/cpp/hku_hdf5.dll +0 -0
- hikyuu/cpp/hku_hdf5_cpp.dll +0 -0
- hikyuu/cpp/hku_hdf5_hl.dll +0 -0
- hikyuu/cpp/hku_hdf5_hl_cpp.dll +0 -0
- hikyuu/cpp/i18n/zh_CN/hikyuu.mo +0 -0
- hikyuu/cpp/msvcp140.dll +0 -0
- hikyuu/cpp/msvcp140_1.dll +0 -0
- hikyuu/cpp/msvcp140_2.dll +0 -0
- hikyuu/cpp/msvcp140_atomic_wait.dll +0 -0
- hikyuu/cpp/msvcp140_codecvt_ids.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/cpp/vcruntime140.dll +0 -0
- hikyuu/cpp/vcruntime140_1.dll +0 -0
- hikyuu/draw/__init__.pyi +1 -1
- hikyuu/draw/drawplot/bokeh_draw.pyi +33 -8
- hikyuu/draw/drawplot/echarts_draw.pyi +33 -8
- hikyuu/draw/drawplot/matplotlib_draw.pyi +33 -8
- hikyuu/extend.py +19 -0
- hikyuu/extend.pyi +27 -3
- hikyuu/hub.pyi +6 -6
- hikyuu/include/hikyuu/DataType.h +2 -2
- hikyuu/include/hikyuu/KData.h +91 -25
- hikyuu/include/hikyuu/KDataImp.h +31 -46
- hikyuu/include/hikyuu/KDataPrivatedBufferImp.h +73 -0
- hikyuu/include/hikyuu/KDataSharedBufferImp.h +69 -0
- hikyuu/include/hikyuu/KQuery.h +16 -4
- hikyuu/include/hikyuu/KRecord.h +4 -1
- hikyuu/include/hikyuu/Stock.h +10 -4
- hikyuu/include/hikyuu/StockManager.h +11 -3
- hikyuu/include/hikyuu/TransRecord.h +2 -2
- hikyuu/include/hikyuu/data_driver/KDataDriver.h +5 -0
- hikyuu/include/hikyuu/doc.h +2 -2
- hikyuu/include/hikyuu/global/GlobalSpotAgent.h +8 -0
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +12 -7
- hikyuu/include/hikyuu/indicator/Indicator.h +11 -0
- hikyuu/include/hikyuu/indicator/Indicator2InImp.h +9 -0
- hikyuu/include/hikyuu/indicator/IndicatorImp.h +83 -15
- hikyuu/include/hikyuu/indicator/build_in.h +1 -0
- hikyuu/include/hikyuu/indicator/crt/AMA.h +2 -1
- hikyuu/include/hikyuu/indicator/crt/ATR.h +1 -1
- hikyuu/include/hikyuu/indicator/crt/CONTEXT.h +2 -0
- hikyuu/include/hikyuu/indicator/crt/CYCLE.h +3 -0
- hikyuu/include/hikyuu/indicator/crt/DMA.h +1 -1
- hikyuu/include/hikyuu/indicator/crt/IC.h +14 -6
- hikyuu/include/hikyuu/indicator/crt/ICIR.h +8 -4
- hikyuu/include/hikyuu/indicator/crt/INSUM.h +2 -0
- hikyuu/include/hikyuu/indicator/crt/PRICELIST.h +2 -0
- hikyuu/include/hikyuu/indicator/crt/REFX.h +25 -0
- hikyuu/include/hikyuu/indicator/crt/SLICE.h +4 -4
- hikyuu/include/hikyuu/indicator/crt/SPEARMAN.h +3 -2
- hikyuu/include/hikyuu/indicator/imp/IContext.h +5 -0
- hikyuu/include/hikyuu/indicator/imp/ICval.h +6 -0
- hikyuu/include/hikyuu/indicator/imp/IDropna.h +9 -0
- hikyuu/include/hikyuu/indicator/imp/IIc.h +2 -1
- hikyuu/include/hikyuu/indicator/imp/IPriceList.h +1 -0
- hikyuu/include/hikyuu/indicator/imp/IRefX.h +23 -0
- hikyuu/include/hikyuu/plugin/backtest.h +2 -0
- hikyuu/include/hikyuu/plugin/extind.h +45 -0
- hikyuu/include/hikyuu/plugin/hkuextra.h +21 -0
- hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +16 -0
- hikyuu/include/hikyuu/plugin/interface/TMReportPluginInterface.h +1 -0
- hikyuu/include/hikyuu/python/pybind_utils.h +27 -11
- hikyuu/include/hikyuu/trade_manage/Performance.h +0 -1
- hikyuu/include/hikyuu/trade_manage/TradeCostBase.h +5 -0
- hikyuu/include/hikyuu/trade_manage/TradeManager.h +4 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +10 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +6 -3
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +4 -0
- hikyuu/include/hikyuu/trade_sys/profitgoal/ProfitGoalBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +5 -2
- hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/slippage/SlippageBase.h +5 -0
- hikyuu/include/hikyuu/trade_sys/stoploss/StoplossBase.h +6 -1
- hikyuu/include/hikyuu/trade_sys/system/System.h +5 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +2 -2
- hikyuu/include/hikyuu/utilities/os.h +4 -0
- hikyuu/include/hikyuu/utilities/thread/GlobalMQStealThreadPool.h +1 -1
- hikyuu/include/hikyuu/utilities/thread/GlobalMQThreadPool.h +1 -1
- hikyuu/include/hikyuu/utilities/thread/GlobalThreadPool.h +1 -1
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +1 -1
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/include/hikyuu/views/arrow_common.h +38 -0
- hikyuu/include/hikyuu/views/arrow_views.h +117 -0
- hikyuu/indicator/indicator.py +4 -5
- hikyuu/plugin/backtest.dll +0 -0
- hikyuu/plugin/clickhousedriver.dll +0 -0
- hikyuu/plugin/dataserver.dll +0 -0
- hikyuu/plugin/device.dll +0 -0
- hikyuu/plugin/extind.dll +0 -0
- hikyuu/plugin/hkuextra.dll +0 -0
- hikyuu/plugin/import2hdf5.dll +0 -0
- hikyuu/plugin/tmreport.dll +0 -0
- hikyuu/strategy/strategy_demo1.py +1 -1
- hikyuu/test/test_init.py +19 -19
- hikyuu/trade_manage/__init__.pyi +32 -7
- hikyuu/trade_manage/trade.py +6 -0
- hikyuu/trade_manage/trade.pyi +32 -7
- hikyuu/trade_sys/__init__.py +4 -0
- hikyuu/util/__init__.pyi +1 -1
- hikyuu/util/singleton.pyi +1 -1
- {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.2.dist-info}/METADATA +15 -3
- {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.2.dist-info}/RECORD +128 -125
- {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.2.dist-info}/WHEEL +1 -1
- {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.2.dist-info}/top_level.txt +1 -1
- hikyuu/include/hikyuu/view/MarketView.h +0 -59
- hikyuu/setup.py +0 -104
- hikyuu-2.6.7.dist-info/LICENSE +0 -201
- /hikyuu/include/hikyuu/{view → views}/__init__.py +0 -0
- {hikyuu-2.6.7.dist-info → hikyuu-2.6.8.2.dist-info}/entry_points.txt +0 -0
|
@@ -68,6 +68,10 @@ public:
|
|
|
68
68
|
return m_server_addr;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
+
bool isConnected() const {
|
|
72
|
+
return m_connected;
|
|
73
|
+
}
|
|
74
|
+
|
|
71
75
|
/**
|
|
72
76
|
* 增加收到 Spot 数据时的处理函数
|
|
73
77
|
* @note 仅能在停止状态时执行此操作,否则将抛出异常
|
|
@@ -99,9 +103,9 @@ public:
|
|
|
99
103
|
static void setQuotationServer(const string& server);
|
|
100
104
|
|
|
101
105
|
private:
|
|
102
|
-
static string ms_pubUrl;
|
|
103
|
-
static const char* ms_startTag;
|
|
104
|
-
static const char* ms_endTag;
|
|
106
|
+
static string ms_pubUrl; // 数据发送服务地址
|
|
107
|
+
static const char* ms_startTag; // 批次数据接收起始标记,用于判断启动了新的批次数据接收
|
|
108
|
+
static const char* ms_endTag; // 批次数据接收接收标记,用于判断该批次数据更新结束
|
|
105
109
|
static const char* ms_spotTopic; // 向数据发送服务订阅的主题
|
|
106
110
|
static const size_t ms_startTagLength; // 批次数据接收起始标记长度
|
|
107
111
|
static const size_t ms_endTagLength; // 批次数据接收结束标记长度
|
|
@@ -121,9 +125,10 @@ private:
|
|
|
121
125
|
void work_thread();
|
|
122
126
|
|
|
123
127
|
private:
|
|
124
|
-
enum STATUS { WAITING, RECEIVING };
|
|
125
|
-
enum STATUS m_status = WAITING;
|
|
126
|
-
std::atomic_bool m_stop = true;
|
|
128
|
+
enum STATUS { WAITING, RECEIVING }; // 等待新的批次数据,正在接收批次数据中
|
|
129
|
+
enum STATUS m_status = WAITING; // 当前内部状态
|
|
130
|
+
std::atomic_bool m_stop = true; // 结束代理工作标识
|
|
131
|
+
std::atomic_bool m_connected = false; // 是否已连接数据服务
|
|
127
132
|
|
|
128
133
|
int m_revTimeout = 100; // 连接数据服务超时时长(毫秒)
|
|
129
134
|
std::thread m_receiveThread; // 数据接收线程
|
|
@@ -137,7 +142,7 @@ private:
|
|
|
137
142
|
// 下面属性被修改时需要加锁,以便可以使用多线程方式运行 strategy
|
|
138
143
|
std::mutex m_mutex;
|
|
139
144
|
list<std::function<void(const SpotRecord&)>> m_processList; // 已注册的 spot 处理函数列表
|
|
140
|
-
list<std::function<void(Datetime)>> m_postProcessList;
|
|
145
|
+
list<std::function<void(Datetime)>> m_postProcessList; // 已注册的批次后处理函数列表
|
|
141
146
|
};
|
|
142
147
|
|
|
143
148
|
} // namespace hku
|
|
@@ -110,6 +110,9 @@ public:
|
|
|
110
110
|
*/
|
|
111
111
|
value_t get(size_t pos, size_t num = 0) const;
|
|
112
112
|
|
|
113
|
+
value_t front(size_t num = 0) const;
|
|
114
|
+
value_t back(size_t num = 0) const;
|
|
115
|
+
|
|
113
116
|
/**
|
|
114
117
|
* 获取指定位置的日期
|
|
115
118
|
* @param pos 结果集中的位置
|
|
@@ -322,6 +325,14 @@ inline Indicator::value_t Indicator::get(size_t pos, size_t num) const {
|
|
|
322
325
|
return m_imp->get(pos, num);
|
|
323
326
|
}
|
|
324
327
|
|
|
328
|
+
inline Indicator::value_t Indicator::front(size_t num) const {
|
|
329
|
+
return m_imp->front(num);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
inline Indicator::value_t Indicator::back(size_t num) const {
|
|
333
|
+
return m_imp->back(num);
|
|
334
|
+
}
|
|
335
|
+
|
|
325
336
|
inline Datetime Indicator::getDatetime(size_t pos) const {
|
|
326
337
|
return m_imp ? m_imp->getDatetime(pos) : Null<Datetime>();
|
|
327
338
|
}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
namespace hku {
|
|
13
13
|
|
|
14
|
+
/* note: 双输入但同一上下文*/
|
|
14
15
|
class Indicator2InImp : public IndicatorImp {
|
|
15
16
|
public:
|
|
16
17
|
Indicator2InImp();
|
|
@@ -21,6 +22,14 @@ public:
|
|
|
21
22
|
|
|
22
23
|
virtual IndicatorImpPtr _clone() override;
|
|
23
24
|
|
|
25
|
+
virtual bool needSelfAlikeCompare() const noexcept override {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
|
|
30
|
+
|
|
31
|
+
virtual void getSelfInnerNodesWithInputConext(vector<IndicatorImpPtr>& nodes) const override;
|
|
32
|
+
|
|
24
33
|
protected:
|
|
25
34
|
Indicator prepare(const Indicator& ind);
|
|
26
35
|
|
|
@@ -78,6 +78,9 @@ public:
|
|
|
78
78
|
|
|
79
79
|
value_t get(size_t pos, size_t num = 0) const;
|
|
80
80
|
|
|
81
|
+
value_t front(size_t num = 0) const;
|
|
82
|
+
value_t back(size_t num = 0) const;
|
|
83
|
+
|
|
81
84
|
value_t getByDate(Datetime, size_t num = 0);
|
|
82
85
|
|
|
83
86
|
Datetime getDatetime(size_t pos) const;
|
|
@@ -92,12 +95,6 @@ public:
|
|
|
92
95
|
/** 以Indicator的方式获取指定的输出集,该方式包含了discard的信息 */
|
|
93
96
|
IndicatorImpPtr getResult(size_t result_num);
|
|
94
97
|
|
|
95
|
-
/** 判断是否和另一个指标等效,即计算效果相同 */
|
|
96
|
-
bool alike(const IndicatorImp& other) const;
|
|
97
|
-
|
|
98
|
-
/** 判断指标公式中是否包含指定名称的指标(特殊用途) */
|
|
99
|
-
bool contains(const string& name) const;
|
|
100
|
-
|
|
101
98
|
/**
|
|
102
99
|
* 使用IndicatorImp(const Indicator&...)构造函数后,计算结果使用该函数,
|
|
103
100
|
* 未做越界保护
|
|
@@ -149,9 +146,6 @@ public:
|
|
|
149
146
|
typedef std::map<string, IndicatorImpPtr> ind_param_map_t;
|
|
150
147
|
const ind_param_map_t& getIndParams() const;
|
|
151
148
|
|
|
152
|
-
value_t* data(size_t result_idx = 0);
|
|
153
|
-
value_t const* data(size_t result_idx = 0) const;
|
|
154
|
-
|
|
155
149
|
// ===================
|
|
156
150
|
// 子类接口
|
|
157
151
|
// ===================
|
|
@@ -179,6 +173,45 @@ public:
|
|
|
179
173
|
|
|
180
174
|
virtual void _dyn_calculate(const Indicator&);
|
|
181
175
|
|
|
176
|
+
public:
|
|
177
|
+
// ===================
|
|
178
|
+
// 内部特殊用途公共接口
|
|
179
|
+
// ===================
|
|
180
|
+
|
|
181
|
+
/** 判断是否和另一个指标等效,即计算效果相同 */
|
|
182
|
+
bool alike(const IndicatorImp& other) const;
|
|
183
|
+
|
|
184
|
+
/** 判断指标公式中是否包含指定名称的指标(特殊用途) */
|
|
185
|
+
bool contains(const string& name) const;
|
|
186
|
+
|
|
187
|
+
value_t* data(size_t result_idx = 0);
|
|
188
|
+
value_t const* data(size_t result_idx = 0) const;
|
|
189
|
+
|
|
190
|
+
void getAllSubNodes(vector<IndicatorImpPtr>& nodes) const;
|
|
191
|
+
|
|
192
|
+
IndicatorImpPtr getRightNode() const;
|
|
193
|
+
IndicatorImpPtr getLeftNode() const;
|
|
194
|
+
IndicatorImpPtr getThreeNode() const;
|
|
195
|
+
void printTree(bool show_long_name = false) const;
|
|
196
|
+
void printAllSubTrees(bool show_long_name = false) const;
|
|
197
|
+
void printLeaves(bool show_long_name = false) const;
|
|
198
|
+
|
|
199
|
+
/* 特殊指标需自己实现 selfAlike 函数的, needSelfAlikeCompare 应返回 true */
|
|
200
|
+
virtual bool needSelfAlikeCompare() const noexcept {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// 特殊指标需自己实现 selfAlike 函数,返回true表示两个指标等效
|
|
205
|
+
virtual bool selfAlike(const IndicatorImp& other) const noexcept {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 使用输入上下文的特殊指标获取内部节点,以便合入指标树优化
|
|
210
|
+
virtual void getSelfInnerNodesWithInputConext(vector<IndicatorImpPtr>& nodes) const {}
|
|
211
|
+
|
|
212
|
+
// 指定独立 ktype 的叶子节点重载获取内部子节点
|
|
213
|
+
virtual void getSeparateKTypeLeafSubNodes(vector<IndicatorImpPtr>& nodes) const {}
|
|
214
|
+
|
|
182
215
|
private:
|
|
183
216
|
void initContext();
|
|
184
217
|
bool needCalculate();
|
|
@@ -198,17 +231,32 @@ private:
|
|
|
198
231
|
void execute_weave();
|
|
199
232
|
void execute_if();
|
|
200
233
|
|
|
201
|
-
|
|
234
|
+
static void inner_repeatALikeNodes(vector<IndicatorImpPtr>& sub_nodes);
|
|
202
235
|
void repeatALikeNodes();
|
|
236
|
+
void repeatSeparateKTypeLeafALikeNodes();
|
|
237
|
+
|
|
238
|
+
void generateSpecialLeafSet();
|
|
203
239
|
|
|
204
240
|
void _clearBuffer();
|
|
205
241
|
|
|
242
|
+
void _printTree(int depth = 0, bool isLast = true, bool show_long_name = false) const;
|
|
243
|
+
|
|
244
|
+
// 获取所有子树
|
|
245
|
+
vector<IndicatorImp*> getAllSubTrees() const;
|
|
246
|
+
|
|
247
|
+
// 获取子树中节点的数量
|
|
248
|
+
static size_t treeSize(IndicatorImp* tree);
|
|
249
|
+
|
|
250
|
+
static bool nodeInTree(IndicatorImp* node, IndicatorImp* tree);
|
|
251
|
+
|
|
206
252
|
protected:
|
|
207
253
|
static size_t _get_step_start(size_t pos, size_t step, size_t discard);
|
|
208
254
|
|
|
209
255
|
// 用于动态参数时,更新 discard
|
|
210
256
|
void _update_discard();
|
|
211
257
|
|
|
258
|
+
virtual bool isPythonObject() const;
|
|
259
|
+
|
|
212
260
|
protected:
|
|
213
261
|
string m_name;
|
|
214
262
|
size_t m_discard;
|
|
@@ -296,17 +344,17 @@ private:
|
|
|
296
344
|
ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
|
|
297
345
|
vector<value_t>& values = *m_pBuffer[i];
|
|
298
346
|
values.resize(count);
|
|
299
|
-
for (size_t
|
|
347
|
+
for (size_t j = 0; j < count; j++) {
|
|
300
348
|
std::string vstr;
|
|
301
349
|
ar >> boost::serialization::make_nvp<string>("item", vstr);
|
|
302
350
|
if (vstr == "nan") {
|
|
303
|
-
values[
|
|
351
|
+
values[j] = std::numeric_limits<double>::quiet_NaN();
|
|
304
352
|
} else if (vstr == "+inf") {
|
|
305
|
-
values[
|
|
353
|
+
values[j] = std::numeric_limits<double>::infinity();
|
|
306
354
|
} else if (vstr == "-inf") {
|
|
307
|
-
values[
|
|
355
|
+
values[j] = 0.0 - std::numeric_limits<double>::infinity();
|
|
308
356
|
} else {
|
|
309
|
-
values[
|
|
357
|
+
values[j] = std::atof(vstr.c_str());
|
|
310
358
|
}
|
|
311
359
|
}
|
|
312
360
|
}
|
|
@@ -392,6 +440,10 @@ inline KData IndicatorImp::getContext() const {
|
|
|
392
440
|
return getParam<KData>("kdata");
|
|
393
441
|
}
|
|
394
442
|
|
|
443
|
+
inline void IndicatorImp::setContext(const Stock& stock, const KQuery& query) {
|
|
444
|
+
setContext(stock.getKData(query));
|
|
445
|
+
}
|
|
446
|
+
|
|
395
447
|
inline const IndicatorImp::ind_param_map_t& IndicatorImp::getIndParams() const {
|
|
396
448
|
return m_ind_params;
|
|
397
449
|
}
|
|
@@ -412,6 +464,22 @@ inline size_t IndicatorImp::_get_step_start(size_t pos, size_t step, size_t disc
|
|
|
412
464
|
return step == 0 || pos < discard + step ? discard : pos + 1 - step;
|
|
413
465
|
}
|
|
414
466
|
|
|
467
|
+
inline bool IndicatorImp::isPythonObject() const {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
inline IndicatorImpPtr IndicatorImp::getRightNode() const {
|
|
472
|
+
return m_right;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
inline IndicatorImpPtr IndicatorImp::getLeftNode() const {
|
|
476
|
+
return m_left;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
inline IndicatorImpPtr IndicatorImp::getThreeNode() const {
|
|
480
|
+
return m_three;
|
|
481
|
+
}
|
|
482
|
+
|
|
415
483
|
} /* namespace hku */
|
|
416
484
|
|
|
417
485
|
#if FMT_VERSION >= 90000
|
|
@@ -18,7 +18,8 @@ namespace hku {
|
|
|
18
18
|
* @param n 计算均值的周期窗口,必须为大于2的整数,默认为10天
|
|
19
19
|
* @param fast_n 对应快速周期N,默认为2
|
|
20
20
|
* @param slow_n 对应慢速EMA线的N值,默认为30,不过当超过60左右该指标会收敛不会有太大的影响
|
|
21
|
-
* @
|
|
21
|
+
* @return 具有2个结果集,result(0)为AMA,result(1)为ER
|
|
22
|
+
* @ingroup Indicator
|
|
22
23
|
*/
|
|
23
24
|
Indicator HKU_API AMA(int n = 10, int fast_n = 2, int slow_n = 30);
|
|
24
25
|
Indicator HKU_API AMA(int n, int fast_n, const IndParam& slow_n);
|
|
@@ -15,6 +15,8 @@ namespace hku {
|
|
|
15
15
|
* 独立上下文指标
|
|
16
16
|
* @param ind 待包装指标
|
|
17
17
|
* @param fill_null 是否填充空值,默认为 false
|
|
18
|
+
* @param use_self_ktype 使用自身独立上下文的K线类型,否则计算时将使用计算上下文中K线类型
|
|
19
|
+
* @param use_self_recover_type 使用自身独立上下文的复权类型,否则计算时将使用计算上下文中的复权类型
|
|
18
20
|
* @ingroup Indicator
|
|
19
21
|
*/
|
|
20
22
|
Indicator HKU_API CONTEXT(const Indicator& ind, bool fill_null = false, bool use_self_ktype = false,
|
|
@@ -14,6 +14,9 @@ namespace hku {
|
|
|
14
14
|
/**
|
|
15
15
|
* PF调仓周期指标,主要用于PF调仓日验证,及作为SG
|
|
16
16
|
* @param k 关联的K线数据
|
|
17
|
+
* @param adjust_cycle 调仓周期,默认为1
|
|
18
|
+
* @param adjust_mode 调仓方式,默认为"query" day|week|month|quarter|year|query
|
|
19
|
+
* @param delay_to_trading_day 延迟至交易日,当调仓日为非交易日时,自动延迟至下一个交易日作为调仓日
|
|
17
20
|
* @ingroup Indicator
|
|
18
21
|
*/
|
|
19
22
|
Indicator CYCLE(const KData& k, int adjust_cycle = 1, const string& adjust_mode = "query",
|
|
@@ -14,28 +14,36 @@ namespace hku {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* @brief 计算指定的因子相对于参考证券的 IC (实际为 RankIC)
|
|
17
|
+
* @note IC 原本需要 “t 时刻因子值→t+1 时刻收益”,改为计算 “t 时刻因子值→t 时刻之前 N
|
|
18
|
+
天的收益”(比如过去 5 天的收益),并称之为 “当前 IC”。(否则当前值都会是缺失NA)
|
|
19
|
+
如需严格“t 时刻因子值→t+1 时刻收益“计算,请设置 strict=True (注意此模式下, 后n位为 NA)
|
|
17
20
|
* @param stks 证券组合
|
|
18
21
|
* @param query 查询条件
|
|
19
22
|
* @param ref_stk 参照证券,默认 sh000300 沪深300
|
|
20
23
|
* @param n 时间窗口 (对应 n 日收益率)
|
|
21
24
|
* @param spearman 使用 spearman 相关系数,否则为 pearson
|
|
25
|
+
* @param strict 严格模式, 遵循IC定义“t 时刻因子值→t+1 时刻收益”
|
|
22
26
|
* @return Indicator
|
|
23
27
|
* @ingroup Indicator
|
|
24
28
|
*/
|
|
25
29
|
Indicator HKU_API IC(const StockList& stks, const KQuery& query,
|
|
26
|
-
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true
|
|
30
|
+
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
|
|
31
|
+
bool strict = false);
|
|
27
32
|
|
|
28
33
|
Indicator HKU_API IC(const Block& blk, const KQuery& query,
|
|
29
|
-
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true
|
|
34
|
+
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
|
|
35
|
+
bool strict = false);
|
|
30
36
|
|
|
31
37
|
inline Indicator IC(const Indicator& ind, const StockList& stks, const KQuery& query,
|
|
32
|
-
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true
|
|
33
|
-
|
|
38
|
+
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
|
|
39
|
+
bool strict = false) {
|
|
40
|
+
return IC(stks, query, ref_stk, n, spearman, strict)(ind);
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
inline Indicator IC(const Indicator& ind, const Block& blk, const KQuery& query,
|
|
37
|
-
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true
|
|
38
|
-
|
|
44
|
+
const Stock& ref_stk = getStock("sh000300"), int n = 1, bool spearman = true,
|
|
45
|
+
bool strict = false) {
|
|
46
|
+
return IC(blk, query, ref_stk, n, spearman, strict)(ind);
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
} // namespace hku
|
|
@@ -16,6 +16,9 @@ namespace hku {
|
|
|
16
16
|
* @brief 计算指定的因子相对于参考证券的 ICIR (实际为 RankIC)
|
|
17
17
|
* @details IR:信息比率(Information Ratio,简称IR)=
|
|
18
18
|
* IC的多周期均值/IC的标准方差,代表因子获取稳定Alpha的能力。
|
|
19
|
+
* @note IC 原本需要 “t 时刻因子值→t+1 时刻收益”,改为计算 “t 时刻因子值→t 时刻之前 N
|
|
20
|
+
* 天的收益”(比如过去 5 天的收益),并称之为 “当前 IC”。(否则当前值都会是缺失NA)
|
|
21
|
+
* 如需严格“t 时刻因子值→t+1 时刻收益“计算,请设置 strict=True (注意此模式下, 后n位为 NA)
|
|
19
22
|
* @param ind 因子公式
|
|
20
23
|
* @param stks 证券组合
|
|
21
24
|
* @param query 查询条件
|
|
@@ -23,13 +26,14 @@ namespace hku {
|
|
|
23
26
|
* @param n IC对应的N日收益率
|
|
24
27
|
* @param rolling_n 滚动时间窗口
|
|
25
28
|
* @param spearman 使用 spearman 相关系数,否则为 pearson
|
|
29
|
+
* @param strict 是否严格模式
|
|
26
30
|
* @return Indicator
|
|
27
31
|
* @ingroup Indicator
|
|
28
32
|
*/
|
|
29
33
|
inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery& query,
|
|
30
34
|
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);
|
|
35
|
+
bool spearman = true, bool strict = false) {
|
|
36
|
+
Indicator ic = IC(ind, stks, query, ref_stk, n, spearman, strict);
|
|
33
37
|
Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
|
|
34
38
|
x.name("ICIR");
|
|
35
39
|
x.setParam<int>("n", n);
|
|
@@ -39,8 +43,8 @@ inline Indicator ICIR(const Indicator& ind, const StockList& stks, const KQuery&
|
|
|
39
43
|
|
|
40
44
|
inline Indicator ICIR(const Indicator& ind, const Block& blk, const KQuery& query,
|
|
41
45
|
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);
|
|
46
|
+
bool spearman = true, bool strict = false) {
|
|
47
|
+
Indicator ic = IC(ind, blk, query, ref_stk, n, spearman, strict);
|
|
44
48
|
Indicator x = MA(ic, rolling_n) / STDEV(ic, rolling_n);
|
|
45
49
|
x.name("ICIR");
|
|
46
50
|
x.setParam<int>("n", n);
|
|
@@ -28,4 +28,6 @@ Indicator HKU_API INSUM(const Block& block, const KQuery& query, const Indicator
|
|
|
28
28
|
|
|
29
29
|
Indicator HKU_API INSUM(const Block& block, const Indicator& ind, int mode, bool fill_null = true);
|
|
30
30
|
|
|
31
|
+
Indicator HKU_API INSUM(const Block& block, int mode, bool fill_null);
|
|
32
|
+
|
|
31
33
|
} // namespace hku
|
|
@@ -23,6 +23,8 @@ namespace hku {
|
|
|
23
23
|
*/
|
|
24
24
|
Indicator HKU_API PRICELIST(const PriceList& data, int discard = 0);
|
|
25
25
|
Indicator HKU_API PRICELIST(const PriceList& data, const DatetimeList& ds, int discard = 0);
|
|
26
|
+
Indicator HKU_API PRICELIST(size_t size, double value, int discard = 0);
|
|
27
|
+
Indicator HKU_API PRICELIST(const DatetimeList& dates, double value, int discard = 0);
|
|
26
28
|
Indicator HKU_API PRICELIST();
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-08-22
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../Indicator.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* REF增强(不安全引用), 用于数据左移或右移,周期为整数时,功能同 REF
|
|
16
|
+
* @note 不应用于回测,通常用于AI模型训练等场景
|
|
17
|
+
* @param n 引用周期
|
|
18
|
+
* @ingroup Indicator
|
|
19
|
+
*/
|
|
20
|
+
Indicator HKU_API REFX(int n);
|
|
21
|
+
inline Indicator HKU_API REFX(const Indicator& ind, int n) {
|
|
22
|
+
return REFX(n)(ind);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
} // namespace hku
|
|
@@ -24,20 +24,20 @@ Indicator HKU_API SLICE(const PriceList& data, int64_t start, int64_t end);
|
|
|
24
24
|
* 获取某指标中指定范围的数据
|
|
25
25
|
* @param start 起始范围,可为负数
|
|
26
26
|
* @param end 终止范围(不包含本身),可为负数
|
|
27
|
-
* @param result_index
|
|
27
|
+
* @param result_index 源数据中指定的结果集, 小于0时表示全部
|
|
28
28
|
* @ingroup Indicator
|
|
29
29
|
*/
|
|
30
|
-
Indicator HKU_API SLICE(int64_t start, int64_t end, int result_index =
|
|
30
|
+
Indicator HKU_API SLICE(int64_t start, int64_t end, int result_index = -1);
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* 获取某指标中指定范围的数据
|
|
34
34
|
* @param ind 源数据
|
|
35
35
|
* @param start 起始范围,可为负数
|
|
36
36
|
* @param end 终止范围(不包含本身),可为负数
|
|
37
|
-
* @param result_index
|
|
37
|
+
* @param result_index 源数据中指定的结果集,小于0时表示全部
|
|
38
38
|
* @ingroup Indicator
|
|
39
39
|
*/
|
|
40
|
-
inline Indicator SLICE(const Indicator& ind, int64_t start, int64_t end, int result_index =
|
|
40
|
+
inline Indicator SLICE(const Indicator& ind, int64_t start, int64_t end, int result_index = -1) {
|
|
41
41
|
return SLICE(start, end, result_index)(ind);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -12,9 +12,10 @@ namespace hku {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Spearman 相关系数
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
15
|
+
* @param ind 指标1
|
|
16
|
+
* @param ref_ind 指标2
|
|
17
17
|
* @param n 滚动窗口(大于2 或 等于0),等于0时,代表 n 实际使用 ind 的长度
|
|
18
|
+
* @param fill_null 填充缺失值
|
|
18
19
|
* @ingroup Indicator
|
|
19
20
|
*/
|
|
20
21
|
Indicator HKU_API SPEARMAN(const Indicator& ind, const Indicator& ref_ind, int n = 0,
|
|
@@ -21,6 +21,11 @@ public:
|
|
|
21
21
|
virtual string formula() const override;
|
|
22
22
|
virtual void _calculate(const Indicator& data) override;
|
|
23
23
|
virtual IndicatorImpPtr _clone() override;
|
|
24
|
+
virtual bool needSelfAlikeCompare() const noexcept override {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
|
|
24
29
|
|
|
25
30
|
KData getContextKdata() const;
|
|
26
31
|
|
|
@@ -22,6 +22,12 @@ public:
|
|
|
22
22
|
ICval(double value, size_t discard);
|
|
23
23
|
virtual ~ICval();
|
|
24
24
|
virtual void _checkParam(const string& name) const override;
|
|
25
|
+
|
|
26
|
+
virtual bool needSelfAlikeCompare() const noexcept override {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
virtual bool selfAlike(const IndicatorImp& other) const noexcept override;
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
} /* namespace hku */
|
|
@@ -22,6 +22,15 @@ class IDropna : public IndicatorImp {
|
|
|
22
22
|
public:
|
|
23
23
|
IDropna();
|
|
24
24
|
virtual ~IDropna();
|
|
25
|
+
|
|
26
|
+
virtual bool needSelfAlikeCompare() const noexcept override {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 禁止子节点合并, 上级默认已为 false
|
|
31
|
+
// virtual bool selfAlike(const IndicatorImp& other) const noexcept override {
|
|
32
|
+
// return false;
|
|
33
|
+
// }
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
} /* namespace hku */
|
|
@@ -14,7 +14,8 @@ 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, bool spearman
|
|
17
|
+
IIc(const StockList& stks, const KQuery& query, int n, const Stock& ref_stk, bool spearman,
|
|
18
|
+
bool strict);
|
|
18
19
|
virtual ~IIc();
|
|
19
20
|
|
|
20
21
|
virtual void _checkParam(const string& name) const override;
|
|
@@ -21,6 +21,7 @@ class IPriceList : public IndicatorImp {
|
|
|
21
21
|
public:
|
|
22
22
|
IPriceList();
|
|
23
23
|
IPriceList(const PriceList&, int discard);
|
|
24
|
+
IPriceList(size_t size, double value, int discard);
|
|
24
25
|
virtual ~IPriceList();
|
|
25
26
|
virtual void _checkParam(const string& name) const override;
|
|
26
27
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-08-22
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../Indicator.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class IRefX : public IndicatorImp {
|
|
15
|
+
INDICATOR_IMP(IRefX)
|
|
16
|
+
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
IRefX();
|
|
20
|
+
virtual ~IRefX();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
} /* namespace hku */
|
|
@@ -22,6 +22,8 @@ namespace hku {
|
|
|
22
22
|
* @param ref_market 所属市场
|
|
23
23
|
* @param mode 模式 0: 当前bar收盘价执行买卖操作;1: 下一bar开盘价执行买卖操作;
|
|
24
24
|
* @param support_short 是否支持做空
|
|
25
|
+
* @param slip 滑点算法
|
|
26
|
+
* @ingroup Strategy
|
|
25
27
|
*/
|
|
26
28
|
void HKU_API backtest(const StrategyContext& context, const std::function<void(Strategy*)>& on_bar,
|
|
27
29
|
const TradeManagerPtr& tm, const Datetime& start_date,
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
namespace hku {
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* @ingroup Indicator
|
|
16
|
+
* @{
|
|
17
|
+
*/
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* @brief 将指标数据转换到指定周期
|
|
16
21
|
* @param ktype 指定周期
|
|
@@ -146,5 +151,45 @@ inline Indicator WITHHOUR4(const Indicator& ind, bool fill_null = false) {
|
|
|
146
151
|
*/
|
|
147
152
|
Indicator HKU_API RANK(const Block& block, const Indicator& ref_ind, int mode = 0,
|
|
148
153
|
bool fill_null = true, const string& market = "SH");
|
|
154
|
+
Indicator HKU_API RANK(const Block& block, int mode = 0, bool fill_null = true,
|
|
155
|
+
const string& market = "SH");
|
|
149
156
|
|
|
157
|
+
/**
|
|
158
|
+
* @brief 聚合其他K线周期统计值,聚合计算指定K线类型数据均值到以上下文中的K线周期
|
|
159
|
+
* @param ktype 指定K线周期
|
|
160
|
+
* @param fill_null 是否填充null数据
|
|
161
|
+
* @param unit 聚合周期单位,默认为1。按上下文K线 unit 个周期计算
|
|
162
|
+
* @return Indicator
|
|
163
|
+
*/
|
|
164
|
+
#define AGG_FUNC_DEFINE(agg_name) \
|
|
165
|
+
Indicator HKU_API agg_name(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN, \
|
|
166
|
+
bool fill_null = false, int unit = 1);
|
|
167
|
+
|
|
168
|
+
#define AGG_FUNC_IMP(agg_name) \
|
|
169
|
+
Indicator HKU_API agg_name(const Indicator& ind, const KQuery::KType& ktype, bool fill_null, \
|
|
170
|
+
int unit) { \
|
|
171
|
+
Parameter params; \
|
|
172
|
+
params.set<string>("ktype", ktype); \
|
|
173
|
+
params.set<bool>("fill_null", fill_null); \
|
|
174
|
+
params.set<int>("unit", unit); \
|
|
175
|
+
return getExtIndicator(#agg_name, ind, params); \
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
AGG_FUNC_DEFINE(AGG_MEAN)
|
|
179
|
+
AGG_FUNC_DEFINE(AGG_COUNT)
|
|
180
|
+
AGG_FUNC_DEFINE(AGG_SUM)
|
|
181
|
+
AGG_FUNC_DEFINE(AGG_MAX)
|
|
182
|
+
AGG_FUNC_DEFINE(AGG_MIN)
|
|
183
|
+
AGG_FUNC_DEFINE(AGG_MAD)
|
|
184
|
+
AGG_FUNC_DEFINE(AGG_MEDIAN)
|
|
185
|
+
AGG_FUNC_DEFINE(AGG_PROD)
|
|
186
|
+
|
|
187
|
+
Indicator HKU_API AGG_STD(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
|
|
188
|
+
bool fill_null = false, int unit = 1, int ddof = 1);
|
|
189
|
+
Indicator HKU_API AGG_VAR(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
|
|
190
|
+
bool fill_null = false, int unit = 1, int ddof = 1);
|
|
191
|
+
Indicator HKU_API AGG_QUANTILE(const Indicator& ind, const KQuery::KType& ktype = KQuery::MIN,
|
|
192
|
+
bool fill_null = false, int unit = 1, double quantile = 0.75);
|
|
193
|
+
|
|
194
|
+
/** @} */
|
|
150
195
|
} // namespace hku
|