mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
Merge branch 'master' of https://github.com/fasiondog/hikyuu into feature/se
This commit is contained in:
commit
3f737f53c7
@ -84,18 +84,19 @@ void GlobalInitializer::clean() {
|
||||
getLatestVersion(), getLatestVersion());
|
||||
}
|
||||
|
||||
#if !HKU_ENABLE_LEAK_DETECT && !defined(MSVC_LEAKER_DETECT)
|
||||
// 未启用内存泄漏检测时,直接退出,让系统自行释放全部资源
|
||||
fmt::print("Quit Hikyuu system!\n\n");
|
||||
return;
|
||||
#endif
|
||||
|
||||
releaseGlobalTaskGroup();
|
||||
releaseScheduler();
|
||||
releaseGlobalSpotAgent();
|
||||
|
||||
IndicatorImp::releaseDynEngine();
|
||||
|
||||
#if HKU_ENABLE_LEAK_DETECT || defined(MSVC_LEAKER_DETECT)
|
||||
// 非内存泄漏检测时,内存让系统自动释放,避免某些场景下 windows 下退出速度过慢
|
||||
StockManager::quit();
|
||||
#else
|
||||
fmt::print("Quit Hikyuu system!\n\n");
|
||||
#endif
|
||||
|
||||
DataDriverFactory::release();
|
||||
|
||||
#if HKU_ENABLE_HDF5_KDATA
|
||||
|
@ -18,14 +18,6 @@ namespace hku {
|
||||
* @return Indicator
|
||||
*/
|
||||
Indicator HKU_API BLOCKSETNUM(const Block& blk, const KQuery& query);
|
||||
|
||||
/**
|
||||
* 横向统计(返回板块股个数)
|
||||
* @param category 板块分类
|
||||
* @param name 板块名称
|
||||
* @param query 统计范围
|
||||
* @return Indicator
|
||||
*/
|
||||
Indicator HKU_API BLOCKSETNUM(const string& category, const string& name, const KQuery& query);
|
||||
Indicator HKU_API BLOCKSETNUM(const Block& blk);
|
||||
|
||||
} // namespace hku
|
@ -23,14 +23,11 @@ Indicator HKU_API INSUM(const Block& block, const KQuery& query, const Indicator
|
||||
|
||||
/**
|
||||
* 返回板块各成分该指标相应输出按计算类型得到的计算值.计算类型:0-累加,1-平均数,2-最大值,3-最小值.
|
||||
* @param category 板块类别
|
||||
* @param category 板块名称
|
||||
* @param query 指定范围
|
||||
* @param block 指定板块
|
||||
* @param ind 指定指标
|
||||
* @param mode 计算类型:0-累加,1-平均数,2-最大值,3-最小值.
|
||||
* @return Indicator
|
||||
*/
|
||||
Indicator HKU_API INSUM(const string& category, const string& name, const KQuery& query,
|
||||
const Indicator& ind, int mode);
|
||||
Indicator HKU_API INSUM(const Block& block, const Indicator& ind, int mode);
|
||||
|
||||
} // namespace hku
|
@ -43,8 +43,10 @@ void IBlockSetNum::_calculate(const Indicator& ind) {
|
||||
dates = k.getDatetimeList();
|
||||
} else {
|
||||
KQuery q = getParam<KQuery>("query");
|
||||
if (q != KQuery(0, 0)) {
|
||||
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
|
||||
}
|
||||
}
|
||||
|
||||
size_t total = dates.size();
|
||||
m_discard = 0;
|
||||
@ -72,17 +74,13 @@ Indicator HKU_API BLOCKSETNUM(const Block& block, const KQuery& query) {
|
||||
IndicatorImpPtr p = make_shared<IBlockSetNum>();
|
||||
p->setParam<KQuery>("query", query);
|
||||
p->setParam<Block>("block", block);
|
||||
if (query == Null<KQuery>()) {
|
||||
p->setParam<bool>("ignore_context", true);
|
||||
} else {
|
||||
p->setParam<bool>("ignore_context", false);
|
||||
p->calculate();
|
||||
}
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API BLOCKSETNUM(const string& category, const string& name, const KQuery& query) {
|
||||
Block block = StockManager::instance().getBlock(category, name);
|
||||
return BLOCKSETNUM(block, query);
|
||||
Indicator HKU_API BLOCKSETNUM(const Block& block) {
|
||||
return BLOCKSETNUM(block, KQuery(0, 0));
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -20,7 +20,7 @@ BOOST_CLASS_EXPORT(hku::IInSum)
|
||||
namespace hku {
|
||||
|
||||
IInSum::IInSum() : IndicatorImp("INSUM", 1) {
|
||||
setParam<KQuery>("query", KQueryByIndex(-100));
|
||||
setParam<KQuery>("query", KQuery(0, 0));
|
||||
setParam<Block>("block", Block());
|
||||
setParam<int>("mode", 0);
|
||||
setParam<string>("market", "SH");
|
||||
@ -61,7 +61,14 @@ static IndicatorList getAllIndicators(const Block& block, const KQuery& query,
|
||||
|
||||
static void insum_cum(const IndicatorList& inds, Indicator::value_t* dst, size_t len) {
|
||||
for (const auto& value : inds) {
|
||||
HKU_ASSERT(value.size() == len);
|
||||
if (value.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (value.size() != len) {
|
||||
HKU_WARN("Ignore stock: {}, value len: {}, dst len: {}, stk: {}",
|
||||
value.getContext().getStock().name(), value.size(), len);
|
||||
continue;
|
||||
}
|
||||
const auto* data = value.data();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!std::isnan(data[i])) {
|
||||
@ -78,7 +85,14 @@ static void insum_cum(const IndicatorList& inds, Indicator::value_t* dst, size_t
|
||||
static void insum_mean(const IndicatorList& inds, Indicator::value_t* dst, size_t len) {
|
||||
vector<size_t> count(len, 0);
|
||||
for (const auto& value : inds) {
|
||||
HKU_ASSERT(value.size() == len);
|
||||
if (value.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (value.size() != len) {
|
||||
HKU_WARN("Ignore stock: {}, value len: {}, dst len: {}, stk: {}",
|
||||
value.getContext().getStock().name(), value.size(), len);
|
||||
continue;
|
||||
}
|
||||
const auto* data = value.data();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!std::isnan(data[i])) {
|
||||
@ -101,7 +115,14 @@ static void insum_mean(const IndicatorList& inds, Indicator::value_t* dst, size_
|
||||
|
||||
static void insum_max(const IndicatorList& inds, Indicator::value_t* dst, size_t len) {
|
||||
for (const auto& value : inds) {
|
||||
HKU_ASSERT(value.size() == len);
|
||||
if (value.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (value.size() != len) {
|
||||
HKU_WARN("Ignore stock: {}, value len: {}, dst len: {}, stk: {}",
|
||||
value.getContext().getStock().name(), value.size(), len);
|
||||
continue;
|
||||
}
|
||||
const auto* data = value.data();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!std::isnan(data[i])) {
|
||||
@ -117,7 +138,14 @@ static void insum_max(const IndicatorList& inds, Indicator::value_t* dst, size_t
|
||||
|
||||
static void insum_min(const IndicatorList& inds, Indicator::value_t* dst, size_t len) {
|
||||
for (const auto& value : inds) {
|
||||
HKU_ASSERT(value.size() == len);
|
||||
if (value.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (value.size() != len) {
|
||||
HKU_WARN("Ignore stock: {}, value len: {}, dst len: {}, stk: {}",
|
||||
value.getContext().getStock().name(), value.size(), len);
|
||||
continue;
|
||||
}
|
||||
const auto* data = value.data();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (!std::isnan(data[i])) {
|
||||
@ -142,8 +170,10 @@ void IInSum::_calculate(const Indicator& ind) {
|
||||
dates = k.getDatetimeList();
|
||||
} else {
|
||||
q = getParam<KQuery>("query");
|
||||
if (q != KQuery(0, 0)) {
|
||||
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
|
||||
}
|
||||
}
|
||||
|
||||
size_t total = dates.size();
|
||||
m_discard = 0;
|
||||
@ -172,16 +202,12 @@ Indicator HKU_API INSUM(const Block& block, const KQuery& query, const Indicator
|
||||
p->setParam<KQuery>("query", query);
|
||||
p->setParam<Block>("block", block);
|
||||
p->setParam<int>("mode", mode);
|
||||
if (query == Null<KQuery>()) {
|
||||
p->setParam<bool>("ignore_context", true);
|
||||
}
|
||||
p->setParam<bool>("ignore_context", false);
|
||||
return Indicator(p)(ind);
|
||||
}
|
||||
|
||||
Indicator HKU_API INSUM(const string& category, const string& name, const KQuery& query,
|
||||
const Indicator& ind, int mode) {
|
||||
Block block = StockManager::instance().getBlock(category, name);
|
||||
return INSUM(block, query, ind, mode);
|
||||
Indicator HKU_API INSUM(const Block& block, const Indicator& ind, int mode) {
|
||||
return INSUM(block, KQuery(0, 0), ind, mode);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -1849,6 +1849,7 @@ void export_Indicator_build_in(py::module& m) {
|
||||
:param int ix: 历史财务信息字段索引
|
||||
:param int name: 历史财务信息字段名称)");
|
||||
|
||||
m.def("BLOCKSETNUM", py::overload_cast<const Block&>(BLOCKSETNUM), py::arg("block"));
|
||||
m.def("BLOCKSETNUM", py::overload_cast<const Block&, const KQuery&>(BLOCKSETNUM),
|
||||
py::arg("block"), py::arg("query"), R"(BLOCKSETNUM(block, query)
|
||||
|
||||
@ -1858,15 +1859,29 @@ void export_Indicator_build_in(py::module& m) {
|
||||
:param Query query: 统计范围)");
|
||||
|
||||
m.def(
|
||||
"BLOCKSETNUM", py::overload_cast<const string&, const string&, const KQuery&>(BLOCKSETNUM),
|
||||
py::arg("category"), py::arg("name"), py::arg("query"), R"(BLOCKSETNUM(category, name, query)
|
||||
"BLOCKSETNUM",
|
||||
[](const py::sequence& stks) {
|
||||
Block blk;
|
||||
blk.add(python_list_to_vector<Stock>(stks));
|
||||
return BLOCKSETNUM(blk);
|
||||
},
|
||||
py::arg("stks"));
|
||||
m.def(
|
||||
"BLOCKSETNUM",
|
||||
[](const py::sequence& stks, const KQuery& query) {
|
||||
Block blk;
|
||||
blk.add(python_list_to_vector<Stock>(stks));
|
||||
return BLOCKSETNUM(blk, query);
|
||||
},
|
||||
py::arg("stks"), py::arg("query"), R"(BLOCKSETNUM(block, query)
|
||||
|
||||
横向统计(返回板块股个数)
|
||||
|
||||
:param str category: 板块类别
|
||||
:param str name: 板块名称
|
||||
:param query 统计范围)");
|
||||
:param Sequence stks: stock list
|
||||
:param Query query: 统计范围)");
|
||||
|
||||
m.def("INSUM", py::overload_cast<const Block&, const Indicator&, int>(INSUM), py::arg("block"),
|
||||
py::arg("ind"), py::arg("mode"));
|
||||
m.def("INSUM", py::overload_cast<const Block&, const KQuery&, const Indicator&, int>(INSUM),
|
||||
py::arg("block"), py::arg("query"), py::arg("ind"), py::arg("mode"),
|
||||
R"(INSUM(block, query, ind, mode)
|
||||
@ -1881,14 +1896,25 @@ void export_Indicator_build_in(py::module& m) {
|
||||
|
||||
m.def(
|
||||
"INSUM",
|
||||
py::overload_cast<const string&, const string&, const KQuery&, const Indicator&, int>(INSUM),
|
||||
py::arg("category"), py::arg("name"), py::arg("query"), py::arg("ind"), py::arg("mode"),
|
||||
R"(INSUM(category, name, ind, mode)
|
||||
[](const py::sequence stks, const Indicator& ind, int mode) {
|
||||
Block blk;
|
||||
blk.add(python_list_to_vector<Stock>(stks));
|
||||
return INSUM(blk, ind, mode);
|
||||
},
|
||||
py::arg("stks"), py::arg("ind"), py::arg("mode"));
|
||||
m.def(
|
||||
"INSUM",
|
||||
[](const py::sequence stks, const KQuery& query, const Indicator& ind, int mode) {
|
||||
Block blk;
|
||||
blk.add(python_list_to_vector<Stock>(stks));
|
||||
return INSUM(blk, query, ind, mode);
|
||||
},
|
||||
py::arg("stks"), py::arg("query"), py::arg("ind"), py::arg("mode"),
|
||||
R"(INSUM(stks, query, ind, mode)
|
||||
|
||||
返回板块各成分该指标相应输出按计算类型得到的计算值.计算类型:0-累加,1-平均数,2-最大值,3-最小值.
|
||||
|
||||
:param str category: 板块类别
|
||||
:param str name: 板块名称
|
||||
:param Sequence stks: stock list
|
||||
:param Query query: 指定范围
|
||||
:param Indicator ind: 指定指标
|
||||
:param int mode: 计算类型:0-累加,1-平均数,2-最大值,3-最小值.
|
||||
|
Loading…
Reference in New Issue
Block a user