mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
add BLOCKSETNUM indicator
This commit is contained in:
parent
992343dd68
commit
e81b34f95b
@ -26,6 +26,7 @@
|
||||
#include "crt/BARSLAST.h"
|
||||
#include "crt/BARSSINCE.h"
|
||||
#include "crt/BETWEEN.h"
|
||||
#include "crt/BLOCKSETNUM.h"
|
||||
#include "crt/CEILING.h"
|
||||
#include "crt/CORR.h"
|
||||
#include "crt/COS.h"
|
||||
|
31
hikyuu_cpp/hikyuu/indicator/crt/BLOCKSETNUM.h
Normal file
31
hikyuu_cpp/hikyuu/indicator/crt/BLOCKSETNUM.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2024 hikyuu.org
|
||||
*
|
||||
* Created on: 2024-05-21
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../Indicator.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
/**
|
||||
* 横向统计(返回板块股个数)
|
||||
* @param blk 待统计的板块
|
||||
* @param query 统计范围
|
||||
* @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);
|
||||
|
||||
} // namespace hku
|
84
hikyuu_cpp/hikyuu/indicator/imp/IBlockSetNum.cpp
Normal file
84
hikyuu_cpp/hikyuu/indicator/imp/IBlockSetNum.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* IBlockSetNum.cpp
|
||||
*
|
||||
* Copyright (c) 2019, hikyuu.org
|
||||
*
|
||||
* Created on: 2024-5-21
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#include "IBlockSetNum.h"
|
||||
#include "../Indicator.h"
|
||||
#include "../crt/KDATA.h"
|
||||
#include "../crt/REF.h"
|
||||
#include "../crt/ALIGN.h"
|
||||
#include "../../StockManager.h"
|
||||
|
||||
#if HKU_SUPPORT_SERIALIZATION
|
||||
BOOST_CLASS_EXPORT(hku::IBlockSetNum)
|
||||
#endif
|
||||
|
||||
namespace hku {
|
||||
|
||||
IBlockSetNum::IBlockSetNum() : IndicatorImp("BLOCKSETNUM", 1) {
|
||||
setParam<KQuery>("query", KQueryByIndex(-100));
|
||||
setParam<Block>("block", Block());
|
||||
setParam<bool>("ignore_context", false);
|
||||
}
|
||||
|
||||
IBlockSetNum::~IBlockSetNum() {}
|
||||
|
||||
void IBlockSetNum::_calculate(const Indicator& ind) {
|
||||
Block block = getParam<Block>("block");
|
||||
bool ignore_context = getParam<bool>("ignore_context");
|
||||
KData k = getContext();
|
||||
KQuery q;
|
||||
DatetimeList dates;
|
||||
if (!ignore_context && !k.empty()) {
|
||||
q = k.getQuery();
|
||||
dates = k.getDatetimeList();
|
||||
} else {
|
||||
q = getParam<KQuery>("query");
|
||||
dates = StockManager::instance().getTradingCalendar(q);
|
||||
}
|
||||
|
||||
size_t total = dates.size();
|
||||
m_discard = 0;
|
||||
_readyBuffer(total, 1);
|
||||
HKU_IF_RETURN(total == 0, void());
|
||||
|
||||
value_t zero = 0.0;
|
||||
auto* dst = this->data();
|
||||
for (size_t i = 0; i < total; i++) {
|
||||
dst[i] = zero;
|
||||
}
|
||||
|
||||
for (auto iter = block.begin(); iter != block.end(); ++iter) {
|
||||
const Datetime& start_date = iter->startDatetime();
|
||||
Datetime last_date = iter->lastDatetime().isNull() ? Datetime::max() : iter->lastDatetime();
|
||||
for (size_t i = 0; i < total; i++) {
|
||||
if (dates[i] >= start_date && dates[i] <= last_date) {
|
||||
dst[i]++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
27
hikyuu_cpp/hikyuu/indicator/imp/IBlockSetNum.h
Normal file
27
hikyuu_cpp/hikyuu/indicator/imp/IBlockSetNum.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 2024 hikyuu.org
|
||||
*
|
||||
* Created on: 2024-05-21
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#ifndef INDICATOR_IMP_IBLOCKSETNUM_H_
|
||||
#define INDICATOR_IMP_IBLOCKSETNUM_H_
|
||||
|
||||
#include "../Indicator.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
class IBlockSetNum : public IndicatorImp {
|
||||
INDICATOR_IMP(IBlockSetNum)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IBlockSetNum();
|
||||
virtual ~IBlockSetNum();
|
||||
};
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_IMP_IBLOCKSETNUM_H_ */
|
@ -1848,4 +1848,22 @@ void export_Indicator_build_in(py::module& m) {
|
||||
:param KData kdata: K线数据
|
||||
:param int ix: 历史财务信息字段索引
|
||||
:param int name: 历史财务信息字段名称)");
|
||||
|
||||
m.def("BLOCKSETNUM", py::overload_cast<const Block&, const KQuery&>(BLOCKSETNUM),
|
||||
py::arg("block"), py::arg("query"), R"(BLOCKSETNUM(block, query)
|
||||
|
||||
横向统计(返回板块股个数)
|
||||
|
||||
:param Block block: 待统计的板块
|
||||
: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)
|
||||
|
||||
横向统计(返回板块股个数)
|
||||
|
||||
:param str category: 板块类别
|
||||
:param str name: 板块名称
|
||||
:param query 统计范围)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user