mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
commit
3cc2a118a7
@ -113,7 +113,7 @@
|
||||
例如:BACKSET(CLOSE>OPEN,2)若收阳则将该周期及前一周期数值设为1,否则为0
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: N周期
|
||||
:param int n|Indicator|IndParam: N周期
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -230,7 +230,7 @@
|
||||
例如:COUNT(CLOSE>OPEN,20)表示统计20周期内收阳的周期数
|
||||
|
||||
:param Indicator data: 条件
|
||||
:param int n: 周期
|
||||
:param int|Indicator|IndParam n: 周期
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -309,7 +309,7 @@
|
||||
连跌周期数, DOWNNDAY(CLOSE,M)表示连涨M个周期
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -340,7 +340,7 @@
|
||||
存在, EXIST(X,N) 表示条件X在N周期有存在
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 计算均值的周期窗口,必须为大于0的整数
|
||||
:param int|Indicator|IndParam n: 计算均值的周期窗口,必须为大于0的整数
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -361,7 +361,7 @@
|
||||
例如:FILTER(CLOSE>OPEN,5) 查找阳线,5 天内再次出现的阳线不被记录在内。
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: 过滤周期
|
||||
:param int|Indicator|IndParam n: 过滤周期
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -395,7 +395,7 @@
|
||||
例如:HHVBARS(HIGH,0)求得历史新高到到当前的周期数
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: N日时间窗口
|
||||
:param int|Indicator|IndParam n: N日时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
.. py:function:: HIGH([data])
|
||||
@ -503,7 +503,7 @@
|
||||
例如:LLVBARS(HIGH,20)求得20日最低点到当前的周期数
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: N日时间窗口
|
||||
:param int|Indicator|IndParam n: N日时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -635,7 +635,7 @@
|
||||
例如:POW(CLOSE,3)求得收盘价的3次方
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 幂
|
||||
:param int|Indicator|IndParam n: 幂
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -673,7 +673,7 @@
|
||||
变动率指标: ((price / prevPrice)-1)*100
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -682,7 +682,7 @@
|
||||
变动率指标: (price - prevPrice) / prevPrice
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
@ -691,7 +691,7 @@
|
||||
变动率指标: (price / prevPrice)
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator
|
||||
|
||||
|
||||
|
@ -410,7 +410,7 @@ inline price_t* IndicatorImp::data(size_t result_num) {
|
||||
}
|
||||
|
||||
inline size_t IndicatorImp::_get_step_start(size_t pos, size_t step, size_t discard) {
|
||||
return pos < discard + step ? discard : pos + 1 - step;
|
||||
return step == 0 || pos < discard + step ? discard : pos + 1 - step;
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -34,6 +34,12 @@ inline Indicator AVEDEV(const Indicator& ind, const Indicator& n) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator AVEDEV(const Indicator& ind, const IndParam& n) {
|
||||
Indicator result = ABS(ind - MA(ind, n)) / n.get();
|
||||
result.name("AVEDEV");
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_AVEDEV_H_ */
|
||||
|
@ -25,12 +25,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API BACKSET(int n = 2);
|
||||
Indicator BACKSET(const Indicator& ind, int n = 2);
|
||||
Indicator HKU_API BACKSET(const IndParam& n);
|
||||
|
||||
inline Indicator BACKSET(const Indicator& ind, int n) {
|
||||
inline Indicator BACKSET(const Indicator& ind, int n = 2) {
|
||||
return BACKSET(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator BACKSET(const Indicator& ind, const IndParam& n) {
|
||||
return BACKSET(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator BACKSET(const Indicator& ind, const Indicator& n) {
|
||||
return BACKSET(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_BACKSET_H_ */
|
||||
|
@ -24,6 +24,7 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API COUNT(int n = 20);
|
||||
Indicator HKU_API COUNT(const IndParam& n);
|
||||
|
||||
/**
|
||||
* 统计总数 统计满足条件的周期数。
|
||||
@ -36,7 +37,17 @@ Indicator HKU_API COUNT(int n = 20);
|
||||
* @param n 周期数
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API COUNT(const Indicator& ind, int n = 20);
|
||||
inline Indicator HKU_API COUNT(const Indicator& ind, int n = 20) {
|
||||
return COUNT(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator HKU_API COUNT(const Indicator& ind, const IndParam& n) {
|
||||
return COUNT(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator HKU_API COUNT(const Indicator& ind, const Indicator& n) {
|
||||
return COUNT(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
|
@ -20,14 +20,24 @@ namespace hku {
|
||||
* 连跌周期, DOWNNDAY(CLOSE,M)表示连跌M个周期
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator DOWNNDAY(const Indicator& ind, int n = 3);
|
||||
|
||||
inline Indicator DOWNNDAY(const Indicator& ind, int n) {
|
||||
inline Indicator DOWNNDAY(const Indicator& ind, int n = 3) {
|
||||
Indicator result = EVERY(REF(ind, 1) > ind, n);
|
||||
result.name("DOWNNDAY");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator DOWNNDAY(const Indicator& ind, const Indicator& n) {
|
||||
Indicator result = EVERY(REF(ind, 1) > ind, n);
|
||||
result.name("DOWNNDAY");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator DOWNNDAY(const Indicator& ind, const IndParam& n) {
|
||||
Indicator result = EVERY(REF(ind, 1) > ind, n.get());
|
||||
result.name("DOWNNDAY");
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_DOWNNDAY_H_ */
|
||||
|
@ -25,12 +25,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API EXIST(int n = 20);
|
||||
Indicator EXIST(const Indicator& ind, int n = 20);
|
||||
Indicator HKU_API EXIST(const IndParam& n);
|
||||
|
||||
inline Indicator EXIST(const Indicator& ind, int n) {
|
||||
inline Indicator EXIST(const Indicator& ind, int n = 20) {
|
||||
return EXIST(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator EXIST(const Indicator& ind, const IndParam& n) {
|
||||
return EXIST(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator EXIST(const Indicator& ind, const Indicator& n) {
|
||||
return EXIST(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_EXIST_H_ */
|
||||
|
@ -19,18 +19,26 @@ namespace hku {
|
||||
* 信号过滤, 过滤连续出现的信号。
|
||||
* @details
|
||||
* <pre>
|
||||
* 用法:FILTER(X,N): X 满足条件后,删除其后 N 周期内的数据置为 0。
|
||||
* 用法:FILTER(X,N): X 满足条件后,删除其后 N 周期内的数据置为 0
|
||||
* 例如:FILTER(CLOSE>OPEN,5) 查找阳线,5天内再次出现的阳线不被记录在内。
|
||||
* </pre>
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API FILTER(int n = 5);
|
||||
Indicator FILTER(const Indicator& ind, int n = 5);
|
||||
Indicator HKU_API FILTER(const IndParam& n);
|
||||
|
||||
inline Indicator FILTER(const Indicator& ind, int n) {
|
||||
inline Indicator FILTER(const Indicator& ind, int n = 5) {
|
||||
return FILTER(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator FILTER(const Indicator& ind, const IndParam& n) {
|
||||
return FILTER(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator FILTER(const Indicator& ind, const Indicator& n) {
|
||||
return FILTER(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_FILTER_H_ */
|
||||
|
@ -25,12 +25,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API HHVBARS(int n = 20);
|
||||
Indicator HHVBARS(const Indicator& ind, int n = 20);
|
||||
Indicator HKU_API HHVBARS(const IndParam& n);
|
||||
|
||||
inline Indicator HHVBARS(const Indicator& ind, int n) {
|
||||
inline Indicator HHVBARS(const Indicator& ind, int n = 20) {
|
||||
return HHVBARS(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator HHVBARS(const Indicator& ind, const IndParam& n) {
|
||||
return HHVBARS(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator HHVBARS(const Indicator& ind, const Indicator& n) {
|
||||
return HHVBARS(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_HHVBARS_H_ */
|
||||
|
@ -25,12 +25,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API LLVBARS(int n = 20);
|
||||
Indicator LLVBARS(const Indicator& ind, int n = 20);
|
||||
Indicator HKU_API LLVBARS(const IndParam& n);
|
||||
|
||||
inline Indicator LLVBARS(const Indicator& ind, int n) {
|
||||
inline Indicator LLVBARS(const Indicator& ind, int n = 20) {
|
||||
return LLVBARS(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator LLVBARS(const Indicator& ind, const IndParam& n) {
|
||||
return LLVBARS(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator LLVBARS(const Indicator& ind, const Indicator& n) {
|
||||
return LLVBARS(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_LLVBARS_H_ */
|
||||
|
@ -16,7 +16,7 @@ namespace hku {
|
||||
/**
|
||||
* 简单移动平均
|
||||
* @param data 待计算的数据
|
||||
* @param n 计算均值的周期窗口,必须为大于0的整数
|
||||
* @param n 计算均值的周期窗口,n为0时从第一个有效数据开始计算
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API MA(int n = 22);
|
||||
|
@ -20,9 +20,19 @@ namespace hku {
|
||||
* 连大, NDAY(X,Y,N)表示条件X>Y持续存在N个周期
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator NDAY(const Indicator& x, const Indicator& y, int n = 3);
|
||||
inline Indicator NDAY(const Indicator& x, const Indicator& y, int n = 3) {
|
||||
Indicator result = EVERY(x > y, n);
|
||||
result.name("NDAY");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator NDAY(const Indicator& x, const Indicator& y, int n) {
|
||||
inline Indicator NDAY(const Indicator& x, const Indicator& y, const Indicator& n) {
|
||||
Indicator result = EVERY(x > y, n);
|
||||
result.name("NDAY");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator NDAY(const Indicator& x, const Indicator& y, const IndParam& n) {
|
||||
Indicator result = EVERY(x > y, n);
|
||||
result.name("NDAY");
|
||||
return result;
|
||||
|
@ -25,13 +25,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API POW(int n);
|
||||
Indicator POW(price_t, int n);
|
||||
Indicator POW(const Indicator& ind, int n);
|
||||
Indicator HKU_API POW(const IndParam& n);
|
||||
|
||||
inline Indicator POW(const Indicator& ind, int n) {
|
||||
return POW(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator POW(const Indicator& ind, const IndParam& n) {
|
||||
return POW(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator POW(const Indicator& ind, const Indicator& n) {
|
||||
return POW(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
inline Indicator POW(price_t val, int n) {
|
||||
return POW(CVAL(val), n);
|
||||
}
|
||||
|
@ -20,12 +20,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROC(int n = 10);
|
||||
Indicator ROC(const Indicator& ind, int n = 10);
|
||||
Indicator HKU_API ROC(const IndParam& n);
|
||||
|
||||
inline Indicator ROC(const Indicator& ind, int n) {
|
||||
inline Indicator ROC(const Indicator& ind, int n = 10) {
|
||||
return ROC(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROC(const Indicator& ind, const IndParam& n) {
|
||||
return ROC(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROC(const Indicator& ind, const Indicator& n) {
|
||||
return ROC(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_ROC_H_ */
|
||||
|
@ -20,12 +20,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROCP(int n = 10);
|
||||
Indicator ROCP(const Indicator& ind, int n = 10);
|
||||
Indicator HKU_API ROCP(const IndParam& n);
|
||||
|
||||
inline Indicator ROCP(const Indicator& ind, int n) {
|
||||
inline Indicator ROCP(const Indicator& ind, int n = 10) {
|
||||
return ROCP(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROCP(const Indicator& ind, const IndParam& n) {
|
||||
return ROCP(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROCP(const Indicator& ind, const Indicator& n) {
|
||||
return ROCP(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_ROCP_H_ */
|
||||
|
@ -20,12 +20,20 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROCR(int n = 10);
|
||||
Indicator ROCR(const Indicator& ind, int n = 10);
|
||||
Indicator HKU_API ROCR(const IndParam& n);
|
||||
|
||||
inline Indicator ROCR(const Indicator& ind, int n) {
|
||||
inline Indicator ROCR(const Indicator& ind, int n = 10) {
|
||||
return ROCR(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROCR(const Indicator& ind, const IndParam& n) {
|
||||
return ROCR(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROCR(const Indicator& ind, const Indicator& n) {
|
||||
return ROCR(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
#endif /* INDICATOR_CRT_ROCR_H_ */
|
||||
|
@ -73,10 +73,29 @@ void IBackset::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IBackset::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = _get_step_start(curPos, step, ind.discard());
|
||||
if (ind[curPos] == 0.0) {
|
||||
for (size_t i = start; i <= curPos; i++) {
|
||||
_set(0.0, curPos);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = start; i <= curPos; i++) {
|
||||
_set(1.0, curPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API BACKSET(int n) {
|
||||
IndicatorImpPtr p = make_shared<IBackset>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API BACKSET(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IBackset>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,12 +16,16 @@
|
||||
namespace hku {
|
||||
|
||||
class IBackset : public IndicatorImp {
|
||||
INDICATOR_IMP(IBackset)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IBackset)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IBackset();
|
||||
virtual ~IBackset();
|
||||
|
||||
virtual bool isSerial() const override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -79,14 +79,50 @@ void ICount::_calculate(const Indicator& data) {
|
||||
}
|
||||
}
|
||||
|
||||
void ICount::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = 0;
|
||||
if (0 == step) {
|
||||
start = ind.discard();
|
||||
} else if (curPos < ind.discard() + step - 1) {
|
||||
return;
|
||||
} else {
|
||||
start = curPos + 1 - step;
|
||||
}
|
||||
price_t count = 0;
|
||||
for (size_t i = start; i <= curPos; i++) {
|
||||
if (ind[i] != 0.0) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
_set(count, curPos);
|
||||
}
|
||||
|
||||
void ICount::_after_dyn_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
HKU_IF_RETURN(m_discard == total, void());
|
||||
|
||||
size_t discard = m_discard;
|
||||
for (size_t i = total - 1; i > discard; i--) {
|
||||
if (std::isnan(get(i))) {
|
||||
m_discard = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_discard == discard && std::isnan(get(discard))) {
|
||||
m_discard = discard + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API COUNT(int n) {
|
||||
IndicatorImpPtr p = make_shared<ICount>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API COUNT(const Indicator& ind, int n) {
|
||||
return COUNT(n)(ind);
|
||||
Indicator HKU_API COUNT(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<ICount>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -19,12 +19,14 @@ namespace hku {
|
||||
* COUNT(CLOSE>OPEN,20)表示统计20周期内收阳的周期数
|
||||
*/
|
||||
class ICount : public IndicatorImp {
|
||||
INDICATOR_IMP(ICount)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(ICount)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
ICount();
|
||||
virtual ~ICount();
|
||||
|
||||
virtual void _after_dyn_calculate(const Indicator& ind) override;
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -32,6 +32,18 @@ void IExist::_calculate(const Indicator& ind) {
|
||||
int n = getParam<int>("n");
|
||||
if (n == 0) {
|
||||
n = total;
|
||||
m_discard = ind.discard();
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
price_t exist = 0.0;
|
||||
for (size_t j = m_discard; j <= i; j++) {
|
||||
if (ind[j] != 0.0) {
|
||||
exist = 1.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_set(exist, i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_discard = ind.discard() + n - 1;
|
||||
@ -75,10 +87,52 @@ void IExist::_calculate(const Indicator& ind) {
|
||||
_set(exist, total - 1);
|
||||
}
|
||||
|
||||
void IExist::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = 0;
|
||||
if (0 == step) {
|
||||
start = ind.discard();
|
||||
} else if (curPos < ind.discard() + step - 1) {
|
||||
return;
|
||||
} else {
|
||||
start = curPos + 1 - step;
|
||||
}
|
||||
|
||||
price_t exist = 0.0;
|
||||
for (size_t i = start; i <= curPos; i++) {
|
||||
if (ind[i] != 0.0) {
|
||||
exist = 1.0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
_set(exist, curPos);
|
||||
}
|
||||
|
||||
void IExist::_after_dyn_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
HKU_IF_RETURN(m_discard == total, void());
|
||||
|
||||
size_t discard = m_discard;
|
||||
for (size_t i = total - 1; i > discard; i--) {
|
||||
if (std::isnan(get(i))) {
|
||||
m_discard = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_discard == discard && std::isnan(get(discard))) {
|
||||
m_discard = discard + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API EXIST(int n) {
|
||||
IndicatorImpPtr p = make_shared<IExist>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API EXIST(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IExist>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -19,12 +19,14 @@ namespace hku {
|
||||
* 存在, EXIST(X,N) 表示条件X在N周期有存在
|
||||
*/
|
||||
class IExist : public IndicatorImp {
|
||||
INDICATOR_IMP(IExist)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IExist)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IExist();
|
||||
virtual ~IExist();
|
||||
|
||||
virtual void _after_dyn_calculate(const Indicator& ind) override;
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -22,7 +22,7 @@ IFilter::IFilter() : IndicatorImp("FILTER", 1) {
|
||||
IFilter::~IFilter() {}
|
||||
|
||||
bool IFilter::check() {
|
||||
return getParam<int>("n") >= 1;
|
||||
return getParam<int>("n") >= 0;
|
||||
}
|
||||
|
||||
void IFilter::_calculate(const Indicator& ind) {
|
||||
@ -34,6 +34,13 @@ void IFilter::_calculate(const Indicator& ind) {
|
||||
}
|
||||
|
||||
int n = getParam<int>("n");
|
||||
if (0 == n) {
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
_set(ind[i] != 0.0 ? 1.0 : 0.0, i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
size_t i = m_discard;
|
||||
while (i < total) {
|
||||
if (ind[i] == 0.0) {
|
||||
@ -53,10 +60,33 @@ void IFilter::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IFilter::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
price_t val = get(curPos);
|
||||
HKU_IF_RETURN(!std::isnan(val) && val == 0.0, void());
|
||||
if (ind[curPos] == 0.0) {
|
||||
_set(0.0, curPos);
|
||||
} else {
|
||||
_set(1.0, curPos);
|
||||
size_t end = curPos + step + 1;
|
||||
if (end > ind.size()) {
|
||||
end = ind.size();
|
||||
}
|
||||
for (size_t i = curPos + 1; i < end; i++) {
|
||||
_set(0.0, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API FILTER(int n) {
|
||||
IndicatorImpPtr p = make_shared<IFilter>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API FILTER(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IFilter>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,12 +16,16 @@
|
||||
namespace hku {
|
||||
|
||||
class IFilter : public IndicatorImp {
|
||||
INDICATOR_IMP(IFilter)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IFilter)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IFilter();
|
||||
virtual ~IFilter();
|
||||
|
||||
virtual bool isSerial() const override {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -85,10 +85,29 @@ void IHhvbars::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IHhvbars::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = _get_step_start(curPos, step, ind.discard());
|
||||
price_t maxVal = ind[start];
|
||||
size_t maxPos = start;
|
||||
for (size_t i = start + 1; i <= curPos; i++) {
|
||||
if (ind[i] > maxVal) {
|
||||
maxVal = ind[i];
|
||||
maxPos = i;
|
||||
}
|
||||
}
|
||||
_set(curPos - maxPos, curPos);
|
||||
}
|
||||
|
||||
Indicator HKU_API HHVBARS(int n) {
|
||||
IndicatorImpPtr p = make_shared<IHhvbars>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API HHVBARS(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IHhvbars>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace hku {
|
||||
|
||||
class IHhvbars : public IndicatorImp {
|
||||
INDICATOR_IMP(IHhvbars)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IHhvbars)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
|
@ -84,10 +84,29 @@ void ILowLineBars::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void ILowLineBars::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = _get_step_start(curPos, step, ind.discard());
|
||||
price_t minVal = ind[start];
|
||||
size_t minPos = start;
|
||||
for (size_t i = start + 1; i <= curPos; i++) {
|
||||
if (ind[i] < minVal) {
|
||||
minVal = ind[i];
|
||||
minPos = i;
|
||||
}
|
||||
}
|
||||
_set(curPos - minPos, curPos);
|
||||
}
|
||||
|
||||
Indicator HKU_API LLVBARS(int n) {
|
||||
IndicatorImpPtr p = make_shared<ILowLineBars>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API LLVBARS(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<ILowLineBars>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,7 +16,7 @@
|
||||
namespace hku {
|
||||
|
||||
class ILowLineBars : public IndicatorImp {
|
||||
INDICATOR_IMP(ILowLineBars)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(ILowLineBars)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
|
@ -20,7 +20,7 @@ IMa::IMa() : IndicatorImp("MA", 1) {
|
||||
IMa::~IMa() {}
|
||||
|
||||
bool IMa::check() {
|
||||
return getParam<int>("n") >= 1;
|
||||
return getParam<int>("n") >= 0;
|
||||
}
|
||||
|
||||
void IMa::_calculate(const Indicator& indicator) {
|
||||
@ -32,6 +32,15 @@ void IMa::_calculate(const Indicator& indicator) {
|
||||
}
|
||||
|
||||
int n = getParam<int>("n");
|
||||
if (0 == n) {
|
||||
price_t sum = 0.0;
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
sum += indicator[i];
|
||||
_set(sum / (i - m_discard + 1), i);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
size_t startPos = m_discard;
|
||||
price_t sum = 0.0;
|
||||
size_t count = 1;
|
||||
|
@ -39,10 +39,20 @@ void IPow::_calculate(const Indicator& data) {
|
||||
}
|
||||
}
|
||||
|
||||
void IPow::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
_set(std::pow(ind[curPos], step), curPos);
|
||||
}
|
||||
|
||||
Indicator HKU_API POW(int n) {
|
||||
IndicatorImpPtr p = make_shared<IPow>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API POW(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IPow>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -19,7 +19,7 @@ namespace hku {
|
||||
* 乘幂
|
||||
*/
|
||||
class IPow : public IndicatorImp {
|
||||
INDICATOR_IMP(IPow)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IPow)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
|
@ -22,7 +22,7 @@ IRoc::IRoc() : IndicatorImp("ROC", 1) {
|
||||
IRoc::~IRoc() {}
|
||||
|
||||
bool IRoc::check() {
|
||||
return getParam<int>("n") >= 1;
|
||||
return getParam<int>("n") >= 0;
|
||||
}
|
||||
|
||||
void IRoc::_calculate(const Indicator& ind) {
|
||||
@ -35,6 +35,21 @@ void IRoc::_calculate(const Indicator& ind) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == n) {
|
||||
price_t pre_price = ind[m_discard];
|
||||
if (pre_price != 0.0) {
|
||||
_set(0.0, m_discard);
|
||||
for (size_t i = m_discard + 1; i < total; i++) {
|
||||
_set((ind[i] / pre_price - 1.0) * 100, i);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
_set(0.0, i);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
price_t pre_price = ind[i - n];
|
||||
if (pre_price != 0.0) {
|
||||
@ -45,10 +60,45 @@ void IRoc::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IRoc::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = 0;
|
||||
if (0 == step) {
|
||||
start = ind.discard();
|
||||
} else if (curPos < ind.discard() + step) {
|
||||
return;
|
||||
} else {
|
||||
start = curPos - step;
|
||||
}
|
||||
|
||||
_set(ind[start] != 0.0 ? ((ind[curPos] / ind[start]) - 1.0) * 100 : 0.0, curPos);
|
||||
}
|
||||
|
||||
void IRoc::_after_dyn_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
HKU_IF_RETURN(m_discard == total, void());
|
||||
|
||||
size_t discard = m_discard;
|
||||
for (size_t i = total - 1; i > discard; i--) {
|
||||
if (std::isnan(get(i))) {
|
||||
m_discard = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_discard == discard && std::isnan(get(discard))) {
|
||||
m_discard = discard + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API ROC(int n) {
|
||||
IndicatorImpPtr p = make_shared<IRoc>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API ROC(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IRoc>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,12 +16,14 @@
|
||||
namespace hku {
|
||||
|
||||
class IRoc : public hku::IndicatorImp {
|
||||
INDICATOR_IMP(IRoc)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IRoc)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IRoc();
|
||||
virtual ~IRoc();
|
||||
|
||||
virtual void _after_dyn_calculate(const Indicator& ind) override;
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -22,7 +22,7 @@ IRocp::IRocp() : IndicatorImp("ROCP", 1) {
|
||||
IRocp::~IRocp() {}
|
||||
|
||||
bool IRocp::check() {
|
||||
return getParam<int>("n") >= 1;
|
||||
return getParam<int>("n") >= 0;
|
||||
}
|
||||
|
||||
void IRocp::_calculate(const Indicator& ind) {
|
||||
@ -35,6 +35,21 @@ void IRocp::_calculate(const Indicator& ind) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == n) {
|
||||
price_t pre_price = ind[m_discard];
|
||||
if (pre_price != 0.0) {
|
||||
_set(0.0, m_discard);
|
||||
for (size_t i = m_discard + 1; i < total; i++) {
|
||||
_set((ind[i] - pre_price) / pre_price, i);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
_set(0.0, i);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
price_t pre_price = ind[i - n];
|
||||
if (pre_price != 0.0) {
|
||||
@ -45,10 +60,45 @@ void IRocp::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IRocp::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = 0;
|
||||
if (0 == step) {
|
||||
start = ind.discard();
|
||||
} else if (curPos < ind.discard() + step) {
|
||||
return;
|
||||
} else {
|
||||
start = curPos - step;
|
||||
}
|
||||
|
||||
_set(ind[start] != 0.0 ? (ind[curPos] - ind[start]) / ind[start] : 0.0, curPos);
|
||||
}
|
||||
|
||||
void IRocp::_after_dyn_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
HKU_IF_RETURN(m_discard == total, void());
|
||||
|
||||
size_t discard = m_discard;
|
||||
for (size_t i = total - 1; i > discard; i--) {
|
||||
if (std::isnan(get(i))) {
|
||||
m_discard = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_discard == discard && std::isnan(get(discard))) {
|
||||
m_discard = discard + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API ROCP(int n) {
|
||||
IndicatorImpPtr p = make_shared<IRocp>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API ROCP(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IRocp>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,12 +16,14 @@
|
||||
namespace hku {
|
||||
|
||||
class IRocp : public hku::IndicatorImp {
|
||||
INDICATOR_IMP(IRocp)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IRocp)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IRocp();
|
||||
virtual ~IRocp();
|
||||
|
||||
virtual void _after_dyn_calculate(const Indicator& ind) override;
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -22,7 +22,7 @@ IRocr::IRocr() : IndicatorImp("ROCR", 1) {
|
||||
IRocr::~IRocr() {}
|
||||
|
||||
bool IRocr::check() {
|
||||
return getParam<int>("n") >= 1;
|
||||
return getParam<int>("n") >= 0;
|
||||
}
|
||||
|
||||
void IRocr::_calculate(const Indicator& ind) {
|
||||
@ -35,6 +35,21 @@ void IRocr::_calculate(const Indicator& ind) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 == n) {
|
||||
price_t pre_price = ind[m_discard];
|
||||
if (pre_price != 0.0) {
|
||||
_set(1.0, m_discard);
|
||||
for (size_t i = m_discard + 1; i < total; i++) {
|
||||
_set(ind[i] / pre_price, i);
|
||||
}
|
||||
} else {
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
_set(0.0, i);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
for (size_t i = m_discard; i < total; i++) {
|
||||
price_t pre_price = ind[i - n];
|
||||
if (pre_price != 0.0) {
|
||||
@ -45,10 +60,45 @@ void IRocr::_calculate(const Indicator& ind) {
|
||||
}
|
||||
}
|
||||
|
||||
void IRocr::_dyn_run_one_step(const Indicator& ind, size_t curPos, size_t step) {
|
||||
size_t start = 0;
|
||||
if (0 == step) {
|
||||
start = ind.discard();
|
||||
} else if (curPos < ind.discard() + step) {
|
||||
return;
|
||||
} else {
|
||||
start = curPos - step;
|
||||
}
|
||||
|
||||
_set(ind[start] != 0.0 ? ind[curPos] / ind[start] : 0.0, curPos);
|
||||
}
|
||||
|
||||
void IRocr::_after_dyn_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
HKU_IF_RETURN(m_discard == total, void());
|
||||
|
||||
size_t discard = m_discard;
|
||||
for (size_t i = total - 1; i > discard; i--) {
|
||||
if (std::isnan(get(i))) {
|
||||
m_discard = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_discard == discard && std::isnan(get(discard))) {
|
||||
m_discard = discard + 1;
|
||||
}
|
||||
}
|
||||
|
||||
Indicator HKU_API ROCR(int n) {
|
||||
IndicatorImpPtr p = make_shared<IRocr>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API ROCR(const IndParam& n) {
|
||||
IndicatorImpPtr p = make_shared<IRocr>();
|
||||
p->setIndParam("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -16,12 +16,14 @@
|
||||
namespace hku {
|
||||
|
||||
class IRocr : public hku::IndicatorImp {
|
||||
INDICATOR_IMP(IRocr)
|
||||
INDICATOR_IMP_SUPPORT_IND_PARAM(IRocr)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
IRocr();
|
||||
virtual ~IRocr();
|
||||
|
||||
virtual void _after_dyn_calculate(const Indicator& ind) override;
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -28,11 +28,22 @@ TEST_CASE("test_AVEDEV_dyn") {
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = AVEDEV(c, 10);
|
||||
Indicator result = AVEDEV(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.size(); i++) {
|
||||
if (i >= result.discard()) {
|
||||
CHECK(!isnan(result[i]));
|
||||
}
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = AVEDEV(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/BACKSET.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
#include <hikyuu/indicator/crt/PRICELIST.h>
|
||||
|
||||
@ -120,6 +121,34 @@ TEST_CASE("test_BACKSET") {
|
||||
CHECK_EQ(result[10], 1);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_BACKSET_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = BACKSET(c, 10);
|
||||
Indicator result = BACKSET(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(!std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = BACKSET(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(!std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
#include <hikyuu/indicator/crt/COUNT.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/REF.h>
|
||||
|
||||
using namespace hku;
|
||||
@ -51,6 +52,45 @@ TEST_CASE("test_COUNT") {
|
||||
CHECK_EQ(x[7], 4);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_COUNT_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = COUNT(c, 10);
|
||||
Indicator result = COUNT(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = COUNT(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = COUNT(c, 0);
|
||||
result = COUNT(c, IndParam(CVAL(c, 0)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -28,11 +28,22 @@ TEST_CASE("test_DEVSQ_dyn") {
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = DEVSQ(c, 10);
|
||||
Indicator result = DEVSQ(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.size(); i++) {
|
||||
if (i >= result.discard()) {
|
||||
CHECK(!isnan(result[i]));
|
||||
}
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = DEVSQ(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
51
hikyuu_cpp/unit_test/hikyuu/indicator/test_DOWNNDAY.cpp
Normal file
51
hikyuu_cpp/unit_test/hikyuu/indicator/test_DOWNNDAY.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* test_AMA.cpp
|
||||
*
|
||||
* Created on: 2013-4-10
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#include "doctest/doctest.h"
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/DOWNNDAY.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
|
||||
using namespace hku;
|
||||
|
||||
/**
|
||||
* @defgroup test_indicator_AMA test_indicator_DOWNNDAY
|
||||
* @ingroup test_hikyuu_indicator_suite
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_DOWNNDAY_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = DOWNNDAY(c, 10);
|
||||
Indicator result = DOWNNDAY(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = DOWNNDAY(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
@ -126,7 +126,7 @@ TEST_CASE("test_EVERY_dyn") {
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK(isnan(result[i]));
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
@ -137,7 +137,7 @@ TEST_CASE("test_EVERY_dyn") {
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK_UNARY(isnan(result[i]));
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
|
@ -36,11 +36,10 @@ TEST_CASE("test_EXIST") {
|
||||
|
||||
/** @arg n=0 */
|
||||
result = EXIST(data, 0);
|
||||
CHECK_EQ(result.discard(), data.size() - 1);
|
||||
CHECK_EQ(result.discard(), data.discard());
|
||||
CHECK_EQ(result.size(), data.size());
|
||||
CHECK_EQ(result[5], 1);
|
||||
for (int i = 0; i < data.discard(); ++i) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
CHECK_EQ(result[i], data[i]);
|
||||
}
|
||||
|
||||
/** @arg n=1, total>1 */
|
||||
@ -112,6 +111,36 @@ TEST_CASE("test_EXIST") {
|
||||
CHECK_EQ(result[9], 0);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_EXIST_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator o = OPEN(kdata);
|
||||
Indicator expect = EXIST(c > o, 3);
|
||||
Indicator result = EXIST(c > o, CVAL(c, 3));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = EXIST(c > o, 0);
|
||||
result = EXIST(c > o, CVAL(c, 0));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -40,7 +40,7 @@ TEST_CASE("test_FILTER") {
|
||||
/** @arg n=0 */
|
||||
result = FILTER(data, 0);
|
||||
CHECK_EQ(result.name(), "FILTER");
|
||||
CHECK_EQ(result.discard(), data.size());
|
||||
CHECK_EQ(result.discard(), data.discard());
|
||||
CHECK_EQ(result.size(), data.size());
|
||||
|
||||
/** @arg n=1, total>1 */
|
||||
@ -134,6 +134,36 @@ TEST_CASE("test_FILTER") {
|
||||
CHECK_EQ(result[11], 0);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_FILTER_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator o = OPEN(kdata);
|
||||
Indicator expect = FILTER(c > o, 3);
|
||||
Indicator result = FILTER(c > o, CVAL(c, 3));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = FILTER(c > o, 0);
|
||||
result = FILTER(c > o, CVAL(c, 0));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -103,10 +103,32 @@ TEST_CASE("test_HHV_dyn") {
|
||||
expect = HHV(c, 50);
|
||||
result = HHV(c, CVAL(c, 50));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < expect.size(); i++) {
|
||||
if (i >= result.discard()) {
|
||||
CHECK(!isnan(result[i]));
|
||||
}
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
|
||||
result = HHV(c, IndParam(CVAL(c, 50)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
|
||||
expect = HHV(c, 0);
|
||||
result = HHV(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +130,45 @@ TEST_CASE("test_HHVBARS") {
|
||||
CHECK_EQ(result[9], 5);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_HHVBARS_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = HHVBARS(c, 10);
|
||||
Indicator result = HHVBARS(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = HHVBARS(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = HHVBARS(c, 0);
|
||||
result = HHVBARS(c, IndParam(CVAL(c, 0)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -87,6 +87,32 @@ TEST_CASE("test_LLV_dyn") {
|
||||
for (size_t i = 0; i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-100));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
expect = LLV(c, 50);
|
||||
result = LLV(c, CVAL(c, 50));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
|
||||
expect = LLV(c, 0);
|
||||
result = LLV(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -132,6 +132,45 @@ TEST_CASE("test_LLVBARS") {
|
||||
CHECK_EQ(result[9], 0);
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_HHVBARS_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = LLVBARS(c, 10);
|
||||
Indicator result = LLVBARS(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = LLVBARS(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = LLVBARS(c, 0);
|
||||
result = LLVBARS(c, IndParam(CVAL(c, 0)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -40,9 +40,10 @@ TEST_CASE("test_MA") {
|
||||
ma = MA(open, 0);
|
||||
CHECK_EQ(ma.empty(), false);
|
||||
CHECK_EQ(ma.size(), kdata.size());
|
||||
CHECK_EQ(ma.discard(), kdata.size());
|
||||
CHECK_EQ(ma.discard(), 0);
|
||||
for (size_t i = 0; i < kdata.size(); ++i) {
|
||||
CHECK_UNARY(std::isnan(ma[i]));
|
||||
HKU_INFO("i: {}, ma: {}, open: {}", i, ma[i], open[i]);
|
||||
// CHECK_UNARY(std::isnan(ma[i]));
|
||||
}
|
||||
|
||||
/** @arg n = 10 且数据大小刚好为10 时, 正常关联数据 */
|
||||
@ -142,10 +143,31 @@ TEST_CASE("test_MA_dyn") {
|
||||
Indicator result = MA(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < expect.size(); i++) {
|
||||
if (i >= result.discard()) {
|
||||
CHECK(!isnan(result[i]));
|
||||
}
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = MA(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = MA(c, 0);
|
||||
result = MA(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
63
hikyuu_cpp/unit_test/hikyuu/indicator/test_NDAY.cpp
Normal file
63
hikyuu_cpp/unit_test/hikyuu/indicator/test_NDAY.cpp
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* test_AMA.cpp
|
||||
*
|
||||
* Created on: 2013-4-10
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#include "doctest/doctest.h"
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/NDAY.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
|
||||
using namespace hku;
|
||||
|
||||
/**
|
||||
* @defgroup test_indicator_AMA test_indicator_NDAY
|
||||
* @ingroup test_hikyuu_indicator_suite
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_NDAY_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator o = OPEN(kdata);
|
||||
Indicator expect = NDAY(c, o, 10);
|
||||
Indicator result = NDAY(c, o, CVAL(c, 10));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = NDAY(c, o, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = NDAY(c, o, 0);
|
||||
result = NDAY(c, o, CVAL(c, 0));
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(!std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/** @} */
|
@ -47,6 +47,34 @@ TEST_CASE("test_POW") {
|
||||
CHECK_EQ(result[0], std::pow(-11, 3));
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_POW_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = POW(c, 10);
|
||||
Indicator result = POW(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = POW(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// test export
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/ROC.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
#include <hikyuu/indicator/crt/PRICELIST.h>
|
||||
|
||||
@ -52,6 +53,58 @@ TEST_CASE("test_ROC") {
|
||||
CHECK_EQ(result[2], 0);
|
||||
CHECK_EQ(result[3], 200);
|
||||
CHECK_EQ(result[4], 100);
|
||||
|
||||
// n = 0
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
a[i] = i + 1;
|
||||
}
|
||||
data = PRICELIST(a);
|
||||
result = ROC(data, 0);
|
||||
CHECK_EQ(data.discard(), result.discard());
|
||||
CHECK_EQ(data.size(), result.size());
|
||||
CHECK_EQ(result[0], 0.0);
|
||||
for (size_t i = 1; i < result.size(); i++) {
|
||||
CHECK_EQ((data[i] / data[0] - 1.) * 100., result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_ROC_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = ROC(c, 10);
|
||||
Indicator result = ROC(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = ROC(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = ROC(c, 0);
|
||||
result = ROC(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/ROCP.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
#include <hikyuu/indicator/crt/PRICELIST.h>
|
||||
|
||||
@ -52,6 +53,58 @@ TEST_CASE("test_ROCP") {
|
||||
CHECK_EQ(result[2], 0);
|
||||
CHECK_EQ(result[3], 2);
|
||||
CHECK_EQ(result[4], 1);
|
||||
|
||||
// n = 0
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
a[i] = i + 1;
|
||||
}
|
||||
data = PRICELIST(a);
|
||||
result = ROCP(data, 0);
|
||||
CHECK_EQ(data.discard(), result.discard());
|
||||
CHECK_EQ(data.size(), result.size());
|
||||
CHECK_EQ(result[0], 0.0);
|
||||
for (size_t i = 1; i < result.size(); i++) {
|
||||
CHECK_EQ((data[i] - data[0]) / data[0], result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_ROCP_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = ROCP(c, 10);
|
||||
Indicator result = ROCP(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = ROCP(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = ROCP(c, 0);
|
||||
result = ROCP(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <fstream>
|
||||
#include <hikyuu/StockManager.h>
|
||||
#include <hikyuu/indicator/crt/ROCR.h>
|
||||
#include <hikyuu/indicator/crt/CVAL.h>
|
||||
#include <hikyuu/indicator/crt/KDATA.h>
|
||||
#include <hikyuu/indicator/crt/PRICELIST.h>
|
||||
|
||||
@ -52,6 +53,58 @@ TEST_CASE("test_ROCR") {
|
||||
CHECK_EQ(result[2], 0);
|
||||
CHECK_EQ(result[3], 3);
|
||||
CHECK_EQ(result[4], 2);
|
||||
|
||||
// n = 0
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
a[i] = i + 1;
|
||||
}
|
||||
data = PRICELIST(a);
|
||||
result = ROCR(data, 0);
|
||||
CHECK_EQ(data.discard(), result.discard());
|
||||
CHECK_EQ(data.size(), result.size());
|
||||
CHECK_EQ(result[0], 1.0);
|
||||
for (size_t i = 1; i < result.size(); i++) {
|
||||
CHECK_EQ(data[i] / data[0], result[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
TEST_CASE("test_ROCR_dyn") {
|
||||
Stock stock = StockManager::instance().getStock("sh000001");
|
||||
KData kdata = stock.getKData(KQuery(-30));
|
||||
// KData kdata = stock.getKData(KQuery(0, Null<size_t>(), KQuery::MIN));
|
||||
Indicator c = CLOSE(kdata);
|
||||
Indicator expect = ROCR(c, 10);
|
||||
Indicator result = ROCR(c, CVAL(c, 10));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
result = ROCR(c, IndParam(CVAL(c, 10)));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
|
||||
expect = ROCR(c, 0);
|
||||
result = ROCR(c, CVAL(c, 0));
|
||||
CHECK_EQ(expect.size(), result.size());
|
||||
CHECK_EQ(expect.discard(), result.discard());
|
||||
for (size_t i = 0; i < result.discard(); i++) {
|
||||
CHECK_UNARY(std::isnan(result[i]));
|
||||
}
|
||||
for (size_t i = expect.discard(); i < expect.size(); i++) {
|
||||
CHECK_EQ(expect[i], doctest::Approx(result[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -109,7 +109,10 @@ Indicator (*IF_3)(const Indicator&, const Indicator&, price_t) = IF;
|
||||
Indicator (*IF_4)(const Indicator&, price_t, price_t) = IF;
|
||||
|
||||
Indicator (*COUNT_1)(int) = COUNT;
|
||||
Indicator (*COUNT_2)(const Indicator&, int) = COUNT;
|
||||
Indicator (*COUNT_2)(const IndParam&) = COUNT;
|
||||
Indicator (*COUNT_3)(const Indicator&, const Indicator&) = COUNT;
|
||||
Indicator (*COUNT_4)(const Indicator&, const IndParam&) = COUNT;
|
||||
Indicator (*COUNT_5)(const Indicator&, int) = COUNT;
|
||||
|
||||
Indicator (*SUM_1)(int) = SUM;
|
||||
Indicator (*SUM_2)(const Indicator&, int) = SUM;
|
||||
@ -155,14 +158,23 @@ Indicator (*LOG_2)(price_t) = LOG;
|
||||
Indicator (*LOG_3)(const Indicator&) = LOG;
|
||||
|
||||
Indicator (*HHVBARS_1)(int) = HHVBARS;
|
||||
Indicator (*HHVBARS_2)(const Indicator&, int) = HHVBARS;
|
||||
Indicator (*HHVBARS_2)(const IndParam&) = HHVBARS;
|
||||
Indicator (*HHVBARS_3)(const Indicator&, const IndParam&) = HHVBARS;
|
||||
Indicator (*HHVBARS_4)(const Indicator&, const Indicator&) = HHVBARS;
|
||||
Indicator (*HHVBARS_5)(const Indicator&, int) = HHVBARS;
|
||||
|
||||
Indicator (*LLVBARS_1)(int) = LLVBARS;
|
||||
Indicator (*LLVBARS_2)(const Indicator&, int) = LLVBARS;
|
||||
Indicator (*LLVBARS_2)(const IndParam&) = LLVBARS;
|
||||
Indicator (*LLVBARS_3)(const Indicator&, const IndParam&) = LLVBARS;
|
||||
Indicator (*LLVBARS_4)(const Indicator&, const Indicator&) = LLVBARS;
|
||||
Indicator (*LLVBARS_5)(const Indicator&, int) = LLVBARS;
|
||||
|
||||
Indicator (*POW_1)(int) = POW;
|
||||
Indicator (*POW_2)(const Indicator&, int) = POW;
|
||||
Indicator (*POW_3)(price_t, int) = POW;
|
||||
Indicator (*POW_2)(const IndParam&) = POW;
|
||||
Indicator (*POW_3)(const Indicator&, int) = POW;
|
||||
Indicator (*POW_4)(const Indicator&, const IndParam&) = POW;
|
||||
Indicator (*POW_5)(const Indicator&, const Indicator&) = POW;
|
||||
Indicator (*POW_6)(price_t, int) = POW;
|
||||
|
||||
Indicator (*SQRT_1)() = SQRT;
|
||||
Indicator (*SQRT_2)(const Indicator&) = SQRT;
|
||||
@ -193,7 +205,10 @@ Indicator (*INTPART_2)(const Indicator&) = INTPART;
|
||||
Indicator (*INTPART_3)(price_t) = INTPART;
|
||||
|
||||
Indicator (*EXIST_1)(int) = EXIST;
|
||||
Indicator (*EXIST_2)(const Indicator&, int) = EXIST;
|
||||
Indicator (*EXIST_2)(const IndParam&) = EXIST;
|
||||
Indicator (*EXIST_3)(const Indicator&, const IndParam&) = EXIST;
|
||||
Indicator (*EXIST_4)(const Indicator&, const Indicator&) = EXIST;
|
||||
Indicator (*EXIST_5)(const Indicator&, int) = EXIST;
|
||||
|
||||
Indicator (*EVERY_1)(int) = EVERY;
|
||||
Indicator (*EVERY_2)(const IndParam&) = EVERY;
|
||||
@ -254,7 +269,10 @@ Indicator (*LONGCROSS_3)(price_t, const Indicator&, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_4)(price_t, price_t, int) = LONGCROSS;
|
||||
|
||||
Indicator (*FILTER_1)(int) = FILTER;
|
||||
Indicator (*FILTER_2)(const Indicator&, int) = FILTER;
|
||||
Indicator (*FILTER_2)(const IndParam&) = FILTER;
|
||||
Indicator (*FILTER_3)(const Indicator&, const IndParam&) = FILTER;
|
||||
Indicator (*FILTER_4)(const Indicator&, const Indicator&) = FILTER;
|
||||
Indicator (*FILTER_5)(const Indicator&, int) = FILTER;
|
||||
|
||||
Indicator (*BARSSINCE_1)() = BARSSINCE;
|
||||
Indicator (*BARSSINCE_2)(const Indicator&) = BARSSINCE;
|
||||
@ -271,7 +289,10 @@ Indicator (*BARSCOUNT_1)() = BARSCOUNT;
|
||||
Indicator (*BARSCOUNT_2)(const Indicator&) = BARSCOUNT;
|
||||
|
||||
Indicator (*BACKSET_1)(int) = BACKSET;
|
||||
Indicator (*BACKSET_2)(const Indicator&, int) = BACKSET;
|
||||
Indicator (*BACKSET_2)(const IndParam&) = BACKSET;
|
||||
Indicator (*BACKSET_3)(const Indicator&, const IndParam&) = BACKSET;
|
||||
Indicator (*BACKSET_4)(const Indicator&, const Indicator&) = BACKSET;
|
||||
Indicator (*BACKSET_5)(const Indicator&, int) = BACKSET;
|
||||
|
||||
Indicator (*TIMELINE_1)() = TIMELINE;
|
||||
Indicator (*TIMELINE_2)(const KData&) = TIMELINE;
|
||||
@ -286,13 +307,22 @@ Indicator (*DEVSQ_4)(const Indicator&, const IndParam&) = DEVSQ;
|
||||
Indicator (*DEVSQ_5)(const Indicator&, int) = DEVSQ;
|
||||
|
||||
Indicator (*ROC_1)(int) = ROC;
|
||||
Indicator (*ROC_2)(const Indicator&, int) = ROC;
|
||||
Indicator (*ROC_2)(const IndParam&) = ROC;
|
||||
Indicator (*ROC_3)(const Indicator&, const IndParam&) = ROC;
|
||||
Indicator (*ROC_4)(const Indicator&, const Indicator&) = ROC;
|
||||
Indicator (*ROC_5)(const Indicator&, int) = ROC;
|
||||
|
||||
Indicator (*ROCP_1)(int) = ROCP;
|
||||
Indicator (*ROCP_2)(const Indicator&, int) = ROCP;
|
||||
Indicator (*ROCP_2)(const IndParam&) = ROCP;
|
||||
Indicator (*ROCP_3)(const Indicator&, const IndParam&) = ROCP;
|
||||
Indicator (*ROCP_4)(const Indicator&, const Indicator&) = ROCP;
|
||||
Indicator (*ROCP_5)(const Indicator&, int) = ROCP;
|
||||
|
||||
Indicator (*ROCR_1)(int) = ROCR;
|
||||
Indicator (*ROCR_2)(const Indicator&, int) = ROCR;
|
||||
Indicator (*ROCR_2)(const IndParam&) = ROCR;
|
||||
Indicator (*ROCR_3)(const Indicator&, const IndParam&) = ROCR;
|
||||
Indicator (*ROCR_4)(const Indicator&, const Indicator&) = ROCR;
|
||||
Indicator (*ROCR_5)(const Indicator&, int) = ROCR;
|
||||
|
||||
Indicator (*ROCR100_1)(int) = ROCR100;
|
||||
Indicator (*ROCR100_2)(const Indicator&, int) = ROCR100;
|
||||
@ -312,7 +342,16 @@ Indicator (*DROPNA_1)() = DROPNA;
|
||||
Indicator (*DROPNA_2)(const Indicator&) = DROPNA;
|
||||
|
||||
Indicator (*AVEDEV_1)(const Indicator&, int) = AVEDEV;
|
||||
Indicator (*AVEDEV_2)(const Indicator&, const Indicator&) = AVEDEV;
|
||||
Indicator (*AVEDEV_2)(const Indicator&, const IndParam&) = AVEDEV;
|
||||
Indicator (*AVEDEV_3)(const Indicator&, const Indicator&) = AVEDEV;
|
||||
|
||||
Indicator (*DOWNNDAY_1)(const Indicator&, int) = DOWNNDAY;
|
||||
Indicator (*DOWNNDAY_2)(const Indicator&, const IndParam&) = DOWNNDAY;
|
||||
Indicator (*DOWNNDAY_3)(const Indicator&, const Indicator&) = DOWNNDAY;
|
||||
|
||||
Indicator (*NDAY_1)(const Indicator&, const Indicator&, int) = NDAY;
|
||||
Indicator (*NDAY_2)(const Indicator&, const Indicator&, const Indicator&) = NDAY;
|
||||
Indicator (*NDAY_3)(const Indicator&, const Indicator&, const IndParam&) = NDAY;
|
||||
|
||||
void export_Indicator_build_in() {
|
||||
def("KDATA", KDATA1);
|
||||
@ -597,7 +636,10 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("COUNT", COUNT_1, (arg("n") = 20));
|
||||
def("COUNT", COUNT_2, (arg("data"), arg("n") = 20), R"(COUNT([data, n=20])
|
||||
def("COUNT", COUNT_2, (arg("n")));
|
||||
def("COUNT", COUNT_3, (arg("data"), arg("n")));
|
||||
def("COUNT", COUNT_4, (arg("data"), arg("n")));
|
||||
def("COUNT", COUNT_5, (arg("data"), arg("n") = 20), R"(COUNT([data, n=20])
|
||||
|
||||
统计满足条件的周期数。
|
||||
|
||||
@ -606,7 +648,7 @@ void export_Indicator_build_in() {
|
||||
例如:COUNT(CLOSE>OPEN,20)表示统计20周期内收阳的周期数
|
||||
|
||||
:param Indicator data: 条件
|
||||
:param int n: 周期
|
||||
:param int|Indicator|IndParam n: 周期
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("SUM", SUM_1, (arg("n") = 20));
|
||||
@ -712,7 +754,10 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("HHVBARS", HHVBARS_1, (arg("n") = 20));
|
||||
def("HHVBARS", HHVBARS_2, (arg("data"), arg("n") = 20), R"(HHVBARS([data, n=20])
|
||||
def("HHVBARS", HHVBARS_2, (arg("n")));
|
||||
def("HHVBARS", HHVBARS_3, (arg("data"), arg("n")));
|
||||
def("HHVBARS", HHVBARS_4, (arg("data"), arg("n")));
|
||||
def("HHVBARS", HHVBARS_5, (arg("data"), arg("n") = 20), R"(HHVBARS([data, n=20])
|
||||
|
||||
上一高点位置 求上一高点到当前的周期数。
|
||||
|
||||
@ -721,11 +766,14 @@ void export_Indicator_build_in() {
|
||||
例如:HHVBARS(HIGH,0)求得历史新高到到当前的周期数
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: N日时间窗口
|
||||
:param int|Indicator|IndParam n: N日时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("LLVBARS", LLVBARS_1, (arg("n") = 20));
|
||||
def("LLVBARS", LLVBARS_2, (arg("data"), arg("n") = 20), R"(LLVBARS([data, n=20])
|
||||
def("LLVBARS", LLVBARS_2, (arg("n")));
|
||||
def("LLVBARS", LLVBARS_3, (arg("data"), arg("n")));
|
||||
def("LLVBARS", LLVBARS_4, (arg("data"), arg("n")));
|
||||
def("LLVBARS", LLVBARS_5, (arg("data"), arg("n") = 20), R"(LLVBARS([data, n=20])
|
||||
|
||||
上一低点位置 求上一低点到当前的周期数。
|
||||
|
||||
@ -734,12 +782,15 @@ void export_Indicator_build_in() {
|
||||
例如:LLVBARS(HIGH,20)求得20日最低点到当前的周期数
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: N日时间窗口
|
||||
:param int|Indicator|IndParam n: N日时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("POW", POW_1, (arg("n")));
|
||||
def("POW", POW_2, (arg("data"), arg("n")));
|
||||
def("POW", POW_3), (arg("data"), arg("n"), R"(POW(data, n)
|
||||
def("POW", POW_2, (arg("n")));
|
||||
def("POW", POW_3, (arg("data"), arg("n")));
|
||||
def("POW", POW_4, (arg("data"), arg("n")));
|
||||
def("POW", POW_5, (arg("data"), arg("n")));
|
||||
def("POW", POW_6), (arg("data"), arg("n"), R"(POW(data, n)
|
||||
|
||||
乘幂
|
||||
|
||||
@ -748,7 +799,7 @@ void export_Indicator_build_in() {
|
||||
例如:POW(CLOSE,3)求得收盘价的3次方
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 幂
|
||||
:param int|Indicator|IndParam n: 幂
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("SQRT", SQRT_1);
|
||||
@ -830,12 +881,15 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("EXIST", EXIST_1, (arg("n") = 20));
|
||||
def("EXIST", EXIST_2, (arg("data"), arg("n") = 20), R"(EXIST([data, n=20])
|
||||
def("EXIST", EXIST_2, (arg("n")));
|
||||
def("EXIST", EXIST_3, (arg("data"), arg("n")));
|
||||
def("EXIST", EXIST_4, (arg("data"), arg("n")));
|
||||
def("EXIST", EXIST_5, (arg("data"), arg("n") = 20), R"(EXIST([data, n=20])
|
||||
|
||||
存在, EXIST(X,N) 表示条件X在N周期有存在
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 计算均值的周期窗口,必须为大于0的整数
|
||||
:param int|Indicator|IndParam n: 计算均值的周期窗口,必须为大于0的整数
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("EVERY", EVERY_1, (arg("n") = 20));
|
||||
@ -972,21 +1026,25 @@ void export_Indicator_build_in() {
|
||||
:param int n: 时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("DOWNNDAY", DOWNNDAY, (arg("data"), arg("n") = 3), R"(DOWNNDAY(data[, n=3])
|
||||
def("DOWNNDAY", DOWNNDAY_1, (arg("data"), arg("n") = 3));
|
||||
def("DOWNNDAY", DOWNNDAY_2, (arg("data"), arg("n")));
|
||||
def("DOWNNDAY", DOWNNDAY_3, (arg("data"), arg("n")), R"(DOWNNDAY(data[, n=3])
|
||||
|
||||
连跌周期数, DOWNNDAY(CLOSE,M)表示连涨M个周期
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("NDAY", NDAY, (arg("x"), arg("y"), arg("n") = 3), R"(NDAY(x, y[, n=3])
|
||||
def("NDAY", NDAY_1, (arg("x"), arg("y"), arg("n") = 3));
|
||||
def("NDAY", NDAY_1, (arg("x"), arg("y"), arg("n")));
|
||||
def("NDAY", NDAY_3, (arg("x"), arg("y"), arg("n")), R"(NDAY(x, y[, n=3])
|
||||
|
||||
连大, NDAY(X,Y,N)表示条件X>Y持续存在N个周期
|
||||
|
||||
:param Indicator x:
|
||||
:param Indicator y:
|
||||
:param int n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("CROSS", CROSS_1);
|
||||
@ -1017,7 +1075,10 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("FILTER", FILTER_1, (arg("n") = 5));
|
||||
def("FILTER", FILTER_2, (arg("data"), arg("n") = 5), R"(FILTER([data, n=5])
|
||||
def("FILTER", FILTER_2, (arg("n")));
|
||||
def("FILTER", FILTER_3, (arg("data"), arg("n")));
|
||||
def("FILTER", FILTER_4, (arg("data"), arg("n")));
|
||||
def("FILTER", FILTER_5, (arg("data"), arg("n") = 5), R"(FILTER([data, n=5])
|
||||
|
||||
信号过滤, 过滤连续出现的信号。
|
||||
|
||||
@ -1026,7 +1087,7 @@ void export_Indicator_build_in() {
|
||||
例如:FILTER(CLOSE>OPEN,5) 查找阳线,5 天内再次出现的阳线不被记录在内。
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: 过滤周期
|
||||
:param int|Indicaot|IndParam n: 过滤周期
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("BARSSINCE", BARSSINCE_1);
|
||||
@ -1080,8 +1141,11 @@ void export_Indicator_build_in() {
|
||||
:param Indicator data: 输入数据
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("BACKSET", BACKSET_1);
|
||||
def("BACKSET", BACKSET_2, R"(BACKSET([data, n=2])
|
||||
def("BACKSET", BACKSET_1, (arg("n") = 2));
|
||||
def("BACKSET", BACKSET_2, (arg("n")));
|
||||
def("BACKSET", BACKSET_3, (arg("data"), arg("n")));
|
||||
def("BACKSET", BACKSET_4, (arg("data"), arg("n")));
|
||||
def("BACKSET", BACKSET_5, (arg("data"), arg("n") = 2), R"(BACKSET([data, n=2])
|
||||
|
||||
向前赋值将当前位置到若干周期前的数据设为1。
|
||||
|
||||
@ -1090,7 +1154,7 @@ void export_Indicator_build_in() {
|
||||
例如:BACKSET(CLOSE>OPEN,2)若收阳则将该周期及前一周期数值设为1,否则为0
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int n: N周期
|
||||
:param int|Indicator|IndParam n: N周期
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("TIMELINE", TIMELINE_1);
|
||||
@ -1124,12 +1188,13 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("AVEDEV", AVEDEV_1, (arg("data"), arg("n") = 22));
|
||||
def("AVEDEV", AVEDEV_2, (arg("data"), arg("n")), R"(AVEDEV(data[, n=22])
|
||||
def("AVEDEV", AVEDEV_2, (arg("data"), arg("n")));
|
||||
def("AVEDEV", AVEDEV_3, (arg("data"), arg("n")), R"(AVEDEV(data[, n=22])
|
||||
|
||||
平均绝对偏差,求X的N日平均绝对偏差
|
||||
|
||||
:param Indicator data: 输入数据
|
||||
:param int|Indicator n: 时间窗口
|
||||
:param int|Indicator|IndParam n: 时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("DEVSQ", DEVSQ_1, (arg("n") = 10));
|
||||
@ -1145,7 +1210,10 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("ROC", ROC_1, (arg("n") = 10));
|
||||
def("ROC", ROC_2, (arg("data"), arg("n") = 10), R"(ROC([data, n=10])
|
||||
def("ROC", ROC_2, (arg("n")));
|
||||
def("ROC", ROC_3, (arg("data"), arg("n")));
|
||||
def("ROC", ROC_4, (arg("data"), arg("n")));
|
||||
def("ROC", ROC_5, (arg("data"), arg("n") = 10), R"(ROC([data, n=10])
|
||||
|
||||
变动率指标: ((price / prevPrice)-1)*100
|
||||
|
||||
@ -1154,7 +1222,10 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("ROCP", ROCP_1, (arg("n") = 10));
|
||||
def("ROCP", ROCP_2, (arg("data"), arg("n") = 10), R"(ROCP([data, n=10])
|
||||
def("ROCP", ROCP_2, (arg("n")));
|
||||
def("ROCP", ROCP_3, (arg("data"), arg("n")));
|
||||
def("ROCP", ROCP_4, (arg("data"), arg("n")));
|
||||
def("ROCP", ROCP_5, (arg("data"), arg("n") = 10), R"(ROCP([data, n=10])
|
||||
|
||||
变动率指标: (price - prevPrice) / prevPrice
|
||||
|
||||
@ -1163,12 +1234,15 @@ void export_Indicator_build_in() {
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("ROCR", ROCR_1, (arg("n") = 10));
|
||||
def("ROCR", ROCR_2, (arg("data"), arg("n") = 10), R"(ROCR([data, n=10])
|
||||
def("ROCR", ROCR_2, (arg("n")));
|
||||
def("ROCR", ROCR_3, (arg("data"), arg("n")));
|
||||
def("ROCR", ROCR_4, (arg("data"), arg("n")));
|
||||
def("ROCR", ROCR_5, (arg("data"), arg("n") = 10), R"(ROCR([data, n=10])
|
||||
|
||||
变动率指标: (price / prevPrice)
|
||||
|
||||
:param data: 输入数据
|
||||
:param int n: 时间窗口
|
||||
:param int n|Indicator|IndParam: 时间窗口
|
||||
:rtype: Indicator)");
|
||||
|
||||
def("ROCR100", ROCR100_1, (arg("n") = 10));
|
||||
|
Loading…
Reference in New Issue
Block a user