hikyuu 2.0.9__cp310-none-win_amd64.whl → 2.1.1__cp310-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 +6 -5
- 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/core310.pyd +0 -0
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/data/common.py +1 -4
- hikyuu/draw/drawplot/matplotlib_draw.py +3 -2
- hikyuu/extend.py +3 -1
- hikyuu/flat/Spot.py +0 -139
- hikyuu/flat/SpotList.py +1 -59
- hikyuu/gui/HikyuuTDX.py +17 -11
- hikyuu/gui/data/UseTdxImportToH5Thread.py +1 -1
- hikyuu/hub.py +1 -1
- hikyuu/include/hikyuu/Block.h +2 -2
- hikyuu/include/hikyuu/DataType.h +2 -1
- hikyuu/include/hikyuu/KRecord.h +1 -1
- hikyuu/include/hikyuu/StockManager.h +3 -0
- hikyuu/include/hikyuu/analysis/combinate.h +1 -1
- hikyuu/include/hikyuu/config.h +3 -12
- hikyuu/include/hikyuu/global/agent/hikyuu/flat/__init__.py +1 -0
- hikyuu/include/hikyuu/global/agent/spot_generated.h +3 -225
- hikyuu/include/hikyuu/indicator/crt/BLOCKSETNUM.h +1 -9
- hikyuu/include/hikyuu/indicator/crt/INSUM.h +2 -5
- hikyuu/include/hikyuu/strategy/AccountTradeManager.h +3 -1
- hikyuu/include/hikyuu/trade_sys/allocatefunds/AllocateFundsBase.h +5 -5
- hikyuu/include/hikyuu/trade_sys/condition/ConditionBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/environment/EnvironmentBase.h +5 -5
- hikyuu/include/hikyuu/trade_sys/moneymanager/MoneyManagerBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/profitgoal/ProfitGoalBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/selector/SelectorBase.h +24 -1
- hikyuu/include/hikyuu/trade_sys/selector/build_in.h +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Fixed.h +5 -2
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_MultiFactor.h +2 -5
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Operator.h +43 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/FixedSelector.h +1 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/MultiFactorSelector.h +9 -2
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorAddSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorAddValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorDivSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorDivValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorInvertDivValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorInvertSubValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorMulSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorMulValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorSelector.h +99 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorSubSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorSubValueSelector.h +19 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/OperatorValueSelector.h +77 -0
- hikyuu/include/hikyuu/trade_sys/signal/SignalBase.h +5 -5
- hikyuu/include/hikyuu/trade_sys/slippage/SlippageBase.h +1 -1
- hikyuu/include/hikyuu/trade_sys/stoploss/StoplossBase.h +6 -6
- hikyuu/include/hikyuu/trade_sys/system/System.h +21 -13
- hikyuu/include/hikyuu/utilities/FilterNode.h +267 -0
- hikyuu/include/hikyuu/utilities/LRUCache11.h +230 -0
- hikyuu/include/hikyuu/{Log.h → utilities/Log.h} +91 -113
- hikyuu/include/hikyuu/utilities/Null.h +1 -0
- hikyuu/include/hikyuu/utilities/Parameter.h +2 -1
- hikyuu/include/hikyuu/utilities/ResourcePool.h +636 -0
- hikyuu/include/hikyuu/utilities/SpendTimer.h +10 -9
- hikyuu/include/hikyuu/utilities/TimerManager.h +2 -2
- hikyuu/include/hikyuu/utilities/any_to_string.h +142 -0
- hikyuu/include/hikyuu/utilities/arithmetic.h +69 -33
- hikyuu/include/hikyuu/utilities/base64.h +59 -0
- hikyuu/include/hikyuu/utilities/config.h +41 -0
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +41 -31
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +24 -13
- hikyuu/include/hikyuu/utilities/db_connect/DBCondition.h +48 -48
- hikyuu/include/hikyuu/utilities/db_connect/DBConnect.h +10 -0
- hikyuu/include/hikyuu/utilities/db_connect/DBConnectBase.h +5 -22
- hikyuu/include/hikyuu/utilities/db_connect/DBUpgrade.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/SQLException.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLResultSet.h +1 -1
- hikyuu/include/hikyuu/utilities/db_connect/SQLStatementBase.h +7 -7
- hikyuu/include/hikyuu/utilities/db_connect/TableMacro.h +1 -2
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLConnect.h +9 -9
- hikyuu/include/hikyuu/utilities/db_connect/mysql/MySQLStatement.h +18 -18
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteConnect.h +3 -3
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteStatement.h +2 -2
- hikyuu/include/hikyuu/utilities/db_connect/sqlite/SQLiteUtil.h +6 -6
- hikyuu/include/hikyuu/{exception.h → utilities/exception.h} +1 -0
- hikyuu/include/hikyuu/utilities/http_client/HttpClient.h +229 -0
- hikyuu/include/hikyuu/utilities/http_client/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/http_client/nng_wrap.h +517 -0
- hikyuu/include/hikyuu/utilities/http_client/url.h +25 -0
- hikyuu/include/hikyuu/utilities/{IniParser.h → ini_parser/IniParser.h} +10 -5
- hikyuu/include/hikyuu/utilities/ini_parser/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/md5.h +41 -0
- hikyuu/include/hikyuu/utilities/mo/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/mo/mo.h +48 -0
- hikyuu/include/hikyuu/utilities/mo/moFileReader.h +836 -0
- hikyuu/include/hikyuu/{global → utilities}/node/NodeClient.h +25 -18
- hikyuu/include/hikyuu/{global → utilities}/node/NodeError.h +1 -1
- hikyuu/include/hikyuu/{global → utilities}/node/NodeMessage.h +3 -2
- hikyuu/include/hikyuu/utilities/node/NodeServer.h +246 -0
- hikyuu/include/hikyuu/utilities/node/__init__.py +1 -0
- hikyuu/include/hikyuu/utilities/os.h +20 -14
- hikyuu/include/hikyuu/utilities/snowflake.h +110 -0
- hikyuu/include/hikyuu/utilities/string_view.h +70 -0
- hikyuu/include/hikyuu/utilities/thread/MQStealThreadPool.h +5 -5
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +5 -5
- hikyuu/include/hikyuu/utilities/thread/StealThreadPool.h +5 -5
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +5 -5
- hikyuu/include/hikyuu/version.h +5 -5
- hikyuu/sqlite3.dll +0 -0
- hikyuu/vcruntime140.dll +0 -0
- hikyuu/vcruntime140_1.dll +0 -0
- hikyuu-2.1.1.dist-info/METADATA +115 -0
- {hikyuu-2.0.9.dist-info → hikyuu-2.1.1.dist-info}/RECORD +115 -82
- {hikyuu-2.0.9.dist-info → hikyuu-2.1.1.dist-info}/top_level.txt +6 -1
- hikyuu/README.rst +0 -79
- hikyuu/cpp/boost_atomic-mt.dll +0 -0
- hikyuu/cpp/boost_filesystem-mt.dll +0 -0
- hikyuu-2.0.9.dist-info/METADATA +0 -126
- /hikyuu/include/hikyuu/global/{node → agent/hikyuu}/__init__.py +0 -0
- {hikyuu-2.0.9.dist-info → hikyuu-2.1.1.dist-info}/LICENSE +0 -0
- {hikyuu-2.0.9.dist-info → hikyuu-2.1.1.dist-info}/WHEEL +0 -0
- {hikyuu-2.0.9.dist-info → hikyuu-2.1.1.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorValueSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorInvertDivValueSelector : public OperatorValueSelector {
|
|
15
|
+
OPERATOR_VALUE_SELECTOR_IMP(OperatorInvertDivValueSelector, "SE_DivValue")
|
|
16
|
+
OPERATOR_VALUE_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorValueSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorInvertSubValueSelector : public OperatorValueSelector {
|
|
15
|
+
OPERATOR_VALUE_SELECTOR_IMP(OperatorInvertSubValueSelector, "SE_SubValue")
|
|
16
|
+
OPERATOR_VALUE_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorMulSelector : public OperatorSelector {
|
|
15
|
+
OPERATOR_SELECTOR_IMP(OperatorMulSelector, "SE_Multi")
|
|
16
|
+
OPERATOR_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorValueSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorMulValueSelector : public OperatorValueSelector {
|
|
15
|
+
OPERATOR_VALUE_SELECTOR_IMP(OperatorMulValueSelector, "SE_MultiValue")
|
|
16
|
+
OPERATOR_VALUE_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../SelectorBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorSelector : public SelectorBase {
|
|
15
|
+
public:
|
|
16
|
+
OperatorSelector();
|
|
17
|
+
OperatorSelector(const string& name);
|
|
18
|
+
OperatorSelector(const string& name, const SelectorPtr& se1, const SelectorPtr& se2);
|
|
19
|
+
virtual ~OperatorSelector();
|
|
20
|
+
|
|
21
|
+
virtual void _reset() override;
|
|
22
|
+
virtual SelectorPtr _clone() override;
|
|
23
|
+
virtual bool isMatchAF(const AFPtr& af) override;
|
|
24
|
+
virtual void _calculate() override;
|
|
25
|
+
virtual SystemWeightList getSelected(Datetime date) override {
|
|
26
|
+
return SystemWeightList();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
virtual void _addSystem(const SYSPtr& sys) override;
|
|
30
|
+
virtual void _removeAll() override;
|
|
31
|
+
|
|
32
|
+
protected:
|
|
33
|
+
virtual void bindRealToProto(const SYSPtr& real, const SYSPtr& proto) override {
|
|
34
|
+
m_real_to_proto[real] = proto;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
SystemWeightList getUnionSelected(Datetime date,
|
|
38
|
+
const std::function<double(double, double)>&& func);
|
|
39
|
+
|
|
40
|
+
SystemWeightList getIntersectionSelected(Datetime date,
|
|
41
|
+
const std::function<double(double, double)>&& func);
|
|
42
|
+
|
|
43
|
+
protected:
|
|
44
|
+
static void sortSystemWeightList(SystemWeightList& swlist);
|
|
45
|
+
|
|
46
|
+
void cloneRebuild(const SelectorPtr& se1, const SelectorPtr& se2);
|
|
47
|
+
|
|
48
|
+
protected:
|
|
49
|
+
SelectorPtr m_se1;
|
|
50
|
+
SelectorPtr m_se2;
|
|
51
|
+
std::unordered_set<SYSPtr> m_se1_set; // se1 的原型系统实例集合
|
|
52
|
+
std::unordered_set<SYSPtr> m_se2_set; // se2 的原型系统实例集合
|
|
53
|
+
std::unordered_map<SYSPtr, SYSPtr> m_real_to_proto;
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
static std::unordered_set<System*> findIntersection(const SelectorPtr& se1,
|
|
57
|
+
const SelectorPtr& se2);
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
//============================================
|
|
61
|
+
// 序列化支持
|
|
62
|
+
//============================================
|
|
63
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
64
|
+
friend class boost::serialization::access;
|
|
65
|
+
template <class Archive>
|
|
66
|
+
void serialize(Archive& ar, const unsigned int version) {
|
|
67
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(SelectorBase);
|
|
68
|
+
ar& BOOST_SERIALIZATION_NVP(m_se1);
|
|
69
|
+
ar& BOOST_SERIALIZATION_NVP(m_se2);
|
|
70
|
+
}
|
|
71
|
+
#endif
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
#define OPERATOR_SELECTOR_IMP(classname, name) \
|
|
75
|
+
public: \
|
|
76
|
+
classname() : OperatorSelector(name) {} \
|
|
77
|
+
classname(const SelectorPtr& se1, const SelectorPtr& se2) \
|
|
78
|
+
: OperatorSelector(name, se1, se2) {} \
|
|
79
|
+
virtual ~classname() {} \
|
|
80
|
+
\
|
|
81
|
+
virtual SystemWeightList getSelected(Datetime date) override; \
|
|
82
|
+
\
|
|
83
|
+
virtual SelectorPtr _clone() override { \
|
|
84
|
+
HKU_THROW("OperatorSelector Could't support clone!"); \
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
88
|
+
#define OPERATOR_SELECTOR_SERIALIZATION \
|
|
89
|
+
private: \
|
|
90
|
+
friend class boost::serialization::access; \
|
|
91
|
+
template <class Archive> \
|
|
92
|
+
void serialize(Archive& ar, const unsigned int version) { \
|
|
93
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(OperatorSelector); \
|
|
94
|
+
}
|
|
95
|
+
#else
|
|
96
|
+
#define OPERATOR_SELECTOR_SERIALIZATION
|
|
97
|
+
#endif
|
|
98
|
+
|
|
99
|
+
} // namespace hku
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorSubSelector : public OperatorSelector {
|
|
15
|
+
OPERATOR_SELECTOR_IMP(OperatorSubSelector, "SE_Sub")
|
|
16
|
+
OPERATOR_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OperatorValueSelector.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorSubValueSelector : public OperatorValueSelector {
|
|
15
|
+
OPERATOR_VALUE_SELECTOR_IMP(OperatorSubValueSelector, "SE_SubValue")
|
|
16
|
+
OPERATOR_VALUE_SELECTOR_SERIALIZATION
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace hku
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-05-27
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "../SelectorBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HKU_API OperatorValueSelector : public SelectorBase {
|
|
15
|
+
public:
|
|
16
|
+
OperatorValueSelector();
|
|
17
|
+
OperatorValueSelector(const string& name);
|
|
18
|
+
OperatorValueSelector(const string& name, const SelectorPtr& se, double value);
|
|
19
|
+
virtual ~OperatorValueSelector();
|
|
20
|
+
|
|
21
|
+
virtual void _reset() override;
|
|
22
|
+
virtual SelectorPtr _clone() override;
|
|
23
|
+
virtual bool isMatchAF(const AFPtr& af) override;
|
|
24
|
+
virtual void _calculate() override;
|
|
25
|
+
virtual SystemWeightList getSelected(Datetime date) override {
|
|
26
|
+
return SystemWeightList();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected:
|
|
30
|
+
SelectorPtr m_se;
|
|
31
|
+
double m_value{0.0};
|
|
32
|
+
|
|
33
|
+
private:
|
|
34
|
+
//============================================
|
|
35
|
+
// 序列化支持
|
|
36
|
+
//============================================
|
|
37
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
38
|
+
friend class boost::serialization::access;
|
|
39
|
+
template <class Archive>
|
|
40
|
+
void serialize(Archive& ar, const unsigned int version) {
|
|
41
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(SelectorBase);
|
|
42
|
+
ar& BOOST_SERIALIZATION_NVP(m_se);
|
|
43
|
+
ar& BOOST_SERIALIZATION_NVP(m_value);
|
|
44
|
+
}
|
|
45
|
+
#endif
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
#define OPERATOR_VALUE_SELECTOR_IMP(classname, name) \
|
|
49
|
+
public: \
|
|
50
|
+
classname() : OperatorValueSelector(name) {} \
|
|
51
|
+
classname(const SelectorPtr& se, double value) : OperatorValueSelector(name, se, value) {} \
|
|
52
|
+
virtual ~classname() {} \
|
|
53
|
+
\
|
|
54
|
+
virtual SystemWeightList getSelected(Datetime date) override; \
|
|
55
|
+
\
|
|
56
|
+
virtual SelectorPtr _clone() override { \
|
|
57
|
+
auto p = std::make_shared<classname>(); \
|
|
58
|
+
if (m_se) { \
|
|
59
|
+
p->m_se = m_se->clone(); \
|
|
60
|
+
} \
|
|
61
|
+
p->m_value = m_value; \
|
|
62
|
+
return p; \
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#if HKU_SUPPORT_SERIALIZATION
|
|
66
|
+
#define OPERATOR_VALUE_SELECTOR_SERIALIZATION \
|
|
67
|
+
private: \
|
|
68
|
+
friend class boost::serialization::access; \
|
|
69
|
+
template <class Archive> \
|
|
70
|
+
void serialize(Archive& ar, const unsigned int version) { \
|
|
71
|
+
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(OperatorValueSelector); \
|
|
72
|
+
}
|
|
73
|
+
#else
|
|
74
|
+
#define OPERATOR_VALUE_SELECTOR_SERIALIZATION
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
} // namespace hku
|
|
@@ -191,11 +191,11 @@ private: \
|
|
|
191
191
|
#define SIGNAL_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
192
192
|
#endif
|
|
193
193
|
|
|
194
|
-
#define SIGNAL_IMP(classname)
|
|
195
|
-
public:
|
|
196
|
-
virtual SignalPtr _clone() override {
|
|
197
|
-
return
|
|
198
|
-
}
|
|
194
|
+
#define SIGNAL_IMP(classname) \
|
|
195
|
+
public: \
|
|
196
|
+
virtual SignalPtr _clone() override { \
|
|
197
|
+
return std::make_shared<classname>(); \
|
|
198
|
+
} \
|
|
199
199
|
virtual void _calculate(const KData&) override;
|
|
200
200
|
|
|
201
201
|
/**
|
|
@@ -129,7 +129,7 @@ private: \
|
|
|
129
129
|
#define SLIPPAGE_IMP(classname) \
|
|
130
130
|
public: \
|
|
131
131
|
virtual SlippagePtr _clone() override { \
|
|
132
|
-
return
|
|
132
|
+
return std::make_shared<classname>(); \
|
|
133
133
|
} \
|
|
134
134
|
virtual price_t getRealBuyPrice(const Datetime&, price_t) override; \
|
|
135
135
|
virtual price_t getRealSellPrice(const Datetime&, price_t) override; \
|
|
@@ -146,12 +146,12 @@ private: \
|
|
|
146
146
|
#define STOPLOSS_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
147
147
|
#endif
|
|
148
148
|
|
|
149
|
-
#define STOPLOSS_IMP(classname, str_name)
|
|
150
|
-
public:
|
|
151
|
-
virtual StoplossPtr _clone() override {
|
|
152
|
-
return
|
|
153
|
-
}
|
|
154
|
-
virtual void _calculate() override;
|
|
149
|
+
#define STOPLOSS_IMP(classname, str_name) \
|
|
150
|
+
public: \
|
|
151
|
+
virtual StoplossPtr _clone() override { \
|
|
152
|
+
return std::make_shared<classname>(); \
|
|
153
|
+
} \
|
|
154
|
+
virtual void _calculate() override; \
|
|
155
155
|
virtual price_t getPrice(const Datetime&, price_t) override;
|
|
156
156
|
|
|
157
157
|
/**
|
|
@@ -25,12 +25,17 @@
|
|
|
25
25
|
|
|
26
26
|
namespace hku {
|
|
27
27
|
|
|
28
|
+
class HKU_API Portfolio;
|
|
29
|
+
class HKU_API AllocateFundsBase;
|
|
30
|
+
|
|
28
31
|
/**
|
|
29
32
|
* 交易系统基类
|
|
30
33
|
* @ingroup System
|
|
31
34
|
*/
|
|
32
35
|
class HKU_API System {
|
|
33
36
|
PARAMETER_SUPPORT_WITH_CHECK
|
|
37
|
+
friend class HKU_API Portfolio;
|
|
38
|
+
friend class HKU_API AllocateFundsBase;
|
|
34
39
|
|
|
35
40
|
public:
|
|
36
41
|
/** 默认构造函数 */
|
|
@@ -200,12 +205,6 @@ public:
|
|
|
200
205
|
*/
|
|
201
206
|
TradeRecord runMoment(const Datetime& datetime);
|
|
202
207
|
|
|
203
|
-
// 清除已有的交易请求,供Portfolio使用
|
|
204
|
-
void clearDelayRequest();
|
|
205
|
-
|
|
206
|
-
// 当前是否存在延迟的操作请求,供Portfolio
|
|
207
|
-
bool haveDelayRequest() const;
|
|
208
|
-
|
|
209
208
|
// 运行前准备工作, 失败将抛出异常
|
|
210
209
|
void readyForRun();
|
|
211
210
|
|
|
@@ -213,6 +212,12 @@ public:
|
|
|
213
212
|
return _sell(today, src_today, from);
|
|
214
213
|
}
|
|
215
214
|
|
|
215
|
+
// 由各个相关组件调用,用于组件参数变化时通知 sys,以便重算
|
|
216
|
+
void partChangedNotify() {
|
|
217
|
+
m_calculated = false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private:
|
|
216
221
|
// 强制以开盘价卖出,仅供 PF/AF 内部调用
|
|
217
222
|
TradeRecord sellForceOnOpen(const Datetime& date, double num, Part from) {
|
|
218
223
|
HKU_ASSERT(from == PART_ALLOCATEFUNDS || from == PART_PORTFOLIO);
|
|
@@ -225,10 +230,14 @@ public:
|
|
|
225
230
|
return _sellForce(date, num, from, false);
|
|
226
231
|
}
|
|
227
232
|
|
|
228
|
-
//
|
|
229
|
-
void
|
|
230
|
-
|
|
231
|
-
|
|
233
|
+
// 清除已有的交易请求,供Portfolio使用
|
|
234
|
+
void clearDelayBuyRequest();
|
|
235
|
+
|
|
236
|
+
// 当前是否存在延迟的操作请求,供Portfolio
|
|
237
|
+
bool haveDelaySellRequest() const;
|
|
238
|
+
|
|
239
|
+
// 处理延迟买入请求,仅供 PF 调用
|
|
240
|
+
TradeRecord pfProcessDelaySellRequest(const Datetime& date);
|
|
232
241
|
|
|
233
242
|
private:
|
|
234
243
|
bool _environmentIsValid(const Datetime& datetime);
|
|
@@ -338,8 +347,8 @@ private:
|
|
|
338
347
|
ar& BOOST_SERIALIZATION_NVP(m_pg);
|
|
339
348
|
ar& BOOST_SERIALIZATION_NVP(m_sp);
|
|
340
349
|
|
|
341
|
-
// m_kdata中包含了stock和query的信息,不用保存m_stock
|
|
342
350
|
ar& BOOST_SERIALIZATION_NVP(m_kdata);
|
|
351
|
+
ar& BOOST_SERIALIZATION_NVP(m_stock);
|
|
343
352
|
|
|
344
353
|
ar& BOOST_SERIALIZATION_NVP(m_calculated);
|
|
345
354
|
ar& BOOST_SERIALIZATION_NVP(m_pre_ev_valid);
|
|
@@ -372,9 +381,8 @@ private:
|
|
|
372
381
|
ar& BOOST_SERIALIZATION_NVP(m_pg);
|
|
373
382
|
ar& BOOST_SERIALIZATION_NVP(m_sp);
|
|
374
383
|
|
|
375
|
-
// m_kdata中包含了stock和query的信息,不用保存m_stock
|
|
376
384
|
ar& BOOST_SERIALIZATION_NVP(m_kdata);
|
|
377
|
-
|
|
385
|
+
ar& BOOST_SERIALIZATION_NVP(m_stock);
|
|
378
386
|
|
|
379
387
|
ar& BOOST_SERIALIZATION_NVP(m_calculated);
|
|
380
388
|
ar& BOOST_SERIALIZATION_NVP(m_pre_ev_valid);
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2023 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2023-01-13
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <memory>
|
|
11
|
+
#include <functional>
|
|
12
|
+
#include <forward_list>
|
|
13
|
+
#include <unordered_map>
|
|
14
|
+
#include "thread/ThreadPool.h"
|
|
15
|
+
#include "any_to_string.h"
|
|
16
|
+
#include "Log.h"
|
|
17
|
+
|
|
18
|
+
namespace hku {
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @brief 过滤节点
|
|
22
|
+
*/
|
|
23
|
+
class FilterNode {
|
|
24
|
+
public:
|
|
25
|
+
FilterNode() = default;
|
|
26
|
+
FilterNode(const FilterNode&) = default;
|
|
27
|
+
virtual ~FilterNode() = default;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @brief 构造函数
|
|
31
|
+
* @param exclusive 是否排他。为 true 时,只执行第一个遇到的满足过滤条件的子节点
|
|
32
|
+
*/
|
|
33
|
+
explicit FilterNode(bool exclusive) : m_exclusive(exclusive) {}
|
|
34
|
+
|
|
35
|
+
FilterNode(FilterNode&& rv)
|
|
36
|
+
: m_value(std::move(rv.m_value)),
|
|
37
|
+
m_children(std::move(rv.m_children)),
|
|
38
|
+
m_exclusive(rv.m_exclusive) {}
|
|
39
|
+
|
|
40
|
+
FilterNode& operator=(const FilterNode& rv) {
|
|
41
|
+
if (this == &rv)
|
|
42
|
+
return *this;
|
|
43
|
+
m_value = rv.m_value;
|
|
44
|
+
m_children = rv.m_children;
|
|
45
|
+
m_exclusive = rv.m_exclusive;
|
|
46
|
+
return *this;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
FilterNode& operator=(FilterNode&& rv) {
|
|
50
|
+
if (this == &rv)
|
|
51
|
+
return *this;
|
|
52
|
+
m_value = std::move(rv.m_value);
|
|
53
|
+
m_children = std::move(rv.m_children);
|
|
54
|
+
m_exclusive = rv.m_exclusive;
|
|
55
|
+
return *this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
using ptr_t = std::shared_ptr<FilterNode>;
|
|
59
|
+
|
|
60
|
+
ptr_t addChild(const ptr_t& child) {
|
|
61
|
+
HKU_CHECK(child, "Invalid input child! child is null!");
|
|
62
|
+
m_children.push_front(child);
|
|
63
|
+
return child;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bool exclusive() const {
|
|
67
|
+
return m_exclusive;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
void exclusive(bool exclusive) {
|
|
71
|
+
m_exclusive = exclusive;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
using const_iterator = std::forward_list<ptr_t>::const_iterator;
|
|
75
|
+
using iterator = std::forward_list<ptr_t>::iterator;
|
|
76
|
+
const_iterator cbegin() const {
|
|
77
|
+
return m_children.cbegin();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const_iterator cend() const {
|
|
81
|
+
return m_children.cend();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
iterator begin() {
|
|
85
|
+
return m_children.begin();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
iterator end() {
|
|
89
|
+
return m_children.end();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
bool run(const any_t& data) noexcept {
|
|
93
|
+
if (_filter(data)) {
|
|
94
|
+
_process(data);
|
|
95
|
+
for (auto& node : m_children) {
|
|
96
|
+
if (node->run(data) && m_exclusive) {
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
virtual bool filter(const any_t& data) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
virtual void process(const any_t& data) {}
|
|
110
|
+
|
|
111
|
+
template <typename ValueT>
|
|
112
|
+
ValueT value() const {
|
|
113
|
+
return any_cast<ValueT>(m_value);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
template <typename ValueT>
|
|
117
|
+
void value(const ValueT& value) {
|
|
118
|
+
m_value = value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
bool has_value() const {
|
|
122
|
+
#if !HKU_OS_IOS && CPP_STANDARD >= CPP_STANDARD_17
|
|
123
|
+
return m_value.has_value();
|
|
124
|
+
#else
|
|
125
|
+
return !m_value.empty();
|
|
126
|
+
#endif
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
private:
|
|
130
|
+
bool _filter(const any_t& data) noexcept {
|
|
131
|
+
try {
|
|
132
|
+
return filter(data);
|
|
133
|
+
} catch (const std::exception& e) {
|
|
134
|
+
HKU_WARN("Node filter exist error! {}", e.what());
|
|
135
|
+
} catch (...) {
|
|
136
|
+
HKU_WARN("Node filter exist unknown error!");
|
|
137
|
+
}
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void _process(const any_t& data) noexcept {
|
|
142
|
+
try {
|
|
143
|
+
process(data);
|
|
144
|
+
} catch (const std::exception& e) {
|
|
145
|
+
HKU_WARN("Node process exist error! {}", e.what());
|
|
146
|
+
} catch (...) {
|
|
147
|
+
HKU_WARN("Node process exist unknown error!");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected:
|
|
152
|
+
any_t m_value;
|
|
153
|
+
|
|
154
|
+
private:
|
|
155
|
+
std::forward_list<ptr_t> m_children;
|
|
156
|
+
bool m_exclusive = false;
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
template <>
|
|
160
|
+
inline const any_t& FilterNode::value() const {
|
|
161
|
+
return m_value;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
typedef std::shared_ptr<FilterNode> FilterNodePtr;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @brief 绑定过滤节点,通过 std::function 绑定自定义的 filter 和 process 处理函数
|
|
168
|
+
*/
|
|
169
|
+
class BindFilterNode : public FilterNode {
|
|
170
|
+
public:
|
|
171
|
+
BindFilterNode() = default;
|
|
172
|
+
virtual ~BindFilterNode() = default;
|
|
173
|
+
|
|
174
|
+
using filter_func = std::function<bool(FilterNode*, const any_t&)>;
|
|
175
|
+
using process_func = std::function<void(FilterNode*, const any_t&)>;
|
|
176
|
+
|
|
177
|
+
explicit BindFilterNode(const process_func& process) : FilterNode(false), m_process(process) {}
|
|
178
|
+
explicit BindFilterNode(process_func&& process)
|
|
179
|
+
: FilterNode(false), m_process(std::move(process)) {}
|
|
180
|
+
|
|
181
|
+
BindFilterNode(const filter_func& filter, const process_func& process, bool exclusive = false)
|
|
182
|
+
: FilterNode(exclusive), m_filter(filter), m_process(process) {}
|
|
183
|
+
|
|
184
|
+
BindFilterNode(filter_func&& filter, process_func&& process, bool exclusive = false)
|
|
185
|
+
: FilterNode(exclusive), m_filter(std::move(filter)), m_process(std::move(process)) {}
|
|
186
|
+
|
|
187
|
+
virtual bool filter(const any_t& data) {
|
|
188
|
+
return m_filter ? m_filter(this, data) : true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
virtual void process(const any_t& data) {
|
|
192
|
+
if (m_process) {
|
|
193
|
+
m_process(this, data);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private:
|
|
198
|
+
filter_func m_filter;
|
|
199
|
+
process_func m_process;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* @brief 异步串行事件处理器
|
|
204
|
+
* @tparam EventT
|
|
205
|
+
*/
|
|
206
|
+
template <class EventT>
|
|
207
|
+
class AsyncSerialEventProcessor {
|
|
208
|
+
public:
|
|
209
|
+
/**
|
|
210
|
+
* @brief 构造函数
|
|
211
|
+
* @param quit_wait 退出时等待所有任务完成
|
|
212
|
+
*/
|
|
213
|
+
explicit AsyncSerialEventProcessor(bool quit_wait = true) : m_quit_wait(quit_wait) {
|
|
214
|
+
m_tg = std::unique_ptr<ThreadPool>(new ThreadPool(1));
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** 析构函数 */
|
|
218
|
+
virtual ~AsyncSerialEventProcessor() {
|
|
219
|
+
if (m_quit_wait) {
|
|
220
|
+
m_tg->join();
|
|
221
|
+
} else {
|
|
222
|
+
m_tg->stop();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* @brief 添加事件处理节点
|
|
228
|
+
*
|
|
229
|
+
* @param event 事件
|
|
230
|
+
* @param action 对应的处理节点
|
|
231
|
+
* @return 返回加入的节点
|
|
232
|
+
*/
|
|
233
|
+
FilterNodePtr addAction(const EventT& event, const FilterNodePtr& action) {
|
|
234
|
+
HKU_CHECK(action, "Input action is null!");
|
|
235
|
+
std::lock_guard<std::mutex> lock(m_mutex);
|
|
236
|
+
auto iter = m_trees.find(event);
|
|
237
|
+
if (iter != m_trees.end()) {
|
|
238
|
+
iter->second->addChild(action);
|
|
239
|
+
} else {
|
|
240
|
+
m_trees[event] = action;
|
|
241
|
+
}
|
|
242
|
+
return action;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @brief 分派事件消息
|
|
247
|
+
*
|
|
248
|
+
* @param event 事件
|
|
249
|
+
* @param data 事件附加信息
|
|
250
|
+
*/
|
|
251
|
+
void dispatch(const EventT& event, const any_t& data) {
|
|
252
|
+
m_tg->submit([=] {
|
|
253
|
+
auto iter = m_trees.find(event);
|
|
254
|
+
HKU_WARN_IF_RETURN(iter == m_trees.end(), void(),
|
|
255
|
+
"There is no matching handling method for the event({})!", event);
|
|
256
|
+
iter->second->run(data);
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
private:
|
|
261
|
+
mutable std::mutex m_mutex;
|
|
262
|
+
std::unordered_map<EventT, FilterNodePtr> m_trees;
|
|
263
|
+
std::unique_ptr<ThreadPool> m_tg;
|
|
264
|
+
bool m_quit_wait = true;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
} // namespace hku
|