hikyuu 2.6.3__py3-none-win_amd64.whl → 2.6.6__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 -0
- hikyuu/__init__.pyi +548 -546
- hikyuu/analysis/__init__.pyi +519 -514
- hikyuu/analysis/analysis.pyi +520 -515
- hikyuu/core.pyi +521 -516
- hikyuu/cpp/__init__.pyi +2 -2
- 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/core310.pyi +167 -36
- hikyuu/cpp/core311.pyd +0 -0
- hikyuu/cpp/core311.pyi +167 -36
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/core312.pyi +167 -36
- hikyuu/cpp/core313.pyd +0 -0
- hikyuu/cpp/core313.pyi +167 -36
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/core39.pyi +167 -36
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/hikyuu.lib +0 -0
- hikyuu/cpp/i18n/__init__.py +0 -0
- hikyuu/cpp/i18n/zh_CN.mo +0 -0
- hikyuu/cpp/sqlite3.dll +0 -0
- hikyuu/data/clickhouse_upgrade/__init__.py +1 -0
- hikyuu/data/clickhouse_upgrade/createdb.sql +1085 -0
- hikyuu/data/common.py +1 -1
- hikyuu/data/common_clickhouse.py +512 -0
- hikyuu/data/common_mysql.py +19 -0
- hikyuu/data/common_pytdx.py +2 -0
- hikyuu/data/common_sqlite3.py +1 -0
- hikyuu/data/em_block_to_clickhouse.py +120 -0
- hikyuu/data/hku_config_template.py +70 -1
- hikyuu/data/mysql_upgrade/0028.sql +95 -0
- hikyuu/data/pytdx_finance_to_clickhouse.py +107 -0
- hikyuu/data/pytdx_to_clickhouse.py +841 -0
- hikyuu/data/pytdx_to_h5.py +53 -13
- hikyuu/data/pytdx_to_mysql.py +42 -9
- hikyuu/data/pytdx_to_taos.py +736 -0
- hikyuu/data/pytdx_weight_to_clickhouse.py +191 -0
- hikyuu/data/sqlite_upgrade/0028.sql +97 -0
- hikyuu/data/tdx_to_clickhouse.py +448 -0
- hikyuu/data/zh_bond10_to_clickhouse.py +49 -0
- hikyuu/draw/__init__.pyi +1 -1
- hikyuu/draw/drawplot/__init__.pyi +8 -8
- hikyuu/draw/drawplot/bokeh_draw.pyi +538 -536
- hikyuu/draw/drawplot/common.pyi +1 -1
- hikyuu/draw/drawplot/echarts_draw.pyi +540 -538
- hikyuu/draw/drawplot/matplotlib_draw.py +7 -7
- hikyuu/draw/drawplot/matplotlib_draw.pyi +550 -548
- hikyuu/draw/elder.pyi +11 -11
- hikyuu/draw/kaufman.pyi +18 -18
- hikyuu/draw/volume.pyi +10 -10
- hikyuu/examples/notebook/001-overview.ipynb +65 -100
- hikyuu/examples/notebook/004-IndicatorOverview.ipynb +34 -32
- hikyuu/examples/notebook/007-SystemDetails.ipynb +64 -50
- hikyuu/examples/notebook/010-Portfolio.ipynb +120 -124
- hikyuu/extend.py +1 -1
- hikyuu/extend.pyi +527 -527
- hikyuu/fetcher/stock/zh_block_em.py +349 -5
- hikyuu/fetcher/stock/zh_stock_a_pytdx.py +11 -21
- hikyuu/fetcher/stock/zh_stock_a_qmt.py +4 -5
- hikyuu/fetcher/stock/zh_stock_a_sina_qq.py +16 -60
- hikyuu/flat/Spot.py +96 -200
- hikyuu/gui/HikyuuTDX.py +175 -23
- hikyuu/gui/data/ImportBlockInfoTask.py +12 -1
- hikyuu/gui/data/ImportHistoryFinanceTask.py +62 -44
- hikyuu/gui/data/ImportPytdxTimeToH5Task.py +14 -2
- hikyuu/gui/data/ImportPytdxToH5Task.py +17 -3
- hikyuu/gui/data/ImportPytdxTransToH5Task.py +14 -2
- hikyuu/gui/data/ImportTdxToH5Task.py +13 -1
- hikyuu/gui/data/ImportWeightToSqliteTask.py +16 -2
- hikyuu/gui/data/ImportZhBond10Task.py +12 -1
- hikyuu/gui/data/MainWindow.py +191 -110
- hikyuu/gui/data/UsePytdxImportToH5Thread.py +52 -29
- hikyuu/gui/data/UseQmtImportToH5Thread.py +1 -0
- hikyuu/gui/data/UseTdxImportToH5Thread.py +21 -2
- hikyuu/gui/dataserver.py +12 -4
- hikyuu/gui/spot_server.py +30 -40
- hikyuu/gui/start_qmt.py +20 -3
- hikyuu/hub.pyi +6 -6
- hikyuu/include/hikyuu/DataType.h +11 -0
- hikyuu/include/hikyuu/MarketInfo.h +6 -0
- hikyuu/include/hikyuu/StockManager.h +8 -0
- hikyuu/include/hikyuu/data_driver/BaseInfoDriver.h +35 -0
- hikyuu/include/hikyuu/data_driver/kdata/mysql/KRecordTable.h +1 -0
- hikyuu/include/hikyuu/global/GlobalSpotAgent.h +1 -1
- hikyuu/include/hikyuu/global/SpotRecord.h +15 -31
- hikyuu/include/hikyuu/global/agent/spot_generated.h +48 -232
- hikyuu/include/hikyuu/global/schedule/scheduler.h +1 -1
- hikyuu/include/hikyuu/indicator/build_in.h +1 -0
- hikyuu/include/hikyuu/indicator/crt/BARSLASTCOUNT.h +33 -0
- hikyuu/include/hikyuu/indicator/imp/IBarsLastCount.h +27 -0
- hikyuu/include/hikyuu/plugin/KDataToHdf5Importer.h +3 -0
- hikyuu/include/hikyuu/plugin/backtest.h +2 -2
- hikyuu/include/hikyuu/plugin/dataserver.h +26 -1
- hikyuu/include/hikyuu/plugin/device.h +8 -4
- hikyuu/include/hikyuu/plugin/interface/BackTestPluginInterface.h +1 -1
- hikyuu/include/hikyuu/plugin/interface/DataDriverPluginInterface.h +27 -0
- hikyuu/include/hikyuu/plugin/interface/DataServerPluginInterface.h +2 -1
- hikyuu/include/hikyuu/plugin/interface/DevicePluginInterface.h +2 -1
- hikyuu/include/hikyuu/plugin/interface/ImportKDataToHdf5PluginInterface.h +3 -0
- hikyuu/include/hikyuu/plugin/interface/TMReportPluginInterface.h +80 -0
- hikyuu/include/hikyuu/plugin/interface/plugins.h +4 -0
- hikyuu/include/hikyuu/strategy/Strategy.h +0 -9
- hikyuu/include/hikyuu/trade_manage/Performance.h +17 -9
- hikyuu/include/hikyuu/trade_manage/PositionExtInfo.h +92 -0
- hikyuu/include/hikyuu/trade_manage/PositionRecord.h +7 -1
- hikyuu/include/hikyuu/trade_manage/TradeManagerBase.h +60 -1
- hikyuu/include/hikyuu/trade_sys/selector/crt/SE_Optimal.h +8 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalEvaluateSelector.h +28 -0
- hikyuu/include/hikyuu/trade_sys/selector/imp/optimal/OptimalSelectorBase.h +1 -0
- hikyuu/include/hikyuu/utilities/DllLoader.h +226 -0
- hikyuu/include/hikyuu/utilities/config.h +1 -1
- hikyuu/include/hikyuu/utilities/datetime/Datetime.h +20 -0
- hikyuu/include/hikyuu/utilities/datetime/TimeDelta.h +6 -0
- hikyuu/include/hikyuu/utilities/mo/mo.h +30 -14
- hikyuu/include/hikyuu/utilities/os.h +6 -0
- hikyuu/include/hikyuu/utilities/plugin/PluginLoader.h +10 -10
- hikyuu/include/hikyuu/utilities/thread/MQThreadPool.h +13 -7
- hikyuu/include/hikyuu/utilities/thread/ThreadPool.h +13 -6
- hikyuu/include/hikyuu/version.h +4 -4
- 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/import2hdf5.dll +0 -0
- hikyuu/plugin/tmreport.dll +0 -0
- hikyuu/trade_manage/__init__.pyi +537 -535
- hikyuu/trade_manage/broker.pyi +3 -3
- hikyuu/trade_manage/broker_easytrader.pyi +1 -1
- hikyuu/trade_manage/trade.pyi +537 -535
- hikyuu/util/__init__.py +1 -0
- hikyuu/util/__init__.pyi +4 -3
- hikyuu/util/check.py +8 -0
- hikyuu/util/check.pyi +5 -1
- hikyuu/util/singleton.pyi +1 -1
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/METADATA +4 -3
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/RECORD +144 -123
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/top_level.txt +2 -2
- hikyuu/include/hikyuu/global/agent/hikyuu/__init__.py +0 -1
- hikyuu/include/hikyuu/global/agent/hikyuu/flat/__init__.py +0 -1
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/LICENSE +0 -0
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/WHEEL +0 -0
- {hikyuu-2.6.3.dist-info → hikyuu-2.6.6.dist-info}/entry_points.txt +0 -0
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
#include "DataServerPluginInterface.h"
|
|
13
13
|
#include "ImportKDataToHdf5PluginInterface.h"
|
|
14
14
|
#include "ExtendIndicatorsPluginInterface.h"
|
|
15
|
+
#include "TMReportPluginInterface.h"
|
|
16
|
+
#include "DataDriverPluginInterface.h"
|
|
15
17
|
|
|
16
18
|
namespace hku {
|
|
17
19
|
|
|
@@ -20,5 +22,7 @@ namespace hku {
|
|
|
20
22
|
#define HKU_PLUGIN_DATASERVER "dataserver"
|
|
21
23
|
#define HKU_PLUGIN_IMPORTKDATATOHDF5 "import2hdf5"
|
|
22
24
|
#define HKU_PLUGIN_EXTEND_INDICATOR "extind"
|
|
25
|
+
#define HKU_PLUGIN_TMREPORT "tmreport"
|
|
26
|
+
#define HKU_PLUGIN_CLICKHOUSE_DRIVER "clickhousedriver"
|
|
23
27
|
|
|
24
28
|
}
|
|
@@ -267,14 +267,5 @@ void HKU_API runInStrategy(const PFPtr& pf, const KQuery& query, const OrderBrok
|
|
|
267
267
|
const TradeCostPtr& costfunc,
|
|
268
268
|
const std::vector<OrderBrokerPtr>& other_brokers = {});
|
|
269
269
|
|
|
270
|
-
/**
|
|
271
|
-
* 从 hikyuu 数据缓存服务器拉取更新最新的缓存数据
|
|
272
|
-
* @param addr 缓存服务地址,如: tcp://192.168.1.1:9201
|
|
273
|
-
* @param stklist 待更新的股票列表
|
|
274
|
-
* @param ktype 指定更新的K线类型
|
|
275
|
-
*/
|
|
276
|
-
void HKU_API getDataFromBufferServer(const std::string& addr, const StockList& stklist,
|
|
277
|
-
const KQuery::KType& ktype);
|
|
278
|
-
|
|
279
270
|
/** @} */
|
|
280
271
|
} // namespace hku
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
#define PERFORMANCE_H_
|
|
11
11
|
|
|
12
12
|
#include <boost/function.hpp>
|
|
13
|
-
#include "
|
|
13
|
+
#include "TradeManagerBase.h"
|
|
14
14
|
|
|
15
15
|
namespace hku {
|
|
16
16
|
|
|
@@ -23,14 +23,15 @@ public:
|
|
|
23
23
|
Performance();
|
|
24
24
|
virtual ~Performance();
|
|
25
25
|
|
|
26
|
-
Performance(const Performance& other)
|
|
27
|
-
Performance(Performance&& other)
|
|
26
|
+
Performance(const Performance& other) = default;
|
|
27
|
+
Performance(Performance&& other)
|
|
28
|
+
: m_result(std::move(other.m_result)), m_keys(std::move(other.m_keys)) {}
|
|
28
29
|
|
|
29
30
|
Performance& operator=(const Performance& other);
|
|
30
31
|
Performance& operator=(Performance&& other);
|
|
31
32
|
|
|
32
33
|
/** 是否为合法的统计项 */
|
|
33
|
-
|
|
34
|
+
bool exist(const string& key);
|
|
34
35
|
|
|
35
36
|
/** 复位,清除已计算的结果 */
|
|
36
37
|
void reset();
|
|
@@ -44,12 +45,12 @@ public:
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
-
* @
|
|
48
|
+
* 简单的文本统计报告,用于直接输出打印。
|
|
49
|
+
* @note 只有运行 statistics 后或 Performance 本身为从 TM 获取的结果时才生效
|
|
49
50
|
* @param datetime 指定的截止时刻
|
|
50
51
|
* @return
|
|
51
52
|
*/
|
|
52
|
-
string report(
|
|
53
|
+
string report();
|
|
53
54
|
|
|
54
55
|
/**
|
|
55
56
|
* 根据交易记录,统计截至某一时刻的系统绩效, datetime必须大于等于lastDatetime,
|
|
@@ -61,7 +62,7 @@ public:
|
|
|
61
62
|
|
|
62
63
|
/** 获取所有统计项名称,顺序与 values 相同 */
|
|
63
64
|
const StringList& names() const {
|
|
64
|
-
return
|
|
65
|
+
return m_keys;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
/** 获取所有统计项值,顺序与 names 相同*/
|
|
@@ -71,9 +72,16 @@ public:
|
|
|
71
72
|
typedef map_type::iterator iterator;
|
|
72
73
|
typedef map_type::const_iterator const_iterator;
|
|
73
74
|
|
|
75
|
+
const map_type& getAll() const {
|
|
76
|
+
return m_result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void addKey(const string& key);
|
|
80
|
+
void setValue(const string& key, double value);
|
|
81
|
+
|
|
74
82
|
private:
|
|
75
83
|
map_type m_result;
|
|
76
|
-
|
|
84
|
+
StringList m_keys; // 保存统计项顺序, map/unordered_map都不能保持按插入顺序遍历
|
|
77
85
|
};
|
|
78
86
|
|
|
79
87
|
} /* namespace hku */
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-05-30
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "PositionRecord.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
// 持仓扩展信息(只适合一买一卖的情况,一买多卖的情况,部分统计不准确仅供参考)
|
|
14
|
+
struct HKU_API PositionExtInfo final {
|
|
15
|
+
PositionRecord position;
|
|
16
|
+
price_t maxHighPrice{0.}; // 期间最高价最大值
|
|
17
|
+
price_t minLowPrice{0.0}; // 期间最低价最小值
|
|
18
|
+
price_t maxClosePrice{0.}; // 期间收盘价最高值
|
|
19
|
+
price_t minClosePrice{0.0}; // 期间收盘价最低值
|
|
20
|
+
price_t currentClosePrice{0.}; // 当前收盘价
|
|
21
|
+
price_t maxPullBack1{0.}; // 最大回撤百分比1(仅使用最大收盘价和最低收盘价计算)(负数)
|
|
22
|
+
price_t maxPullBack2{0.}; // 最大回撤百分比2(使用期间最高价最大值和最低价最小值计算)(负数)
|
|
23
|
+
price_t currentProfit{0.}; // 当前浮动盈亏(不含预计卖出成本)
|
|
24
|
+
|
|
25
|
+
/** 当前回撤百分比1(仅使用最大收盘价和当前收盘价计算) */
|
|
26
|
+
price_t currentPullBack1() const {
|
|
27
|
+
price_t ret = (maxClosePrice - currentClosePrice) / maxClosePrice;
|
|
28
|
+
return ret > 0. ? 0. : ret;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 当前回撤百分比2(使用期间最高价最大值和当前收盘价计算) */
|
|
32
|
+
price_t currentPullBack2() const {
|
|
33
|
+
price_t ret = (maxHighPrice - currentClosePrice) / maxHighPrice;
|
|
34
|
+
return ret > 0. ? 0. : ret;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 期间最大浮盈1 (正数, 仅使用收盘价计算, 不含预计卖出成本, 多次买卖时统计不准) */
|
|
38
|
+
price_t maxFloatingProfit1() const {
|
|
39
|
+
price_t ret = maxClosePrice * position.number + position.sellMoney - position.buyMoney;
|
|
40
|
+
return ret < 0. ? 0. : ret;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** 期间最大浮盈2 (正数, 使用最高值最大值进行计算,不含预计卖出成本,多次买卖时统计不准) */
|
|
44
|
+
price_t maxFloatingProfit2() const {
|
|
45
|
+
price_t ret = maxHighPrice * position.number + position.sellMoney - position.buyMoney;
|
|
46
|
+
return ret < 0. ? 0. : ret;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 期间最大浮亏1(负数,仅使用收盘价计算, 不含预计卖出成本,多次买卖时统计不准) */
|
|
50
|
+
price_t minLossProfit1() const {
|
|
51
|
+
price_t ret = minClosePrice * position.number + position.sellMoney - position.buyMoney;
|
|
52
|
+
return ret > 0. ? 0. : ret;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** 期间最大浮亏2(负数,仅期间最低价计算, 不含预计卖出成本,多次买卖时统计不准) */
|
|
56
|
+
price_t minLossProfit2() const {
|
|
57
|
+
price_t ret = minLowPrice * position.number + position.sellMoney - position.buyMoney;
|
|
58
|
+
return ret > 0. ? 0. : ret;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
PositionExtInfo() = default;
|
|
62
|
+
PositionExtInfo(const PositionExtInfo&) = default;
|
|
63
|
+
PositionExtInfo& operator=(const PositionExtInfo&) = default;
|
|
64
|
+
|
|
65
|
+
PositionExtInfo(PositionExtInfo&& rhs)
|
|
66
|
+
: position(std::move(rhs.position)),
|
|
67
|
+
maxHighPrice(rhs.maxHighPrice),
|
|
68
|
+
minLowPrice(rhs.minLowPrice),
|
|
69
|
+
maxClosePrice(rhs.maxClosePrice),
|
|
70
|
+
minClosePrice(rhs.minClosePrice),
|
|
71
|
+
currentClosePrice(rhs.currentClosePrice),
|
|
72
|
+
maxPullBack1(rhs.maxPullBack1),
|
|
73
|
+
maxPullBack2(rhs.maxPullBack2),
|
|
74
|
+
currentProfit(rhs.currentProfit) {}
|
|
75
|
+
|
|
76
|
+
PositionExtInfo& operator=(PositionExtInfo&& rhs) {
|
|
77
|
+
if (this != &rhs) {
|
|
78
|
+
position = std::move(rhs.position);
|
|
79
|
+
maxHighPrice = rhs.maxHighPrice;
|
|
80
|
+
minLowPrice = rhs.minLowPrice;
|
|
81
|
+
maxClosePrice = rhs.maxClosePrice;
|
|
82
|
+
minClosePrice = rhs.minClosePrice;
|
|
83
|
+
currentClosePrice = rhs.currentClosePrice;
|
|
84
|
+
maxPullBack1 = rhs.maxPullBack1;
|
|
85
|
+
maxPullBack2 = rhs.maxPullBack2;
|
|
86
|
+
currentProfit = rhs.currentProfit;
|
|
87
|
+
}
|
|
88
|
+
return *this;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
} // namespace hku
|
|
@@ -25,11 +25,17 @@ public:
|
|
|
25
25
|
double number, price_t stoploss, price_t goalPrice, double totalNumber,
|
|
26
26
|
price_t buyMoney, price_t totalCost, price_t totalRisk, price_t sellMoney);
|
|
27
27
|
|
|
28
|
+
PositionRecord(const PositionRecord& ths) = default;
|
|
29
|
+
PositionRecord& operator=(const PositionRecord& ths) = default;
|
|
30
|
+
|
|
31
|
+
PositionRecord(PositionRecord&& rhs);
|
|
32
|
+
PositionRecord& operator=(PositionRecord&& rhs);
|
|
33
|
+
|
|
28
34
|
/** 仅用于python的__str__ */
|
|
29
35
|
string str() const;
|
|
30
36
|
|
|
31
37
|
/**
|
|
32
|
-
* @brief 盈亏 =
|
|
38
|
+
* @brief 盈亏 = 卖出资金 - 累计交易总成本 - 买入资金
|
|
33
39
|
* @note 只对已清仓的记录有效,未清仓将返回0.0
|
|
34
40
|
*/
|
|
35
41
|
price_t totalProfit() const;
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "../utilities/Parameter.h"
|
|
11
11
|
#include "TradeRecord.h"
|
|
12
12
|
#include "PositionRecord.h"
|
|
13
|
+
#include "PositionExtInfo.h"
|
|
13
14
|
#include "BorrowRecord.h"
|
|
14
15
|
#include "FundsRecord.h"
|
|
15
16
|
#include "LoanRecord.h"
|
|
@@ -19,6 +20,8 @@
|
|
|
19
20
|
|
|
20
21
|
namespace hku {
|
|
21
22
|
|
|
23
|
+
class HKU_API Performance;
|
|
24
|
+
|
|
22
25
|
/**
|
|
23
26
|
* 账户交易管理基类,管理帐户的交易记录及资金使用情况
|
|
24
27
|
* @details
|
|
@@ -28,7 +31,7 @@ namespace hku {
|
|
|
28
31
|
* </pre>
|
|
29
32
|
* @ingroup TradeManagerClass
|
|
30
33
|
*/
|
|
31
|
-
class HKU_API TradeManagerBase {
|
|
34
|
+
class HKU_API TradeManagerBase : public enable_shared_from_this<TradeManagerBase> {
|
|
32
35
|
PARAMETER_SUPPORT_WITH_CHECK
|
|
33
36
|
|
|
34
37
|
public:
|
|
@@ -706,6 +709,62 @@ public:
|
|
|
706
709
|
HKU_WARN("The subclass does not implement this method");
|
|
707
710
|
}
|
|
708
711
|
|
|
712
|
+
//-------------------------------------------------------------
|
|
713
|
+
// 以下为可能需要授权的功能
|
|
714
|
+
//-------------------------------------------------------------
|
|
715
|
+
/**
|
|
716
|
+
* 统计截至某一时刻的系统绩效, datetime必须大于等于lastDatetime,
|
|
717
|
+
* 以便用于计算当前市值
|
|
718
|
+
* @param datetime 统计截止时刻
|
|
719
|
+
*/
|
|
720
|
+
Performance getPerformance(const Datetime& datetime = Datetime::now(),
|
|
721
|
+
const KQuery::KType& ktype = KQuery::DAY);
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* @brief 获取指定时刻时账户的最大回撤百分比(负数)(仅根据收盘价计算)
|
|
725
|
+
* @param tm 指定账户
|
|
726
|
+
* @param date 指定日期(包含该时刻)
|
|
727
|
+
* @param ktype k线类型
|
|
728
|
+
* @return price_t
|
|
729
|
+
*/
|
|
730
|
+
price_t getMaxPullBack(const Datetime& date, const KQuery::KType& ktype = KQuery::DAY);
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* @brief 获取账户历史持仓扩展详情
|
|
734
|
+
* @param ktype k线类型
|
|
735
|
+
* @param trade_mode 交易模式,影响部分统计项: 0-收盘时交易, 1-下一开盘时交易
|
|
736
|
+
* @return std::vector<PositionExtInfo>
|
|
737
|
+
*/
|
|
738
|
+
std::vector<PositionExtInfo> getHistoryPositionExtInfoList(
|
|
739
|
+
const KQuery::KType& ktype = KQuery::DAY, int trade_mode = 0);
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* @brief 获取账户最后交易时刻后持仓详情
|
|
743
|
+
* @param current_time 当前时刻(需大于等于最后交易时刻)
|
|
744
|
+
* @param ktype k线类型
|
|
745
|
+
* @param trade_mode 交易模式,影响部分统计项: 0-收盘时交易, 1-下一开盘时交易
|
|
746
|
+
* @return std::vector<PositionExtInfo>
|
|
747
|
+
*/
|
|
748
|
+
std::vector<PositionExtInfo> getPositionExtInfoList(
|
|
749
|
+
const Datetime& current_time = Datetime::now(), const KQuery::KType& ktype = KQuery::DAY,
|
|
750
|
+
int trade_mode = 0);
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* @brief 获取指定截止时间前各月的收益百分比
|
|
754
|
+
* @param datetime
|
|
755
|
+
* @return std::vector<std::pair<Datetime, double>>
|
|
756
|
+
*/
|
|
757
|
+
std::vector<std::pair<Datetime, double>> getProfitPercentMonthly(
|
|
758
|
+
const Datetime& datetime = Datetime::now());
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* @brief 获取指定截止时间前各年的收益百分比
|
|
762
|
+
* @param datetime
|
|
763
|
+
* @return std::vector<std::pair<Datetime, double>>
|
|
764
|
+
*/
|
|
765
|
+
std::vector<std::pair<Datetime, double>> getProfitPercentYearly(
|
|
766
|
+
const Datetime& datetime = Datetime::now());
|
|
767
|
+
|
|
709
768
|
protected:
|
|
710
769
|
string m_name; // 账户名称
|
|
711
770
|
TradeCostPtr m_costfunc; // 成本算法
|
|
@@ -23,4 +23,12 @@ SEPtr HKU_API SE_MaxFundsOptimal();
|
|
|
23
23
|
*/
|
|
24
24
|
SEPtr HKU_API SE_PerformanceOptimal(const string& key = "帐户平均年收益率%", int mode = 0);
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* 使用自定义评估函数进行寻优的选择器
|
|
28
|
+
* @param evaluate
|
|
29
|
+
* @return SEPtr
|
|
30
|
+
*/
|
|
31
|
+
SEPtr HKU_API
|
|
32
|
+
SE_EvaluateOptimal(std::function<double(const SystemPtr&, const Datetime&)>&& evaluate);
|
|
33
|
+
|
|
26
34
|
} // namespace hku
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2024 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2024-09-22
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "OptimalSelectorBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class OptimalEvaluateSelector : public OptimalSelectorBase {
|
|
15
|
+
OPTIMAL_SELECTOR_IMP(OptimalEvaluateSelector)
|
|
16
|
+
OPTIMAL_SELECTOR_NO_PRIVATE_MEMBER_SERIALIZATION
|
|
17
|
+
|
|
18
|
+
public:
|
|
19
|
+
OptimalEvaluateSelector();
|
|
20
|
+
OptimalEvaluateSelector(std::function<double(const SystemPtr&, const Datetime&)>&& evaluate);
|
|
21
|
+
|
|
22
|
+
virtual ~OptimalEvaluateSelector();
|
|
23
|
+
|
|
24
|
+
private:
|
|
25
|
+
std::function<double(const SystemPtr&, const Datetime&)> m_evaluate;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
} // namespace hku
|
|
@@ -43,6 +43,7 @@ public:
|
|
|
43
43
|
// 以便继承子类只需要实现 _clone 和 该接口即可
|
|
44
44
|
// 该接口实现系统绩效评估,getSelected 时将取评估结果最大的系统
|
|
45
45
|
// 使用 std::function 的话,在 C++ 中无法序列化,所以使用继承
|
|
46
|
+
// 返回 Null<double> 时,将不被评估选中
|
|
46
47
|
virtual double evaluate(const SYSPtr& sys, const Datetime& endDate) noexcept {
|
|
47
48
|
return Null<double>();
|
|
48
49
|
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-03-18
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
#ifndef HKU_UTILS_DLL_LOADER_H_
|
|
10
|
+
#define HKU_UTILS_DLL_LOADER_H_
|
|
11
|
+
|
|
12
|
+
#include <string>
|
|
13
|
+
#include <vector>
|
|
14
|
+
#include <cstdlib>
|
|
15
|
+
#include "hikyuu/utilities/config.h"
|
|
16
|
+
#include "hikyuu/utilities/osdef.h"
|
|
17
|
+
#include "hikyuu/utilities/os.h"
|
|
18
|
+
#include "hikyuu/utilities/Log.h"
|
|
19
|
+
#include "hikyuu/utilities/arithmetic.h"
|
|
20
|
+
|
|
21
|
+
#if HKU_OS_WINDOWS
|
|
22
|
+
#include <windows.h>
|
|
23
|
+
#else
|
|
24
|
+
#include <dlfcn.h>
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
namespace hku {
|
|
28
|
+
|
|
29
|
+
class DllLoader {
|
|
30
|
+
public:
|
|
31
|
+
DllLoader() {
|
|
32
|
+
initDefaultSearchPath();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
explicit DllLoader(const std::vector<std::string>& path) {
|
|
36
|
+
if (!path.empty()) {
|
|
37
|
+
m_search_paths.resize(path.size());
|
|
38
|
+
std::copy(path.begin(), path.end(), m_search_paths.begin());
|
|
39
|
+
} else {
|
|
40
|
+
HKU_WARN("DllLoader: empty search path! Use default search path!");
|
|
41
|
+
initDefaultSearchPath();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
DllLoader(const DllLoader&) = delete;
|
|
46
|
+
DllLoader& operator=(const DllLoader&) = delete;
|
|
47
|
+
|
|
48
|
+
DllLoader(DllLoader&& rhs)
|
|
49
|
+
: m_handle(rhs.m_handle), m_search_paths(std::move(rhs.m_search_paths)) {
|
|
50
|
+
rhs.m_handle = nullptr;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
DllLoader& operator=(DllLoader&& rhs) {
|
|
54
|
+
if (this == &rhs) {
|
|
55
|
+
m_handle = rhs.m_handle;
|
|
56
|
+
m_search_paths = std::move(rhs.m_search_paths);
|
|
57
|
+
rhs.m_handle = nullptr;
|
|
58
|
+
}
|
|
59
|
+
return *this;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
virtual ~DllLoader() {
|
|
63
|
+
unload();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
bool load(const std::string& dllname) noexcept {
|
|
67
|
+
std::string filename = search(dllname);
|
|
68
|
+
HKU_WARN_IF_RETURN(filename.empty(), false, "Not found dll: {}!", dllname);
|
|
69
|
+
|
|
70
|
+
#if HKU_OS_WINDOWS
|
|
71
|
+
m_handle = LoadLibrary(HKU_PATH(filename).c_str());
|
|
72
|
+
#else
|
|
73
|
+
m_handle = dlopen(filename.c_str(), RTLD_LAZY);
|
|
74
|
+
#endif
|
|
75
|
+
HKU_WARN_IF_RETURN(!m_handle, false, "load dll({}) failed!", filename);
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void unload() noexcept {
|
|
80
|
+
if (m_handle) {
|
|
81
|
+
#if HKU_OS_WINDOWS
|
|
82
|
+
FreeLibrary(m_handle);
|
|
83
|
+
#else
|
|
84
|
+
dlclose(m_handle);
|
|
85
|
+
#endif
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
std::string search(const std::string& dllname) const noexcept {
|
|
90
|
+
#if HKU_OS_WINDOWS
|
|
91
|
+
std::string dll = fmt::format("{}.dll", dllname);
|
|
92
|
+
#elif HKU_OS_OSX
|
|
93
|
+
std::string dll = fmt::format("lib{}.dylib", dllname);
|
|
94
|
+
#else
|
|
95
|
+
std::string dll = fmt::format("lib{}.so", dllname);
|
|
96
|
+
#endif
|
|
97
|
+
for (const auto& path : m_search_paths) {
|
|
98
|
+
auto filename = fmt::format("{}/{}", path, dll);
|
|
99
|
+
if (existFile(filename)) {
|
|
100
|
+
return filename;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return std::string();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
void* getSymbol(const char* symbol) noexcept {
|
|
108
|
+
#if HKU_OS_WINDOWS
|
|
109
|
+
void* func = GetProcAddress(m_handle, symbol);
|
|
110
|
+
#else
|
|
111
|
+
void* func = dlsym(m_handle, symbol);
|
|
112
|
+
#endif
|
|
113
|
+
return func;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private:
|
|
117
|
+
void initDefaultSearchPath() noexcept {
|
|
118
|
+
m_search_paths.emplace_back(".");
|
|
119
|
+
|
|
120
|
+
std::string userdir = getUserDir();
|
|
121
|
+
if (!userdir.empty()) {
|
|
122
|
+
m_search_paths.emplace_back(userdir + "/lib");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
#if HKU_OS_WINDOWS
|
|
126
|
+
m_search_paths.emplace_back("C:/Windows/System32");
|
|
127
|
+
m_search_paths.emplace_back("C:/Windows/SysWOW64");
|
|
128
|
+
m_search_paths.emplace_back("C:/Windows");
|
|
129
|
+
const char* path = getenv("PATH");
|
|
130
|
+
if (path) {
|
|
131
|
+
std::string pathstr(path);
|
|
132
|
+
auto items = split(pathstr, ";");
|
|
133
|
+
for (auto& item : items) {
|
|
134
|
+
std::string nitem(item);
|
|
135
|
+
trim(nitem);
|
|
136
|
+
if (!item.empty()) {
|
|
137
|
+
m_search_paths.emplace_back(nitem);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#elif HKU_OS_OSX
|
|
143
|
+
const char* path = getenv("DYLD_IMAGE_SUFFIX");
|
|
144
|
+
if (path) {
|
|
145
|
+
std::string pathstr(path);
|
|
146
|
+
auto items = split(pathstr, ";");
|
|
147
|
+
for (auto& item : items) {
|
|
148
|
+
std::string nitem(item);
|
|
149
|
+
trim(nitem);
|
|
150
|
+
if (!item.empty()) {
|
|
151
|
+
m_search_paths.emplace_back(nitem);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
path = getenv("DYLD_FRAMEWORK_PATH");
|
|
156
|
+
if (path) {
|
|
157
|
+
std::string pathstr(path);
|
|
158
|
+
auto items = split(pathstr, ";");
|
|
159
|
+
for (auto& item : items) {
|
|
160
|
+
std::string nitem(item);
|
|
161
|
+
trim(nitem);
|
|
162
|
+
if (!item.empty()) {
|
|
163
|
+
m_search_paths.emplace_back(nitem);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
path = getenv("DYLD_LIBRARY_PATH");
|
|
168
|
+
if (path) {
|
|
169
|
+
std::string pathstr(path);
|
|
170
|
+
auto items = split(pathstr, ";");
|
|
171
|
+
for (auto& item : items) {
|
|
172
|
+
std::string nitem(item);
|
|
173
|
+
trim(nitem);
|
|
174
|
+
if (!item.empty()) {
|
|
175
|
+
m_search_paths.emplace_back(nitem);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
m_search_paths.emplace_back("/Library/Frameworks");
|
|
180
|
+
m_search_paths.emplace_back("/Network/Library/Frameworks");
|
|
181
|
+
m_search_paths.emplace_back("/System/Library/Frameworks");
|
|
182
|
+
m_search_paths.emplace_back("/usr/local/lib");
|
|
183
|
+
m_search_paths.emplace_back("/usr/lib");
|
|
184
|
+
m_search_paths.emplace_back("/lib");
|
|
185
|
+
|
|
186
|
+
#else
|
|
187
|
+
const char* path = getenv("LD_LIBRARY_PATH");
|
|
188
|
+
if (path) {
|
|
189
|
+
std::string pathstr(path);
|
|
190
|
+
auto items = split(pathstr, ";");
|
|
191
|
+
for (auto& item : items) {
|
|
192
|
+
std::string nitem(item);
|
|
193
|
+
trim(nitem);
|
|
194
|
+
if (!item.empty()) {
|
|
195
|
+
m_search_paths.emplace_back(nitem);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
m_search_paths.emplace_back("/usr/local/lib");
|
|
200
|
+
m_search_paths.emplace_back("/usr/lib");
|
|
201
|
+
m_search_paths.emplace_back("/lib");
|
|
202
|
+
if (HKU_ARCH_X64) {
|
|
203
|
+
m_search_paths.emplace_back("/usr/lib/x86_64-linux-gnu");
|
|
204
|
+
} else if (HKU_ARCH_ARM64) {
|
|
205
|
+
m_search_paths.emplace_back("/usr/lib/aarch64-linux-gnu");
|
|
206
|
+
} else if (HKU_ARCH_X86) {
|
|
207
|
+
m_search_paths.emplace_back("/usr/lib/i386-linux-gnu");
|
|
208
|
+
} else if (HKU_ARCH_ARM) {
|
|
209
|
+
m_search_paths.emplace_back("/usr/lib/arm-linux-gnueabihf");
|
|
210
|
+
}
|
|
211
|
+
#endif
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private:
|
|
215
|
+
#if HKU_OS_WINDOWS
|
|
216
|
+
HMODULE m_handle{nullptr};
|
|
217
|
+
#else
|
|
218
|
+
void* m_handle{nullptr};
|
|
219
|
+
#endif
|
|
220
|
+
|
|
221
|
+
std::vector<std::string> m_search_paths;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
} // namespace hku
|
|
225
|
+
|
|
226
|
+
#endif /* HKU_UTILS_DLL_LOADER_H_ */
|
|
@@ -62,6 +62,20 @@ public:
|
|
|
62
62
|
*/
|
|
63
63
|
static Datetime fromHex(uint64_t time);
|
|
64
64
|
|
|
65
|
+
/**
|
|
66
|
+
* @brief 从时间戳(微秒)创建Datetime对象
|
|
67
|
+
* @param timestamp 微妙级别的时间戳(从1970年1月1日0时0分0秒开始)
|
|
68
|
+
* @return Datetime
|
|
69
|
+
*/
|
|
70
|
+
static Datetime fromTimestamp(int64_t timestamp);
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @brief 从时间戳(微秒)创建Datetime对象,并加上本地UTC时间偏差
|
|
74
|
+
* @param timestamp 微妙级别的时间戳(从1970年1月1日0时0分0秒开始)
|
|
75
|
+
* @return Datetime
|
|
76
|
+
*/
|
|
77
|
+
static Datetime fromTimestampUTC(int64_t timestamp);
|
|
78
|
+
|
|
65
79
|
public:
|
|
66
80
|
/** 默认构造函数,Null<Datetime> */
|
|
67
81
|
Datetime();
|
|
@@ -178,6 +192,12 @@ public:
|
|
|
178
192
|
/** 距离最小日期过去的微秒数 */
|
|
179
193
|
uint64_t ticks() const noexcept;
|
|
180
194
|
|
|
195
|
+
/** 时间戳,距离1970-01-01 00:00:00的微秒数 */
|
|
196
|
+
int64_t timestamp() const noexcept;
|
|
197
|
+
|
|
198
|
+
/** 时间戳,距离1970-01-01 00:00:00的微秒数, 并扣除本地 UTC 偏差时间 */
|
|
199
|
+
int64_t timestampUTC() const noexcept;
|
|
200
|
+
|
|
181
201
|
/**
|
|
182
202
|
* 转化为字符串,供打印阅读,格式:
|
|
183
203
|
* <pre>
|
|
@@ -316,6 +316,12 @@ inline TimeDelta Microseconds(int64_t microsecs) {
|
|
|
316
316
|
return TimeDelta::fromTicks(microsecs);
|
|
317
317
|
}
|
|
318
318
|
|
|
319
|
+
/**
|
|
320
|
+
* 获取当前 UTC 时间偏移
|
|
321
|
+
* @return TimeDelta
|
|
322
|
+
*/
|
|
323
|
+
TimeDelta HKU_UTILS_API UTCOffset();
|
|
324
|
+
|
|
319
325
|
} /* namespace hku */
|
|
320
326
|
|
|
321
327
|
namespace std {
|