mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
优化 INSUM, BLOCKSETNUM 可直接输入 stock list, 可以忽略 query 参数
This commit is contained in:
parent
c00f897ceb
commit
bba5f4c5a7
@ -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,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 */
|
||||
|
@ -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");
|
||||
@ -138,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])) {
|
||||
@ -163,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();
|
||||
@ -193,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