Merge branch 'master' of https://github.com/fasiondog/hikyuu into feature/se

This commit is contained in:
fasiondog 2024-06-16 03:11:19 +08:00
commit 3f737f53c7
6 changed files with 92 additions and 52 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -43,7 +43,9 @@ void IBlockSetNum::_calculate(const Indicator& ind) {
dates = k.getDatetimeList();
} else {
KQuery q = getParam<KQuery>("query");
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
if (q != KQuery(0, 0)) {
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
}
}
size_t total = dates.size();
@ -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->calculate();
}
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 */

View File

@ -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,7 +170,9 @@ void IInSum::_calculate(const Indicator& ind) {
dates = k.getDatetimeList();
} else {
q = getParam<KQuery>("query");
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
if (q != KQuery(0, 0)) {
dates = StockManager::instance().getTradingCalendar(q, getParam<string>("market"));
}
}
size_t total = dates.size();
@ -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 */

View File

@ -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-.