hikyuu 2.1.4__cp38-none-win_amd64.whl → 2.2.0__cp38-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/analysis/analysis.py +20 -0
- hikyuu/cpp/boost_date_time-mt.dll +0 -0
- hikyuu/cpp/boost_serialization-mt.dll +0 -0
- hikyuu/cpp/boost_wserialization-mt.dll +0 -0
- hikyuu/cpp/core38.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/data/common.py +3 -3
- hikyuu/data/mysql_upgrade/0022.sql +5 -0
- hikyuu/data/mysql_upgrade/0023.sql +4 -0
- hikyuu/data/pytdx_weight_to_mysql.py +14 -15
- hikyuu/data/pytdx_weight_to_sqlite.py +14 -15
- hikyuu/data/sqlite_upgrade/0023.sql +7 -0
- hikyuu/data/sqlite_upgrade/0024.sql +22 -0
- hikyuu/fetcher/stock/zh_stock_a_pytdx.py +3 -3
- hikyuu/gui/HikyuuTDX.py +3 -2
- hikyuu/gui/data/ImportHistoryFinanceTask.py +7 -0
- hikyuu/gui/data/ImportWeightToSqliteTask.py +2 -2
- hikyuu/gui/data/MainWindow.py +1 -1
- hikyuu/gui/start_qmt.py +99 -13
- hikyuu/include/hikyuu/StockWeight.h +16 -10
- hikyuu/include/hikyuu/analysis/analysis_sys.h +42 -12
- hikyuu/include/hikyuu/data_driver/base_info/table/StockWeightTable.h +6 -4
- hikyuu/include/hikyuu/global/agent/SpotAgent.h +5 -6
- hikyuu/include/hikyuu/indicator/crt/DMA.h +1 -7
- hikyuu/include/hikyuu/indicator/crt/IC.h +7 -6
- hikyuu/include/hikyuu/indicator/crt/ICIR.h +7 -4
- hikyuu/include/hikyuu/indicator/imp/IDma.h +47 -0
- hikyuu/include/hikyuu/indicator/imp/IIc.h +1 -1
- hikyuu/include/hikyuu/serialization/StockWeight_serialization.h +5 -2
- hikyuu/include/hikyuu/strategy/BrokerTradeManager.h +27 -25
- hikyuu/include/hikyuu/strategy/Strategy.h +1 -2
- hikyuu/include/hikyuu/trade_manage/Performance.h +3 -0
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +16 -6
- hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +0 -3
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +2 -2
- hikyuu/include/hikyuu/trade_sys/condition/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/condition/crt/CN_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/condition/imp/ManualCondition.h +23 -0
- hikyuu/include/hikyuu/trade_sys/condition/imp/{AddCondition.h → logic/AddCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{AndCondition.h → logic/AndCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{DivCondition.h → logic/DivCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{MultiCondition.h → logic/MultiCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/{OrCondition.h → logic/OrCondition.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/condition/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +6 -6
- hikyuu/include/hikyuu/trade_sys/environment/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/environment/crt/EV_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/environment/imp/ManualEnvironment.h +23 -0
- hikyuu/include/hikyuu/trade_sys/multifactor/MultiFactorBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_EqualWeight.h +3 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICIRWeight.h +3 -2
- hikyuu/include/hikyuu/trade_sys/multifactor/crt/MF_ICWeight.h +4 -2
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/EqualWeightMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICIRMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/multifactor/imp/ICMultiFactor.h +1 -1
- hikyuu/include/hikyuu/trade_sys/portfolio/Portfolio.h +2 -2
- hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +3 -1
- hikyuu/include/hikyuu/trade_sys/selector/build_in.h +2 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +26 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSelector.h → logic/OperatorSelector.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorValueSelector.h → logic/OperatorValueSelector.h} +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/imp/logic/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/MaxFundsOptimalSelector.h +27 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +86 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/PerformanceOptimalSelector.h +42 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/__init__.py +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/signal/crt/SG_Manual.h +20 -0
- hikyuu/include/hikyuu/trade_sys/signal/imp/ManualSignal.h +23 -0
- hikyuu/include/hikyuu/trade_sys/system/System.h +30 -13
- hikyuu/include/hikyuu/trade_sys/system/TradeRequest.h +19 -11
- hikyuu/include/hikyuu/trade_sys/system/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/system/crt/SYS_WalkForward.h +27 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/DelegateSystem.h +51 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardSystem.h +70 -0
- hikyuu/include/hikyuu/trade_sys/system/imp/WalkForwardTradeManager.h +465 -0
- hikyuu/include/hikyuu/utilities/base64.h +25 -31
- hikyuu/include/hikyuu/version.h +5 -5
- hikyuu/strategy/strategy_demo1.py +2 -1
- hikyuu/trade_sys/trade_sys.py +28 -9
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/METADATA +1 -1
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/RECORD +100 -78
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/top_level.txt +3 -0
- /hikyuu/include/hikyuu/trade_sys/selector/crt/{SE_Operator.h → SE_Logic.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddSelector.h → logic/OperatorAddSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorAddValueSelector.h → logic/OperatorAddValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivSelector.h → logic/OperatorDivSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorDivValueSelector.h → logic/OperatorDivValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertDivValueSelector.h → logic/OperatorInvertDivValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorInvertSubValueSelector.h → logic/OperatorInvertSubValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulSelector.h → logic/OperatorMulSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorMulValueSelector.h → logic/OperatorMulValueSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubSelector.h → logic/OperatorSubSelector.h} +0 -0
- /hikyuu/include/hikyuu/trade_sys/selector/imp/{OperatorSubValueSelector.h → logic/OperatorSubValueSelector.h} +0 -0
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/LICENSE +0 -0
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/WHEEL +0 -0
- {hikyuu-2.1.4.dist-info → hikyuu-2.2.0.dist-info}/entry_points.txt +0 -0
|
@@ -151,12 +151,12 @@ private: \
|
|
|
151
151
|
typedef shared_ptr<EnvironmentBase> EnvironmentPtr;
|
|
152
152
|
typedef shared_ptr<EnvironmentBase> EVPtr;
|
|
153
153
|
|
|
154
|
-
#define ENVIRONMENT_IMP(classname)
|
|
155
|
-
public:
|
|
156
|
-
virtual EnvironmentPtr _clone() {
|
|
157
|
-
return std::make_shared<classname>();
|
|
158
|
-
}
|
|
159
|
-
virtual void _calculate();
|
|
154
|
+
#define ENVIRONMENT_IMP(classname) \
|
|
155
|
+
public: \
|
|
156
|
+
virtual EnvironmentPtr _clone() override { \
|
|
157
|
+
return std::make_shared<classname>(); \
|
|
158
|
+
} \
|
|
159
|
+
virtual void _calculate() override;
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* 输出Environment信息,如:Environment(name, params[...])
|
|
@@ -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 "../EnvironmentBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 仅能手工添加系统环境有效性的EV,用于测试或其他用途
|
|
16
|
+
* @return EVPtr
|
|
17
|
+
*/
|
|
18
|
+
EVPtr HKU_API EV_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 "../EnvironmentBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class ManualEnvironment : public EnvironmentBase {
|
|
15
|
+
ENVIRONMENT_IMP(ManualEnvironment)
|
|
16
|
+
ENVIRONMENT_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
ManualEnvironment();
|
|
20
|
+
virtual ~ManualEnvironment() = default;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
} // namespace hku
|
|
@@ -29,7 +29,7 @@ public:
|
|
|
29
29
|
MultiFactorBase();
|
|
30
30
|
explicit MultiFactorBase(const string& name);
|
|
31
31
|
MultiFactorBase(const IndicatorList& inds, const StockList& stks, const KQuery& query,
|
|
32
|
-
const Stock& ref_stk, const string& name, int ic_n);
|
|
32
|
+
const Stock& ref_stk, const string& name, int ic_n, bool spearman);
|
|
33
33
|
MultiFactorBase(const MultiFactorBase&);
|
|
34
34
|
virtual ~MultiFactorBase() = default;
|
|
35
35
|
|
|
@@ -17,10 +17,12 @@ namespace hku {
|
|
|
17
17
|
* @param query 日期范围
|
|
18
18
|
* @param ref_stk 参考证券
|
|
19
19
|
* @param ic_n 默认 IC 对应的 N 日收益率
|
|
20
|
+
* @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
|
|
20
21
|
* @return MultiFactorPtr
|
|
21
22
|
*/
|
|
22
23
|
MultiFactorPtr HKU_API MF_EqualWeight(const IndicatorList& inds, const StockList& stks,
|
|
23
|
-
const KQuery& query, const Stock& ref_stk, int ic_n = 5
|
|
24
|
+
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
|
|
25
|
+
bool spearman = true);
|
|
24
26
|
|
|
25
27
|
MultiFactorPtr HKU_API MF_EqualWeight();
|
|
26
28
|
|
|
@@ -19,11 +19,12 @@ namespace hku {
|
|
|
19
19
|
* @param ref_stk 参考证券
|
|
20
20
|
* @param ic_n 默认 IC 对应的 N 日收益率
|
|
21
21
|
* @param ic_rolling_n IC 滚动窗口
|
|
22
|
+
* @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
|
|
22
23
|
* @return MultiFactorPtr
|
|
23
24
|
*/
|
|
24
25
|
MultiFactorPtr HKU_API MF_ICIRWeight(const IndicatorList& inds, const StockList& stks,
|
|
25
26
|
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
|
|
26
|
-
int ic_rolling_n = 120);
|
|
27
|
+
int ic_rolling_n = 120, bool spearman = true);
|
|
27
28
|
|
|
28
29
|
MultiFactorPtr HKU_API MF_ICIRWeight();
|
|
29
|
-
}
|
|
30
|
+
} // namespace hku
|
|
@@ -19,10 +19,12 @@ namespace hku {
|
|
|
19
19
|
* @param ref_stk 参考证券
|
|
20
20
|
* @param ic_n 默认 IC 对应的 N 日收益率
|
|
21
21
|
* @param ic_rolling_n IC 滚动窗口
|
|
22
|
+
* @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
|
|
22
23
|
* @return MultiFactorPtr
|
|
23
24
|
*/
|
|
24
25
|
MultiFactorPtr HKU_API MF_ICWeight(const IndicatorList& inds, const StockList& stks,
|
|
25
26
|
const KQuery& query, const Stock& ref_stk, int ic_n = 5,
|
|
26
|
-
int ic_rolling_n = 120);
|
|
27
|
+
int ic_rolling_n = 120, bool spearman = true);
|
|
27
28
|
MultiFactorPtr HKU_API MF_ICWeight();
|
|
28
|
-
|
|
29
|
+
|
|
30
|
+
} // namespace hku
|
|
@@ -18,7 +18,7 @@ class EqualWeightMultiFactor : public MultiFactorBase {
|
|
|
18
18
|
public:
|
|
19
19
|
EqualWeightMultiFactor();
|
|
20
20
|
EqualWeightMultiFactor(const vector<Indicator>& inds, const StockList& stks,
|
|
21
|
-
const KQuery& query, const Stock& ref_stk, int ic_n);
|
|
21
|
+
const KQuery& query, const Stock& ref_stk, int ic_n, bool spearman);
|
|
22
22
|
virtual ~EqualWeightMultiFactor() = default;
|
|
23
23
|
};
|
|
24
24
|
|
|
@@ -18,7 +18,7 @@ class ICIRMultiFactor : public MultiFactorBase {
|
|
|
18
18
|
public:
|
|
19
19
|
ICIRMultiFactor();
|
|
20
20
|
ICIRMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
|
|
21
|
-
const Stock& ref_stk, int ic_n, int ic_rolling_n);
|
|
21
|
+
const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
|
|
22
22
|
virtual ~ICIRMultiFactor() = default;
|
|
23
23
|
|
|
24
24
|
virtual void _checkParam(const string& name) const override;
|
|
@@ -18,7 +18,7 @@ class ICMultiFactor : public MultiFactorBase {
|
|
|
18
18
|
public:
|
|
19
19
|
ICMultiFactor();
|
|
20
20
|
ICMultiFactor(const IndicatorList& inds, const StockList& stks, const KQuery& query,
|
|
21
|
-
const Stock& ref_stk, int ic_n, int ic_rolling_n);
|
|
21
|
+
const Stock& ref_stk, int ic_n, int ic_rolling_n, bool spearman);
|
|
22
22
|
virtual ~ICMultiFactor() = default;
|
|
23
23
|
|
|
24
24
|
virtual void _checkParam(const string& name) const override;
|
|
@@ -34,10 +34,10 @@ public:
|
|
|
34
34
|
/**
|
|
35
35
|
* @brief 构造函数
|
|
36
36
|
* @param tm 账户
|
|
37
|
-
* @param
|
|
37
|
+
* @param se 选择器
|
|
38
38
|
* @param af 资产分配算法
|
|
39
39
|
*/
|
|
40
|
-
Portfolio(const TradeManagerPtr& tm, const SelectorPtr&
|
|
40
|
+
Portfolio(const TradeManagerPtr& tm, const SelectorPtr& se, const AFPtr& af);
|
|
41
41
|
|
|
42
42
|
/** 析构函数 */
|
|
43
43
|
virtual ~Portfolio();
|
|
@@ -122,13 +122,15 @@ public:
|
|
|
122
122
|
virtual void _removeAll() {}
|
|
123
123
|
|
|
124
124
|
/* 仅供PF调用,由PF通知其实际运行的系统列表,并启动计算 */
|
|
125
|
-
void calculate(const SystemList& pf_realSysList, const KQuery& query);
|
|
125
|
+
virtual void calculate(const SystemList& pf_realSysList, const KQuery& query);
|
|
126
126
|
|
|
127
127
|
/* 仅供PF调用,建立实际系统到原型系统映射 */
|
|
128
128
|
virtual void bindRealToProto(const SYSPtr& real, const SYSPtr& proto) {}
|
|
129
129
|
|
|
130
130
|
void calculate_proto(const KQuery& query);
|
|
131
131
|
|
|
132
|
+
virtual string str() const;
|
|
133
|
+
|
|
132
134
|
private:
|
|
133
135
|
void initParam();
|
|
134
136
|
|
|
@@ -28,12 +28,13 @@ SelectorPtr HKU_API SE_MultiFactor(const MFPtr& mf, int topn = 10);
|
|
|
28
28
|
* @param ic_n ic 对应的 ic_n 日收益率
|
|
29
29
|
* @param ic_rolling_n 计算滚动 IC (即 IC 的 n 日移动平均)周期
|
|
30
30
|
* @param ref_stk 参照对比证券,未指定时,默认使用 sh000300 沪深300指数
|
|
31
|
+
* @param spearman 默认使用 spearman 计算相关系数,否则为 pearson
|
|
31
32
|
* @param mode "MF_ICIRWeight" | "MF_ICWeight" | "MF_EqualWeight" 因子合成算法名称
|
|
32
33
|
* @return SelectorPtr
|
|
33
34
|
* @ingroup Selector
|
|
34
35
|
*/
|
|
35
36
|
SelectorPtr HKU_API SE_MultiFactor(const IndicatorList& src_inds, int topn = 10, int ic_n = 5,
|
|
36
37
|
int ic_rolling_n = 120, const Stock& ref_stk = Stock(),
|
|
37
|
-
const string& mode = "MF_ICIRWeight");
|
|
38
|
+
bool spearman = true, const string& mode = "MF_ICIRWeight");
|
|
38
39
|
|
|
39
40
|
} // namespace hku
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-14
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../SelectorBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 账户资产最大寻优选择器
|
|
16
|
+
* @return SEPtr
|
|
17
|
+
*/
|
|
18
|
+
SEPtr HKU_API SE_MaxFundsOptimal();
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 使用 Performance 统计结果进行寻优的选择器
|
|
22
|
+
* @return SEPtr
|
|
23
|
+
*/
|
|
24
|
+
SEPtr HKU_API SE_PerformanceOptimal(const string& key = "帐户平均年收益率%", int mode = 0);
|
|
25
|
+
|
|
26
|
+
} // namespace hku
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-22
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_
|
|
10
|
+
#define HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_
|
|
11
|
+
|
|
12
|
+
#include "OptimalSelectorBase.h"
|
|
13
|
+
|
|
14
|
+
namespace hku {
|
|
15
|
+
|
|
16
|
+
class MaxFundsOptimalSelector : public OptimalSelectorBase {
|
|
17
|
+
OPTIMAL_SELECTOR_IMP(MaxFundsOptimalSelector)
|
|
18
|
+
OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
19
|
+
|
|
20
|
+
public:
|
|
21
|
+
MaxFundsOptimalSelector();
|
|
22
|
+
virtual ~MaxFundsOptimalSelector();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
} // namespace hku
|
|
26
|
+
|
|
27
|
+
#endif /* HKU_TRADE_SYS_MAX_FUNDS_OPTIMAL_SELECTOR_H_ */
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-13
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#include "hikyuu/trade_sys/selector/SelectorBase.h"
|
|
10
|
+
|
|
11
|
+
namespace hku {
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
// start ------ run_start --end
|
|
15
|
+
// | train_len | test_len
|
|
16
|
+
//
|
|
17
|
+
struct RunRanges {
|
|
18
|
+
Datetime start;
|
|
19
|
+
Datetime run_start;
|
|
20
|
+
Datetime end;
|
|
21
|
+
|
|
22
|
+
RunRanges(const Datetime& start_, const Datetime& run_start_, const Datetime end_)
|
|
23
|
+
: start(start_), run_start(run_start_), end(end_) {}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
class HKU_API OptimalSelectorBase : public SelectorBase {
|
|
27
|
+
CLASS_LOGGER_IMP(SE_Optimal)
|
|
28
|
+
SELECTOR_IMP(OptimalSelectorBase)
|
|
29
|
+
SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
30
|
+
|
|
31
|
+
public:
|
|
32
|
+
OptimalSelectorBase();
|
|
33
|
+
explicit OptimalSelectorBase(const string& name);
|
|
34
|
+
virtual ~OptimalSelectorBase() = default;
|
|
35
|
+
|
|
36
|
+
virtual void _checkParam(const string& name) const override;
|
|
37
|
+
virtual void calculate(const SystemList& pf_realSysList, const KQuery& query) override;
|
|
38
|
+
|
|
39
|
+
virtual void _reset() override;
|
|
40
|
+
|
|
41
|
+
virtual string str() const override;
|
|
42
|
+
|
|
43
|
+
// 以便继承子类只需要实现 _clone 和 该接口即可
|
|
44
|
+
// 该接口实现系统绩效评估,getSelected 时将取评估结果最大的系统
|
|
45
|
+
// 使用 std::function 的话,在 C++ 中无法序列化,所以使用继承
|
|
46
|
+
virtual double evaluate(const SYSPtr& sys, const Datetime& endDate) noexcept {
|
|
47
|
+
return Null<double>();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const vector<RunRanges>& getRunRanges() const {
|
|
51
|
+
return m_run_ranges;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private:
|
|
55
|
+
void _initParams();
|
|
56
|
+
void _calculate_single(const vector<std::pair<size_t, size_t>>& train_ranges,
|
|
57
|
+
const DatetimeList& dates, size_t test_len, bool trace);
|
|
58
|
+
|
|
59
|
+
void _calculate_parallel(const vector<std::pair<size_t, size_t>>& train_ranges,
|
|
60
|
+
const DatetimeList& dates, size_t test_len, bool trace);
|
|
61
|
+
|
|
62
|
+
protected:
|
|
63
|
+
unordered_map<Datetime, std::shared_ptr<SystemWeightList>> m_sys_dict;
|
|
64
|
+
vector<RunRanges> m_run_ranges;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
68
|
+
#define OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION \
|
|
69
|
+
private: \
|
|
70
|
+
friend class boost::serialization::access; \
|
|
71
|
+
template <class Archive> \
|
|
72
|
+
void serialize(Archive& ar, const unsigned int version) { \
|
|
73
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(SelectorBase); \
|
|
74
|
+
}
|
|
75
|
+
#else
|
|
76
|
+
#define OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
77
|
+
#endif
|
|
78
|
+
|
|
79
|
+
#define OPTIMAL_SELECTOR_IMP(classname) \
|
|
80
|
+
public: \
|
|
81
|
+
virtual SelectorPtr _clone() override { \
|
|
82
|
+
return std::make_shared<classname>(); \
|
|
83
|
+
} \
|
|
84
|
+
virtual double evaluate(const SYSPtr&, const Datetime& endDate) noexcept override;
|
|
85
|
+
|
|
86
|
+
} // namespace hku
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-13
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OptimalSelectorBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class PerformanceOptimalSelector : public OptimalSelectorBase {
|
|
15
|
+
CLASS_LOGGER_IMP(SE_Optimal)
|
|
16
|
+
OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
PerformanceOptimalSelector();
|
|
20
|
+
virtual ~PerformanceOptimalSelector() = default;
|
|
21
|
+
|
|
22
|
+
virtual void _checkParam(const string& name) const override;
|
|
23
|
+
virtual void calculate(const SystemList& pf_realSysList, const KQuery& query) override;
|
|
24
|
+
|
|
25
|
+
virtual SystemWeightList getSelected(Datetime date);
|
|
26
|
+
virtual SelectorPtr _clone() override;
|
|
27
|
+
virtual void _reset() override;
|
|
28
|
+
|
|
29
|
+
private:
|
|
30
|
+
void _calculate_single(const vector<std::pair<size_t, size_t>>& train_ranges,
|
|
31
|
+
const DatetimeList& dates, const string& key, int mode, size_t test_len,
|
|
32
|
+
bool trace);
|
|
33
|
+
|
|
34
|
+
void _calculate_parallel(const vector<std::pair<size_t, size_t>>& train_ranges,
|
|
35
|
+
const DatetimeList& dates, const string& key, int mode,
|
|
36
|
+
size_t test_len, bool trace);
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
unordered_map<Datetime, SYSPtr> m_sys_dict;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} // namespace hku
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019~2023, hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* History:
|
|
5
|
+
* 1. 20240916 added by fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../SignalBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 仅能手动添加信号的信号指示器,用于测试或其他特殊用途
|
|
16
|
+
* @return SignalPtr
|
|
17
|
+
*/
|
|
18
|
+
SignalPtr HKU_API SG_Manual();
|
|
19
|
+
|
|
20
|
+
} // namespace hku
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019~2023, hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* History:
|
|
5
|
+
* 1. 20240916 added by fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../SignalBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class ManualSignal : public SignalBase {
|
|
15
|
+
SIGNAL_IMP(ManualSignal)
|
|
16
|
+
SIGNAL_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
ManualSignal();
|
|
20
|
+
virtual ~ManualSignal() = default;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
} // namespace hku
|
|
@@ -27,6 +27,7 @@ namespace hku {
|
|
|
27
27
|
|
|
28
28
|
class HKU_API Portfolio;
|
|
29
29
|
class HKU_API AllocateFundsBase;
|
|
30
|
+
class HKU_API WalkForwardSystem;
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
33
|
* 交易系统基类
|
|
@@ -36,6 +37,7 @@ class HKU_API System {
|
|
|
36
37
|
PARAMETER_SUPPORT_WITH_CHECK
|
|
37
38
|
friend class HKU_API Portfolio;
|
|
38
39
|
friend class HKU_API AllocateFundsBase;
|
|
40
|
+
friend class HKU_API WalkForwardSystem;
|
|
39
41
|
|
|
40
42
|
public:
|
|
41
43
|
/** 默认构造函数 */
|
|
@@ -63,6 +65,8 @@ public:
|
|
|
63
65
|
const StoplossPtr& tp, const ProfitGoalPtr& pg, const SlippagePtr& sp,
|
|
64
66
|
const string& name);
|
|
65
67
|
|
|
68
|
+
System(const System&) = default;
|
|
69
|
+
|
|
66
70
|
/** 析构函数 */
|
|
67
71
|
virtual ~System();
|
|
68
72
|
|
|
@@ -151,6 +155,9 @@ public:
|
|
|
151
155
|
const TradeRequest& getSellShortTradeRequest() const;
|
|
152
156
|
const TradeRequest& getBuyShortTradeRequest() const;
|
|
153
157
|
|
|
158
|
+
/** 将所有组件全部置为非共享 */
|
|
159
|
+
void setNotSharedAll();
|
|
160
|
+
|
|
154
161
|
/**
|
|
155
162
|
* 复位,但不包括已有的交易对象,以及共享的部件
|
|
156
163
|
* @note 实际复位操作依赖于系统中各个部件的共享参数
|
|
@@ -196,48 +203,58 @@ public:
|
|
|
196
203
|
* @param reset 执行前是否依据系统部件共享属性复位
|
|
197
204
|
* @param resetAll 强制复位所有部件
|
|
198
205
|
*/
|
|
199
|
-
void run(const KData& kdata, bool reset = true, bool resetAll = false);
|
|
206
|
+
virtual void run(const KData& kdata, bool reset = true, bool resetAll = false);
|
|
200
207
|
|
|
201
208
|
/**
|
|
202
209
|
* @brief 在指定的日期执行一步,仅由 PF 调用
|
|
203
210
|
* @param datetime 指定的日期
|
|
204
211
|
* @return TradeRecord
|
|
205
212
|
*/
|
|
206
|
-
TradeRecord runMoment(const Datetime& datetime);
|
|
213
|
+
virtual TradeRecord runMoment(const Datetime& datetime);
|
|
207
214
|
|
|
208
215
|
// 运行前准备工作, 失败将抛出异常
|
|
209
|
-
void readyForRun();
|
|
210
|
-
|
|
211
|
-
TradeRecord sell(const KRecord& today, const KRecord& src_today, Part from) {
|
|
212
|
-
return _sell(today, src_today, from);
|
|
213
|
-
}
|
|
216
|
+
virtual void readyForRun();
|
|
214
217
|
|
|
215
218
|
// 由各个相关组件调用,用于组件参数变化时通知 sys,以便重算
|
|
216
219
|
void partChangedNotify() {
|
|
217
220
|
m_calculated = false;
|
|
218
221
|
}
|
|
219
222
|
|
|
220
|
-
|
|
223
|
+
virtual void _reset() {}
|
|
224
|
+
virtual void _forceResetAll() {}
|
|
225
|
+
|
|
226
|
+
/** 子类克隆接口 */
|
|
227
|
+
virtual SystemPtr _clone() {
|
|
228
|
+
return make_shared<System>();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
virtual string str() const;
|
|
232
|
+
|
|
233
|
+
public:
|
|
234
|
+
//-------------------------
|
|
235
|
+
// 仅供 PF/AF 内部调用
|
|
236
|
+
//-------------------------
|
|
237
|
+
|
|
221
238
|
// 强制以开盘价卖出,仅供 PF/AF 内部调用
|
|
222
|
-
TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) {
|
|
239
|
+
virtual TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) {
|
|
223
240
|
HKU_ASSERT(from == PART_ALLOCATEFUNDS || from == PART_PORTFOLIO);
|
|
224
241
|
return _sellForce(date, num, from, true);
|
|
225
242
|
}
|
|
226
243
|
|
|
227
244
|
// 强制以收盘价卖出,仅供 PF/AF 内部调用
|
|
228
|
-
TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) {
|
|
245
|
+
virtual TradeRecord sellForceOnClose(const Datetime& date, double num, Part from) {
|
|
229
246
|
HKU_ASSERT(from == PART_ALLOCATEFUNDS || from == PART_PORTFOLIO);
|
|
230
247
|
return _sellForce(date, num, from, false);
|
|
231
248
|
}
|
|
232
249
|
|
|
233
250
|
// 清除已有的交易请求,供Portfolio使用
|
|
234
|
-
void clearDelayBuyRequest();
|
|
251
|
+
virtual void clearDelayBuyRequest();
|
|
235
252
|
|
|
236
253
|
// 当前是否存在延迟的操作请求,供Portfolio
|
|
237
|
-
bool haveDelaySellRequest() const;
|
|
254
|
+
virtual bool haveDelaySellRequest() const;
|
|
238
255
|
|
|
239
256
|
// 处理延迟买入请求,仅供 PF 调用
|
|
240
|
-
TradeRecord pfProcessDelaySellRequest(const Datetime& date);
|
|
257
|
+
virtual TradeRecord pfProcessDelaySellRequest(const Datetime& date);
|
|
241
258
|
|
|
242
259
|
private:
|
|
243
260
|
bool _environmentIsValid(const Datetime& datetime);
|
|
@@ -20,19 +20,19 @@ namespace hku {
|
|
|
20
20
|
*/
|
|
21
21
|
class HKU_API TradeRequest {
|
|
22
22
|
public:
|
|
23
|
-
TradeRequest();
|
|
24
|
-
void clear();
|
|
23
|
+
TradeRequest() = default;
|
|
24
|
+
void clear() noexcept;
|
|
25
25
|
|
|
26
|
-
bool valid;
|
|
27
|
-
BUSINESS business;
|
|
26
|
+
bool valid{false};
|
|
27
|
+
BUSINESS business{BUSINESS_INVALID};
|
|
28
28
|
Datetime datetime;
|
|
29
|
-
price_t stoploss;
|
|
30
|
-
price_t goal;
|
|
31
|
-
double number;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
SystemPart from;
|
|
35
|
-
int count;
|
|
29
|
+
price_t stoploss{0.0};
|
|
30
|
+
price_t goal{0.0};
|
|
31
|
+
double number{0.0}; // 计划的买入/卖出数量,使用发出请求时刻的收盘价,
|
|
32
|
+
// 用于避免实际买入时需用重新计算数量时,人工执行速度较慢
|
|
33
|
+
// 可通过系统参数进行设置,是否使用
|
|
34
|
+
SystemPart from{PART_INVALID}; // 记录SystemBase::Part
|
|
35
|
+
int count{0}; // 因操作失败,连续延迟的次数
|
|
36
36
|
KRecord krecord;
|
|
37
37
|
|
|
38
38
|
//============================================
|
|
@@ -82,5 +82,13 @@ private:
|
|
|
82
82
|
#endif /* HKU_SUPPORT_SERIALIZATION */
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
+
HKU_API std::ostream& operator<<(std::ostream& os, const TradeRequest& tr);
|
|
86
|
+
|
|
85
87
|
} /* namespace hku */
|
|
88
|
+
|
|
89
|
+
#if FMT_VERSION >= 90000
|
|
90
|
+
template <>
|
|
91
|
+
struct fmt::formatter<hku::TradeRequest> : ostream_formatter {};
|
|
92
|
+
#endif
|
|
93
|
+
|
|
86
94
|
#endif /* TRADEREQUEST_H_ */
|