hikyuu2/hikyuu_cpp/hikyuu/indicator/imp/ILiuTongPan.cpp

82 lines
1.7 KiB
C++
Raw Normal View History

2019-03-20 02:47:02 +08:00
/*
* ILiuTongPang.cpp
*
* Created on: 201936
* Author: fasiondog
*/
#include "ILiuTongPan.h"
#if HKU_SUPPORT_SERIALIZATION
BOOST_CLASS_EXPORT(hku::ILiuTongPan)
#endif
2019-03-20 02:47:02 +08:00
namespace hku {
2019-11-10 03:27:57 +08:00
ILiuTongPan::ILiuTongPan() : IndicatorImp("LIUTONGPAN", 1) {}
2019-03-20 02:47:02 +08:00
2019-11-10 03:27:57 +08:00
ILiuTongPan::~ILiuTongPan() {}
2019-03-20 02:47:02 +08:00
ILiuTongPan::ILiuTongPan(const KData& k) : IndicatorImp("LIUTONGPAN", 1) {
setParam<KData>("kdata", k);
2019-11-10 03:27:57 +08:00
ILiuTongPan::_calculate(Indicator());
2019-03-20 02:47:02 +08:00
}
bool ILiuTongPan::check() {
return true;
}
void ILiuTongPan::_calculate(const Indicator& data) {
2019-03-30 23:13:37 +08:00
if (!isLeaf() && !data.empty()) {
HKU_WARN("The input is ignored because {} depends on the context!", m_name);
2019-03-30 23:13:37 +08:00
}
KData k = getContext();
2019-03-20 02:47:02 +08:00
size_t total = k.size();
2019-03-24 00:17:11 +08:00
if (total == 0) {
return;
}
2019-11-10 03:27:57 +08:00
2019-03-20 02:47:02 +08:00
_readyBuffer(total, 1);
Stock stock = k.getStock();
StockWeightList sw_list = stock.getWeight();
2019-11-10 03:27:57 +08:00
if (sw_list.size() == 0) {
2019-03-20 02:47:02 +08:00
return;
}
size_t pos = 0;
auto sw_iter = sw_list.begin();
2019-03-29 22:54:40 +08:00
price_t pre_free_count = sw_iter->freeCount();
2019-03-20 02:47:02 +08:00
for (; sw_iter != sw_list.end(); ++sw_iter) {
2019-03-29 22:54:40 +08:00
price_t free_count = sw_iter->freeCount();
2019-03-20 02:47:02 +08:00
if (free_count == 0) {
2019-11-10 03:27:57 +08:00
continue; //忽略流通盘为0的权息
2019-03-20 02:47:02 +08:00
}
2019-03-29 22:54:40 +08:00
while (pos < total && k[pos].datetime < sw_iter->datetime()) {
_set(pre_free_count, pos);
2019-03-20 02:47:02 +08:00
pos++;
}
2019-03-29 22:54:40 +08:00
pre_free_count = free_count;
if (pos >= total) {
break;
}
2019-03-20 02:47:02 +08:00
}
for (; pos < total; pos++) {
2019-03-29 22:54:40 +08:00
_set(pre_free_count, pos);
2019-03-20 02:47:02 +08:00
}
}
Indicator HKU_API LIUTONGPAN() {
return make_shared<ILiuTongPan>()->calculate();
2019-03-20 02:47:02 +08:00
}
Indicator HKU_API LIUTONGPAN(const KData& k) {
2019-03-22 23:12:28 +08:00
return Indicator(make_shared<ILiuTongPan>(k));
2019-03-20 02:47:02 +08:00
}
} /* namespace hku */