hikyuu 2.6.5__py3-none-win_amd64.whl → 2.6.7__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 +16 -0
- hikyuu/__init__.pyi +484 -474
- hikyuu/analysis/__init__.pyi +466 -445
- hikyuu/analysis/analysis.pyi +467 -446
- hikyuu/core.pyi +468 -447
- 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 +1070 -878
- hikyuu/cpp/core311.pyd +0 -0
- hikyuu/cpp/core311.pyi +1070 -878
- hikyuu/cpp/core312.pyd +0 -0
- hikyuu/cpp/core312.pyi +1070 -878
- hikyuu/cpp/core313.pyd +0 -0
- hikyuu/cpp/core313.pyi +1070 -876
- hikyuu/cpp/core39.pyd +0 -0
- hikyuu/cpp/core39.pyi +1070 -878
- hikyuu/cpp/hikyuu.dll +0 -0
- hikyuu/cpp/hikyuu.lib +0 -0
- hikyuu/cpp/i18n/__init__.py +0 -0
- hikyuu/cpp/i18n/zh_CN/__init__.py +0 -0
- hikyuu/cpp/i18n/zh_CN/hikyuu.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_clickhouse.py +465 -0
- hikyuu/data/em_block_to_clickhouse.py +120 -0
- hikyuu/data/hku_config_template.py +58 -3
- hikyuu/data/pytdx_finance_to_clickhouse.py +107 -0
- hikyuu/data/pytdx_to_clickhouse.py +841 -0
- hikyuu/data/pytdx_to_mysql.py +4 -4
- hikyuu/data/pytdx_weight_to_clickhouse.py +191 -0
- hikyuu/data/tdx_to_clickhouse.py +448 -0
- hikyuu/data/tdx_to_h5.py +1 -1
- hikyuu/data/zh_bond10_to_clickhouse.py +49 -0
- hikyuu/draw/__init__.pyi +1 -1
- hikyuu/draw/drawplot/bokeh_draw.pyi +479 -471
- hikyuu/draw/drawplot/echarts_draw.py +9 -8
- hikyuu/draw/drawplot/echarts_draw.pyi +479 -471
- hikyuu/draw/drawplot/matplotlib_draw.py +3 -3
- hikyuu/draw/drawplot/matplotlib_draw.pyi +479 -471
- hikyuu/draw/elder.pyi +6 -6
- hikyuu/draw/kaufman.py +1 -1
- hikyuu/draw/kaufman.pyi +10 -10
- hikyuu/draw/volume.pyi +5 -5
- hikyuu/examples/notebook/000-Index.ipynb +1 -1
- hikyuu/examples/notebook/001-overview.ipynb +78 -63
- hikyuu/examples/notebook/002-HowToGetStock.ipynb +259 -40
- hikyuu/examples/notebook/003-HowToGetKDataAndDraw.ipynb +49 -41
- hikyuu/examples/notebook/004-IndicatorOverview.ipynb +29 -29
- hikyuu/examples/notebook/005-Drawplot.ipynb +66 -37
- hikyuu/examples/notebook/006-TradeManager.ipynb +808 -61
- hikyuu/examples/notebook/007-SystemDetails.ipynb +23 -23
- hikyuu/examples/notebook/009-RealData.ipynb +3 -3
- hikyuu/examples/notebook/010-Portfolio.ipynb +761 -122
- hikyuu/extend.py +15 -100
- hikyuu/extend.pyi +478 -493
- hikyuu/fetcher/stock/zh_stock_a_pytdx.py +9 -20
- 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 +134 -7
- hikyuu/gui/data/ImportBlockInfoTask.py +11 -0
- hikyuu/gui/data/ImportHistoryFinanceTask.py +15 -1
- hikyuu/gui/data/ImportPytdxTimeToH5Task.py +11 -1
- hikyuu/gui/data/ImportPytdxToH5Task.py +13 -1
- hikyuu/gui/data/ImportPytdxTransToH5Task.py +11 -1
- hikyuu/gui/data/ImportTdxToH5Task.py +13 -1
- hikyuu/gui/data/ImportWeightToSqliteTask.py +14 -1
- hikyuu/gui/data/ImportZhBond10Task.py +11 -0
- hikyuu/gui/data/MainWindow.py +210 -135
- hikyuu/gui/data/UsePytdxImportToH5Thread.py +45 -26
- hikyuu/gui/data/UseTdxImportToH5Thread.py +19 -1
- 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 +2 -0
- hikyuu/include/hikyuu/KQuery.h +22 -28
- hikyuu/include/hikyuu/MarketInfo.h +1 -1
- hikyuu/include/hikyuu/Stock.h +15 -3
- hikyuu/include/hikyuu/StockManager.h +12 -3
- hikyuu/include/hikyuu/StockTypeInfo.h +6 -0
- hikyuu/include/hikyuu/TransRecord.h +2 -8
- hikyuu/include/hikyuu/data_driver/kdata/mysql/KRecordTable.h +1 -0
- hikyuu/include/hikyuu/doc.h +4 -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/Indicator.h +37 -0
- hikyuu/include/hikyuu/lang.h +27 -0
- hikyuu/include/hikyuu/plugin/KDataToHdf5Importer.h +9 -1
- hikyuu/include/hikyuu/plugin/dataserver.h +26 -1
- hikyuu/include/hikyuu/plugin/device.h +2 -1
- hikyuu/include/hikyuu/plugin/hkuextra.h +56 -0
- 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 +1 -1
- hikyuu/include/hikyuu/plugin/interface/HkuExtraPluginInterface.h +38 -0
- hikyuu/include/hikyuu/plugin/interface/ImportKDataToHdf5PluginInterface.h +13 -1
- hikyuu/include/hikyuu/plugin/interface/plugins.h +4 -0
- hikyuu/include/hikyuu/python/pybind_utils.h +9 -0
- hikyuu/include/hikyuu/strategy/Strategy.h +0 -9
- hikyuu/include/hikyuu/trade_manage/TradeRecord.h +1 -1
- hikyuu/include/hikyuu/utilities/config.h +0 -2
- hikyuu/include/hikyuu/utilities/os.h +9 -0
- hikyuu/include/hikyuu/utilities/plugin/PluginLoader.h +2 -1
- hikyuu/include/hikyuu/version.h +4 -4
- hikyuu/include/hikyuu/view/MarketView.h +59 -0
- hikyuu/indicator/__init__.py +0 -1
- hikyuu/indicator/indicator.py +14 -53
- 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/test/test_init.py +59 -0
- hikyuu/test/test_real_tdx_import.py +336 -0
- hikyuu/test/test_tdx_import.py +315 -0
- hikyuu/test/test_tdx_real_data_import.py +281 -0
- hikyuu/trade_manage/__init__.pyi +479 -471
- hikyuu/trade_manage/trade.py +4 -65
- hikyuu/trade_manage/trade.pyi +479 -483
- hikyuu/trade_sys/__init__.py +11 -0
- hikyuu/util/__init__.py +1 -0
- hikyuu/util/__init__.pyi +4 -4
- hikyuu/util/check.py +8 -0
- hikyuu/util/check.pyi +5 -1
- hikyuu/util/singleton.pyi +1 -1
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/METADATA +7 -5
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/RECORD +142 -124
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/top_level.txt +4 -3
- hikyuu/include/hikyuu/global/agent/hikyuu/flat/__init__.py +0 -1
- hikyuu/include/hikyuu/utilities/mo/__init__.py +0 -1
- hikyuu/include/hikyuu/utilities/mo/mo.h +0 -48
- hikyuu/indicator/talib_wrap.py +0 -1273
- /hikyuu/include/hikyuu/utilities/{mo/moFileReader.h → moFileReader.h} +0 -0
- /hikyuu/include/hikyuu/{global/agent/hikyuu → view}/__init__.py +0 -0
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/LICENSE +0 -0
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/WHEEL +0 -0
- {hikyuu-2.6.5.dist-info → hikyuu-2.6.7.dist-info}/entry_points.txt +0 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-05-19
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/utilities/plugin/PluginBase.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
class HkuExtraPluginInterface : public PluginBase {
|
|
15
|
+
public:
|
|
16
|
+
HkuExtraPluginInterface() = default;
|
|
17
|
+
virtual ~HkuExtraPluginInterface() = default;
|
|
18
|
+
|
|
19
|
+
virtual void registerKTypeExtra(const string& ktype, const string& basetype, int32_t minutes,
|
|
20
|
+
std::function<Datetime(const Datetime&)> getPhaseEnd) = 0;
|
|
21
|
+
|
|
22
|
+
virtual void releaseKExtra() = 0;
|
|
23
|
+
|
|
24
|
+
virtual bool isExtraKType(const string& ktype) = 0;
|
|
25
|
+
|
|
26
|
+
virtual std::vector<string> getExtraKTypeList() = 0;
|
|
27
|
+
|
|
28
|
+
virtual int32_t getKTypeExtraMinutes(const string& ktype) = 0;
|
|
29
|
+
|
|
30
|
+
virtual KRecordList getExtraKRecordList(const Stock& stk, const KQuery& query) = 0;
|
|
31
|
+
|
|
32
|
+
virtual size_t getStockExtraCount(const Stock& stk, const string& ktype) = 0;
|
|
33
|
+
|
|
34
|
+
virtual bool getStockExtraIndexRange(const Stock& stk, const KQuery& query, size_t& out_start,
|
|
35
|
+
size_t& out_end) = 0;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
} // namespace hku
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
#include "hikyuu/KRecord.h"
|
|
11
11
|
#include "hikyuu/KQuery.h"
|
|
12
|
+
#include "hikyuu/TimeLineRecord.h"
|
|
13
|
+
#include "hikyuu/TransRecord.h"
|
|
12
14
|
#include "hikyuu/utilities/plugin/PluginBase.h"
|
|
13
15
|
|
|
14
16
|
namespace hku {
|
|
@@ -18,7 +20,8 @@ public:
|
|
|
18
20
|
ImportKDataToHdf5PluginInterface() = default;
|
|
19
21
|
virtual ~ImportKDataToHdf5PluginInterface() = default;
|
|
20
22
|
|
|
21
|
-
virtual bool setConfig(const string& datapath, const vector<string>& markets
|
|
23
|
+
virtual bool setConfig(const string& datapath, const vector<string>& markets,
|
|
24
|
+
const vector<string>& ktypes) = 0;
|
|
22
25
|
|
|
23
26
|
virtual Datetime getLastDatetime(const string& market, const string& code,
|
|
24
27
|
const KQuery::KType& ktype) = 0;
|
|
@@ -26,8 +29,17 @@ public:
|
|
|
26
29
|
virtual void addKRecordList(const string& market, const string& code,
|
|
27
30
|
const vector<KRecord>& krecords, const KQuery::KType& ktype) = 0;
|
|
28
31
|
|
|
32
|
+
virtual void addTimeLineList(const string& market, const string& code,
|
|
33
|
+
const TimeLineList& timeline) = 0;
|
|
34
|
+
|
|
35
|
+
virtual void addTransList(const string& market, const string& code,
|
|
36
|
+
const TransRecordList& translist) = 0;
|
|
37
|
+
|
|
29
38
|
virtual void updateIndex(const string& market, const string& code,
|
|
30
39
|
const KQuery::KType& ktype) = 0;
|
|
40
|
+
|
|
41
|
+
virtual void remove(const string& market, const string& code, const KQuery::KType& ktype,
|
|
42
|
+
Datetime start) = 0;
|
|
31
43
|
};
|
|
32
44
|
|
|
33
45
|
} // namespace hku
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
#include "ImportKDataToHdf5PluginInterface.h"
|
|
14
14
|
#include "ExtendIndicatorsPluginInterface.h"
|
|
15
15
|
#include "TMReportPluginInterface.h"
|
|
16
|
+
#include "DataDriverPluginInterface.h"
|
|
17
|
+
#include "HkuExtraPluginInterface.h"
|
|
16
18
|
|
|
17
19
|
namespace hku {
|
|
18
20
|
|
|
@@ -22,5 +24,7 @@ namespace hku {
|
|
|
22
24
|
#define HKU_PLUGIN_IMPORTKDATATOHDF5 "import2hdf5"
|
|
23
25
|
#define HKU_PLUGIN_EXTEND_INDICATOR "extind"
|
|
24
26
|
#define HKU_PLUGIN_TMREPORT "tmreport"
|
|
27
|
+
#define HKU_PLUGIN_CLICKHOUSE_DRIVER "clickhousedriver"
|
|
28
|
+
#define HKU_PLUGIN_HKU_EXTRA "hkuextra"
|
|
25
29
|
|
|
26
30
|
}
|
|
@@ -106,6 +106,15 @@ inline bool check_pyfunction_arg_num(py::object& func, size_t arg_num) {
|
|
|
106
106
|
return len(params) == arg_num;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
+
/*
|
|
110
|
+
* 将utf8编码的字符串转换为utf32编码
|
|
111
|
+
* @param utf8_str 待转换的字符串
|
|
112
|
+
* @param out 存储转换结果的数组(需自行预先分配内存)
|
|
113
|
+
* @param out_len out数组的长度
|
|
114
|
+
* @return 实际转码点数
|
|
115
|
+
*/
|
|
116
|
+
size_t utf8_to_utf32(const std::string& utf8_str, int32_t* out, size_t out_len) noexcept;
|
|
117
|
+
|
|
109
118
|
} // namespace hku
|
|
110
119
|
|
|
111
120
|
#endif // HIKYUU_PYTHON_BIND_UTILS_H
|
|
@@ -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
|
|
@@ -79,6 +79,12 @@ std::string HKU_UTILS_API getUserDir();
|
|
|
79
79
|
*/
|
|
80
80
|
std::string HKU_UTILS_API getCurrentDir();
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* 获取dll自身所在目录
|
|
84
|
+
* @note 仅支持linux/macos。windows下获取的是exe所在路径!
|
|
85
|
+
*/
|
|
86
|
+
std::string HKU_UTILS_API getDllSelfDir();
|
|
87
|
+
|
|
82
88
|
/**
|
|
83
89
|
* 输出终端是否支持彩色控制字符
|
|
84
90
|
*/
|
|
@@ -99,4 +105,7 @@ std::string HKU_UTILS_API getPlatform();
|
|
|
99
105
|
/** 获取当前CPU架构名称 */
|
|
100
106
|
std::string HKU_UTILS_API getCpuArch();
|
|
101
107
|
|
|
108
|
+
/** 获取当前系统语言名称(全部小写返回) */
|
|
109
|
+
std::string HKU_UTILS_API getSystemLanguage();
|
|
110
|
+
|
|
102
111
|
} // namespace hku
|
|
@@ -46,7 +46,8 @@ public:
|
|
|
46
46
|
|
|
47
47
|
bool load(const std::string& pluginname) noexcept {
|
|
48
48
|
std::string filename = getFileName(pluginname);
|
|
49
|
-
HKU_WARN_IF_RETURN(!existFile(filename), false, "file({}) not exist!", filename);
|
|
49
|
+
// HKU_WARN_IF_RETURN(!existFile(filename), false, "file({}) not exist!", filename);
|
|
50
|
+
HKU_DEBUG_IF_RETURN(!existFile(filename), false, "file({}) not exist!", filename);
|
|
50
51
|
|
|
51
52
|
#if HKU_OS_WINDOWS
|
|
52
53
|
m_handle = LoadLibrary(HKU_PATH(filename).c_str());
|
hikyuu/include/hikyuu/version.h
CHANGED
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
#define HKU_VERSION_H
|
|
13
13
|
|
|
14
14
|
// clang-format off
|
|
15
|
-
#define HKU_VERSION "2.6.
|
|
15
|
+
#define HKU_VERSION "2.6.7"
|
|
16
16
|
#define HKU_VERSION_MAJOR 2
|
|
17
17
|
#define HKU_VERSION_MINOR 6
|
|
18
|
-
#define HKU_VERSION_ALTER
|
|
19
|
-
#define HKU_VERSION_BUILD
|
|
18
|
+
#define HKU_VERSION_ALTER 7
|
|
19
|
+
#define HKU_VERSION_BUILD 202508150017
|
|
20
20
|
#define HKU_VERSION_MODE "RELEASE"
|
|
21
|
-
#define HKU_VERSION_GIT "2.6.
|
|
21
|
+
#define HKU_VERSION_GIT "2.6.7 release.95439630 (RELEASE)"
|
|
22
22
|
// clang-format on
|
|
23
23
|
|
|
24
24
|
#endif /* HKU_VERSION_H */
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2025 hikyuu.org
|
|
3
|
+
*
|
|
4
|
+
* Created on: 2025-08-13
|
|
5
|
+
* Author: fasiondog
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include "hikyuu/Stock.h"
|
|
11
|
+
|
|
12
|
+
namespace hku {
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 实时行情记录(用于显示打印)
|
|
16
|
+
* @ingroup View
|
|
17
|
+
*/
|
|
18
|
+
struct HKU_API MarketViewRecord {
|
|
19
|
+
Stock stock; ///< 证券
|
|
20
|
+
Datetime date; ///< 日期
|
|
21
|
+
price_t open{Null<price_t>()}; ///< 开盘价
|
|
22
|
+
price_t high{Null<price_t>()}; ///< 最高价
|
|
23
|
+
price_t low{Null<price_t>()}; ///< 最低价
|
|
24
|
+
price_t close{Null<price_t>()}; ///< 收盘价
|
|
25
|
+
price_t amount{Null<price_t>()}; ///< 成交额
|
|
26
|
+
price_t volume{Null<price_t>()}; ///< 成交量
|
|
27
|
+
price_t yesterday_close{Null<price_t>()}; ///< 昨收价
|
|
28
|
+
price_t turnover{Null<price_t>()}; ///< 换手率(%)
|
|
29
|
+
price_t amplitude{Null<price_t>()}; ///< 振幅(%)
|
|
30
|
+
price_t price_change{Null<price_t>()}; ///< 涨跌幅(%)
|
|
31
|
+
price_t total_market_cap{Null<price_t>()}; ///< 总市值
|
|
32
|
+
price_t circulating_market_cap{Null<price_t>()}; ///< 流通市值
|
|
33
|
+
price_t pe{Null<price_t>()}; ///< 动态市盈率
|
|
34
|
+
price_t pb{Null<price_t>()}; ///< 市净率
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
using MarketView = vector<MarketViewRecord>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 获取指定股票集合在指定交易日的行情数据,不包含当日停牌无数据的股票
|
|
41
|
+
* @ingroup View
|
|
42
|
+
* @param stks 股票列表
|
|
43
|
+
* @param date 交易日
|
|
44
|
+
* @param market 市场代码(用于获取交易日历)
|
|
45
|
+
* @return MarketView
|
|
46
|
+
*/
|
|
47
|
+
MarketView HKU_API getMarketView(const StockList& stks, const Datetime& date,
|
|
48
|
+
const string& market = "SH");
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 获取指定股票集合在最后交易日的行情数据,不包含当日停牌无数据的股票。如自动接收行情数据,则为实时行情数据
|
|
52
|
+
* @ingroup View
|
|
53
|
+
* @param stks 股票列表
|
|
54
|
+
* @param market 市场代码(用于获取交易日历)
|
|
55
|
+
* @return MarketView
|
|
56
|
+
*/
|
|
57
|
+
MarketView HKU_API getMarketView(const StockList& stks, const string& market = "SH");
|
|
58
|
+
|
|
59
|
+
} // namespace hku
|
hikyuu/indicator/__init__.py
CHANGED
hikyuu/indicator/indicator.py
CHANGED
|
@@ -29,50 +29,9 @@ from hikyuu import Datetime
|
|
|
29
29
|
import pandas as pd
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def indicator_iter(indicator):
|
|
33
|
-
for i in range(len(indicator)):
|
|
34
|
-
yield indicator[i]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def indicator_getitem(data, i):
|
|
38
|
-
"""
|
|
39
|
-
:param i: int | Datetime | slice | str 类型
|
|
40
|
-
"""
|
|
41
|
-
if isinstance(i, int):
|
|
42
|
-
length = len(data)
|
|
43
|
-
index = length + i if i < 0 else i
|
|
44
|
-
if index < 0 or index >= length:
|
|
45
|
-
raise IndexError("index out of range: %d" % i)
|
|
46
|
-
return data.get(index)
|
|
47
|
-
|
|
48
|
-
elif isinstance(i, slice):
|
|
49
|
-
return [data.get(x) for x in range(*i.indices(len(data)))]
|
|
50
|
-
|
|
51
|
-
elif isinstance(i, Datetime):
|
|
52
|
-
return data.get_by_datetime(i)
|
|
53
|
-
|
|
54
|
-
elif isinstance(i, str):
|
|
55
|
-
return data.get_by_datetime(Datetime(i))
|
|
56
|
-
|
|
57
|
-
else:
|
|
58
|
-
raise IndexError("Error index type")
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Indicator.__getitem__ = indicator_getitem
|
|
62
|
-
Indicator.__iter__ = indicator_iter
|
|
63
|
-
|
|
64
|
-
|
|
65
32
|
def indicator_to_df(indicator):
|
|
66
33
|
"""转化为pandas.DataFrame"""
|
|
67
|
-
|
|
68
|
-
return pd.DataFrame(indicator.to_np(), columns=[indicator.name])
|
|
69
|
-
data = {}
|
|
70
|
-
name = indicator.name
|
|
71
|
-
columns = []
|
|
72
|
-
for i in range(indicator.get_result_num()):
|
|
73
|
-
data[name + str(i)] = indicator.get_result(i)
|
|
74
|
-
columns.append(name + str(i + 1))
|
|
75
|
-
return pd.DataFrame(data, columns=columns)
|
|
34
|
+
return pd.DataFrame.from_records(indicator.to_np())
|
|
76
35
|
|
|
77
36
|
|
|
78
37
|
Indicator.to_df = indicator_to_df
|
|
@@ -107,17 +66,19 @@ def concat_to_df(dates, ind_list, head_stock_code=True, head_ind_name=False):
|
|
|
107
66
|
198 2024-03-06 00:00:00 10.070455 9.776818
|
|
108
67
|
199 2024-03-07 00:00:00 10.101364 9.738182
|
|
109
68
|
"""
|
|
110
|
-
df =
|
|
111
|
-
|
|
112
|
-
|
|
69
|
+
df = dates.to_df('ms')
|
|
70
|
+
if not ind_list:
|
|
71
|
+
return df
|
|
72
|
+
for i in range(len(ind_list)):
|
|
73
|
+
ind = ind_list[i]
|
|
113
74
|
if head_ind_name and head_stock_code:
|
|
114
|
-
|
|
75
|
+
name = f"{ind.name}/{ind.get_context().get_stock().market_code}"
|
|
115
76
|
elif head_ind_name:
|
|
116
|
-
|
|
77
|
+
name = f'{ind.name}{i}'
|
|
117
78
|
else:
|
|
118
|
-
|
|
119
|
-
df = pd.
|
|
120
|
-
|
|
79
|
+
name = ind.get_context().get_stock().market_code
|
|
80
|
+
df = pd.merge(df, ind.to_df()[['datetime', 'value1']].rename(
|
|
81
|
+
columns={'value1': name}), on='datetime', how='left')
|
|
121
82
|
return df
|
|
122
83
|
|
|
123
84
|
|
|
@@ -137,10 +98,10 @@ def df_to_ind(df, col_name, col_date=None):
|
|
|
137
98
|
:return: Indicator
|
|
138
99
|
"""
|
|
139
100
|
if col_date is not None:
|
|
140
|
-
dates = df[col_date]
|
|
101
|
+
dates = df[col_date]
|
|
141
102
|
dates = DatetimeList([Datetime(x) for x in dates])
|
|
142
|
-
return PRICELIST(df[col_name]
|
|
143
|
-
return PRICELIST(df[col_name]
|
|
103
|
+
return PRICELIST(df[col_name], align_dates=dates)
|
|
104
|
+
return PRICELIST(df[col_name])
|
|
144
105
|
|
|
145
106
|
|
|
146
107
|
# 避免 python 中公式原型必须加括号
|
hikyuu/plugin/backtest.dll
CHANGED
|
Binary file
|
|
Binary file
|
hikyuu/plugin/dataserver.dll
CHANGED
|
Binary file
|
hikyuu/plugin/device.dll
CHANGED
|
Binary file
|
hikyuu/plugin/extind.dll
CHANGED
|
Binary file
|
|
Binary file
|
hikyuu/plugin/import2hdf5.dll
CHANGED
|
Binary file
|
hikyuu/plugin/tmreport.dll
CHANGED
|
Binary file
|
hikyuu/test/test_init.py
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
# 历史:1)20130128, Added by fasiondog
|
|
8
8
|
#===============================================================================
|
|
9
9
|
from hikyuu import *
|
|
10
|
+
from configparser import ConfigParser
|
|
11
|
+
from functools import lru_cache
|
|
10
12
|
|
|
11
13
|
import os
|
|
12
14
|
#curdir = os.path.dirname(os.path.realpath(__file__))
|
|
@@ -34,3 +36,60 @@ hikyuu_init(config_file)
|
|
|
34
36
|
sm = StockManager.instance()
|
|
35
37
|
#endtime = time.time()
|
|
36
38
|
#print "%.2fs" % (endtime-starttime)
|
|
39
|
+
|
|
40
|
+
# 仅在模块加载时读取一次配置
|
|
41
|
+
_config = ConfigParser()
|
|
42
|
+
_config.read(config_file)
|
|
43
|
+
_tdx_dir = _config.get('tdx', 'dir', fallback='/mnt/tdx')
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@lru_cache(maxsize=None)
|
|
47
|
+
def get_real_tdx_filepath(code, market='sh'):
|
|
48
|
+
"""
|
|
49
|
+
获取真实的通达信.day文件路径。
|
|
50
|
+
|
|
51
|
+
该函数按以下顺序确定文件路径:
|
|
52
|
+
1. 检查环境变量 `HKU_real_tdx_file_path` 是否被设置。
|
|
53
|
+
2. 如果未设置, 则检查配置文件中 "tdx"->"dir" 指定的路径。
|
|
54
|
+
3. 如果未配置, 则使用 /mnt/tdx/vipdoc/。
|
|
55
|
+
4. 如果上述路径不存在, 则检查 test_data/vipdoc/ 是否存在, 如果存在, 则使用该路径。
|
|
56
|
+
5. 如果上述路径都不存在, 则自动回退到在项目根目录下的 `test_data` 文件夹中寻找同名文件作为备用。
|
|
57
|
+
|
|
58
|
+
这使得测试既能适应有权访问生产数据环境的开发者, 也能让其他贡献者使用
|
|
59
|
+
项目内提供的样本数据来运行测试, 避免了因路径问题导致的测试挂起或失败。
|
|
60
|
+
|
|
61
|
+
:param str code: 股票代码 (如 '600000', '000001')
|
|
62
|
+
:param str market: 市场简称 (如 'sh', 'sz')
|
|
63
|
+
:return: 最终确定的文件路径 (可能不存在, 由调用方处理)
|
|
64
|
+
"""
|
|
65
|
+
# 检查环境变量
|
|
66
|
+
env_path = os.environ.get('HKU_real_tdx_file_path')
|
|
67
|
+
if env_path and os.path.exists(env_path):
|
|
68
|
+
print(f"get_real_tdx_filepath return: {env_path}")
|
|
69
|
+
return env_path
|
|
70
|
+
|
|
71
|
+
market_subdir = f"{market.lower()}/lday"
|
|
72
|
+
filename = f"{market.lower()}{code}.day"
|
|
73
|
+
|
|
74
|
+
# 检查配置文件指定的路径
|
|
75
|
+
base_path = os.path.join(_tdx_dir, 'vipdoc')
|
|
76
|
+
if os.path.exists(base_path):
|
|
77
|
+
primary_path = os.path.join(base_path, market_subdir, filename)
|
|
78
|
+
if os.path.exists(primary_path):
|
|
79
|
+
print(f"get_real_tdx_filepath return: {primary_path}")
|
|
80
|
+
return primary_path
|
|
81
|
+
|
|
82
|
+
# 检查 test_data/vipdoc/
|
|
83
|
+
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
|
|
84
|
+
test_data_vipdoc_path = os.path.join(project_root, 'test_data', 'vipdoc')
|
|
85
|
+
if os.path.exists(test_data_vipdoc_path):
|
|
86
|
+
primary_path = os.path.join(test_data_vipdoc_path, market_subdir, filename)
|
|
87
|
+
if os.path.exists(primary_path):
|
|
88
|
+
print(f"get_real_tdx_filepath return: {primary_path}")
|
|
89
|
+
return primary_path
|
|
90
|
+
|
|
91
|
+
# 如果主路径文件不存在, 则尝试从 test_data 目录寻找同名文件作为备用
|
|
92
|
+
test_data_dir = os.path.join(project_root, 'test_data')
|
|
93
|
+
fallback_path = os.path.join(test_data_dir, filename)
|
|
94
|
+
print(f"get_real_tdx_filepath return: {fallback_path}")
|
|
95
|
+
return fallback_path
|