mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-05 05:17:47 +08:00
Merge pull request #177 from fasiondog/feature/simd
增加编译参数 low_precision, 支持 Indicator 以 float 的较低精度方式执行
This commit is contained in:
commit
e87599f002
@ -49,6 +49,9 @@
|
||||
// 启用通达信本地 K线数据引擎
|
||||
#define HKU_ENABLE_TDX_KDATA ${HKU_ENABLE_TDX_KDATA}
|
||||
|
||||
// 使用低精度版本,Indicator 使用 float 类型进行计算
|
||||
#define HKU_USE_LOW_PRECISION ${HKU_USE_LOW_PRECISION}
|
||||
|
||||
// clang-format on
|
||||
|
||||
#endif /* HIKYUU_CONFIG_H_ */
|
@ -50,7 +50,11 @@ void GlobalInitializer::init() {
|
||||
_CrtSetBreakAlloc(-1);
|
||||
#endif
|
||||
|
||||
#if HKU_USE_LOW_PRECISION
|
||||
fmt::print("Initialize hikyuu_{}_low_precision ...\n", getVersionWithBuild());
|
||||
#else
|
||||
fmt::print("Initialize hikyuu_{} ...\n", getVersionWithBuild());
|
||||
#endif
|
||||
|
||||
initLogger();
|
||||
#if defined(_DEBUG) || defined(DEBUG)
|
||||
|
@ -173,107 +173,107 @@ HKU_API Indicator operator|(const Indicator& ind1, const Indicator& ind2) {
|
||||
return p->calculate();
|
||||
}
|
||||
|
||||
HKU_API Indicator operator+(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator+(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind + CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator+(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator+(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) + ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator-(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator-(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind - CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator-(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator-(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) - ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator*(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator*(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind * CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator*(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator*(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) * ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator/(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator/(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind / CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator/(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator/(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) / ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator%(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator%(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind % CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator%(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator%(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) % ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator==(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator==(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind == CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator==(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator==(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) == ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator!=(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator!=(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind != CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator!=(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator!=(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) != ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator>(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator>(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind > CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator>(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator>(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) > ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator<(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator<(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind < CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator<(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator<(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) < ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator>=(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator>=(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind >= CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator>=(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator>=(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) >= ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator<=(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator<=(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind <= CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator<=(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator<=(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) <= ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator&(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator&(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind & CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator&(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator&(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) & ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator|(const Indicator& ind, price_t val) {
|
||||
HKU_API Indicator operator|(const Indicator& ind, Indicator::value_type val) {
|
||||
return ind | CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator|(price_t val, const Indicator& ind) {
|
||||
HKU_API Indicator operator|(Indicator::value_type val, const Indicator& ind) {
|
||||
return CVAL(ind, val) | ind;
|
||||
}
|
||||
|
||||
@ -293,15 +293,15 @@ Indicator HKU_API IF(const Indicator& ind1, const Indicator& ind2, const Indicat
|
||||
return p->calculate();
|
||||
}
|
||||
|
||||
Indicator HKU_API IF(const Indicator& x, price_t a, const Indicator& b) {
|
||||
Indicator HKU_API IF(const Indicator& x, Indicator::value_type a, const Indicator& b) {
|
||||
return IF(x, CVAL(b, a), b);
|
||||
}
|
||||
|
||||
Indicator HKU_API IF(const Indicator& x, const Indicator& a, price_t b) {
|
||||
Indicator HKU_API IF(const Indicator& x, const Indicator& a, Indicator::value_type b) {
|
||||
return IF(x, a, CVAL(a, b));
|
||||
}
|
||||
|
||||
Indicator HKU_API IF(const Indicator& x, price_t a, price_t b) {
|
||||
Indicator HKU_API IF(const Indicator& x, Indicator::value_type a, Indicator::value_type b) {
|
||||
return IF(x, CVAL(x, a), CVAL(x, b));
|
||||
}
|
||||
|
||||
|
@ -98,17 +98,17 @@ public:
|
||||
size_t size() const;
|
||||
|
||||
/** 只获取第一个结果集中相应位置输出,等同于get(pos, 0) */
|
||||
price_t operator[](size_t pos) const;
|
||||
value_type operator[](size_t pos) const;
|
||||
|
||||
/** 只获取第一个结果集中相应位置输出,等同于getByDate(date, 0) */
|
||||
price_t operator[](Datetime) const;
|
||||
value_type operator[](Datetime) const;
|
||||
|
||||
/**
|
||||
* 获取第num个结果集中指定位置的数据
|
||||
* @param pos 结果集中的位置
|
||||
* @param num 第几个结果集
|
||||
*/
|
||||
price_t get(size_t pos, size_t num = 0) const;
|
||||
value_type get(size_t pos, size_t num = 0) const;
|
||||
|
||||
/**
|
||||
* 获取指定位置的日期
|
||||
@ -121,7 +121,7 @@ public:
|
||||
* @param date 指定日期
|
||||
* @param num 第几个结果集
|
||||
*/
|
||||
price_t getByDate(Datetime date, size_t num = 0) const;
|
||||
value_type getByDate(Datetime date, size_t num = 0) const;
|
||||
|
||||
/** 获取指定日期相应的索引位置 */
|
||||
size_t getPos(Datetime) const;
|
||||
@ -245,15 +245,15 @@ inline DatetimeList Indicator::getDatetimeList() const {
|
||||
return m_imp ? m_imp->getDatetimeList() : DatetimeList();
|
||||
}
|
||||
|
||||
inline price_t Indicator::getByDate(Datetime date, size_t num) const {
|
||||
return m_imp ? m_imp->getByDate(date, num) : Null<price_t>();
|
||||
inline Indicator::value_type Indicator::getByDate(Datetime date, size_t num) const {
|
||||
return m_imp ? m_imp->getByDate(date, num) : Null<Indicator::value_type>();
|
||||
}
|
||||
|
||||
inline price_t Indicator::operator[](size_t pos) const {
|
||||
inline Indicator::value_type Indicator::operator[](size_t pos) const {
|
||||
return get(pos, 0);
|
||||
}
|
||||
|
||||
inline price_t Indicator::get(size_t pos, size_t num) const {
|
||||
inline Indicator::value_type Indicator::get(size_t pos, size_t num) const {
|
||||
return m_imp->get(pos, num);
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ inline size_t Indicator::getPos(Datetime date) const {
|
||||
return m_imp ? m_imp->getPos(date) : Null<size_t>();
|
||||
}
|
||||
|
||||
inline price_t Indicator::operator[](Datetime date) const {
|
||||
inline Indicator::value_type Indicator::operator[](Datetime date) const {
|
||||
return getByDate(date);
|
||||
}
|
||||
|
||||
@ -314,44 +314,44 @@ HKU_API Indicator operator<=(const Indicator&, const Indicator&);
|
||||
HKU_API Indicator operator&(const Indicator&, const Indicator&);
|
||||
HKU_API Indicator operator|(const Indicator&, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator+(const Indicator&, price_t);
|
||||
HKU_API Indicator operator+(price_t, const Indicator&);
|
||||
HKU_API Indicator operator+(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator+(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator-(const Indicator&, price_t);
|
||||
HKU_API Indicator operator-(price_t, const Indicator&);
|
||||
HKU_API Indicator operator-(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator-(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator*(const Indicator&, price_t);
|
||||
HKU_API Indicator operator*(price_t, const Indicator&);
|
||||
HKU_API Indicator operator*(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator*(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator/(const Indicator&, price_t);
|
||||
HKU_API Indicator operator/(price_t, const Indicator&);
|
||||
HKU_API Indicator operator/(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator/(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator%(const Indicator&, price_t);
|
||||
HKU_API Indicator operator%(price_t, const Indicator&);
|
||||
HKU_API Indicator operator%(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator%(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator==(const Indicator&, price_t);
|
||||
HKU_API Indicator operator==(price_t, const Indicator&);
|
||||
HKU_API Indicator operator==(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator==(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator!=(const Indicator&, price_t);
|
||||
HKU_API Indicator operator!=(price_t, const Indicator&);
|
||||
HKU_API Indicator operator!=(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator!=(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator>(const Indicator&, price_t);
|
||||
HKU_API Indicator operator>(price_t, const Indicator&);
|
||||
HKU_API Indicator operator>(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator>(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator<(const Indicator&, price_t);
|
||||
HKU_API Indicator operator<(price_t, const Indicator&);
|
||||
HKU_API Indicator operator<(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator<(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator>=(const Indicator&, price_t);
|
||||
HKU_API Indicator operator>=(price_t, const Indicator&);
|
||||
HKU_API Indicator operator>=(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator>=(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator<=(const Indicator&, price_t);
|
||||
HKU_API Indicator operator<=(price_t, const Indicator&);
|
||||
HKU_API Indicator operator<=(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator<=(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator&(const Indicator&, price_t);
|
||||
HKU_API Indicator operator&(price_t, const Indicator&);
|
||||
HKU_API Indicator operator&(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator&(Indicator::value_type, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator|(const Indicator&, price_t);
|
||||
HKU_API Indicator operator|(price_t, const Indicator&);
|
||||
HKU_API Indicator operator|(const Indicator&, Indicator::value_type);
|
||||
HKU_API Indicator operator|(Indicator::value_type, const Indicator&);
|
||||
|
||||
/**
|
||||
* 将ind1和ind2的结果组合在一起放在一个Indicator中。如ind = WEAVE(ind1, ind2)
|
||||
@ -375,9 +375,9 @@ Indicator HKU_API WEAVE(const Indicator& ind1, const Indicator& ind2);
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API IF(const Indicator& x, const Indicator& a, const Indicator& b);
|
||||
Indicator HKU_API IF(const Indicator& x, price_t a, const Indicator& b);
|
||||
Indicator HKU_API IF(const Indicator& x, const Indicator& a, price_t b);
|
||||
Indicator HKU_API IF(const Indicator& x, price_t a, price_t b);
|
||||
Indicator HKU_API IF(const Indicator& x, Indicator::value_type a, const Indicator& b);
|
||||
Indicator HKU_API IF(const Indicator& x, const Indicator& a, Indicator::value_type b);
|
||||
Indicator HKU_API IF(const Indicator& x, Indicator::value_type a, Indicator::value_type b);
|
||||
|
||||
/**
|
||||
* 计算样本相关系数与协方差。返回的结果集中,第一个为相关系数,第二个为协方差
|
||||
|
@ -139,9 +139,9 @@ HKU_API std::ostream &operator<<(std::ostream &os, const IndicatorImp &imp) {
|
||||
os << "}";
|
||||
}
|
||||
os << "\n formula: " << imp.formula() << "\n}";
|
||||
if (imp.m_pBuffer[0]) {
|
||||
os << "\n values: " << *imp.m_pBuffer[0];
|
||||
}
|
||||
// if (imp.m_pBuffer[0]) {
|
||||
// os << "\n values: " << *imp.m_pBuffer[0];
|
||||
// }
|
||||
return os;
|
||||
}
|
||||
|
||||
@ -157,19 +157,19 @@ HKU_API std::ostream &operator<<(std::ostream &os, const IndicatorImpPtr &imp) {
|
||||
IndicatorImp::IndicatorImp()
|
||||
: m_name("IndicatorImp"), m_discard(0), m_result_num(0), m_need_calculate(true), m_optype(LEAF) {
|
||||
initContext();
|
||||
memset(m_pBuffer, 0, sizeof(PriceList *) * MAX_RESULT_NUM);
|
||||
memset(m_pBuffer, 0, sizeof(vector<value_type> *) * MAX_RESULT_NUM);
|
||||
}
|
||||
|
||||
IndicatorImp::IndicatorImp(const string &name)
|
||||
: m_name(name), m_discard(0), m_result_num(0), m_need_calculate(true), m_optype(LEAF) {
|
||||
initContext();
|
||||
memset(m_pBuffer, 0, sizeof(PriceList *) * MAX_RESULT_NUM);
|
||||
memset(m_pBuffer, 0, sizeof(vector<value_type> *) * MAX_RESULT_NUM);
|
||||
}
|
||||
|
||||
IndicatorImp::IndicatorImp(const string &name, size_t result_num)
|
||||
: m_name(name), m_discard(0), m_need_calculate(true), m_optype(LEAF) {
|
||||
initContext();
|
||||
memset(m_pBuffer, 0, sizeof(PriceList *) * MAX_RESULT_NUM);
|
||||
memset(m_pBuffer, 0, sizeof(vector<value_type> *) * MAX_RESULT_NUM);
|
||||
m_result_num = result_num < MAX_RESULT_NUM ? result_num : MAX_RESULT_NUM;
|
||||
}
|
||||
|
||||
@ -261,10 +261,10 @@ void IndicatorImp::_readyBuffer(size_t len, size_t result_num) {
|
||||
"result_num oiverload MAX_RESULT_NUM! {}", name());
|
||||
HKU_IF_RETURN(result_num == 0, void());
|
||||
|
||||
price_t null_price = Null<price_t>();
|
||||
value_type null_price = Null<value_type>();
|
||||
for (size_t i = 0; i < result_num; ++i) {
|
||||
if (!m_pBuffer[i]) {
|
||||
m_pBuffer[i] = new PriceList(len, null_price);
|
||||
m_pBuffer[i] = new vector<value_type>(len, null_price);
|
||||
|
||||
} else {
|
||||
m_pBuffer[i]->clear();
|
||||
@ -301,7 +301,7 @@ IndicatorImpPtr IndicatorImp::clone() {
|
||||
|
||||
for (size_t i = 0; i < m_result_num; ++i) {
|
||||
if (m_pBuffer[i]) {
|
||||
p->m_pBuffer[i] = new PriceList(m_pBuffer[i]->begin(), m_pBuffer[i]->end());
|
||||
p->m_pBuffer[i] = new vector<value_type>(m_pBuffer[i]->begin(), m_pBuffer[i]->end());
|
||||
}
|
||||
}
|
||||
|
||||
@ -362,7 +362,7 @@ IndicatorImpPtr IndicatorImp::operator()(const Indicator &ind) {
|
||||
void IndicatorImp::setDiscard(size_t discard) {
|
||||
size_t tmp_discard = discard > size() ? size() : discard;
|
||||
if (tmp_discard > m_discard) {
|
||||
price_t null_price = Null<price_t>();
|
||||
value_type null_price = Null<value_type>();
|
||||
for (size_t i = 0; i < m_result_num; ++i) {
|
||||
auto *dst = this->data(i);
|
||||
for (size_t j = m_discard; j < tmp_discard; ++j) {
|
||||
@ -380,7 +380,15 @@ string IndicatorImp::long_name() const {
|
||||
|
||||
PriceList IndicatorImp::getResultAsPriceList(size_t result_num) {
|
||||
HKU_IF_RETURN(result_num >= m_result_num || m_pBuffer[result_num] == NULL, PriceList());
|
||||
#if HKU_USE_LOW_PRECISION
|
||||
size_t total = size();
|
||||
PriceList result(total);
|
||||
const auto &src = (*m_pBuffer[result_num]);
|
||||
std::copy(src.begin(), src.end(), result.begin());
|
||||
return result;
|
||||
#else
|
||||
return (*m_pBuffer[result_num]);
|
||||
#endif
|
||||
}
|
||||
|
||||
IndicatorImpPtr IndicatorImp::getResult(size_t result_num) {
|
||||
@ -392,13 +400,12 @@ IndicatorImpPtr IndicatorImp::getResult(size_t result_num) {
|
||||
auto const *src = this->data(result_num);
|
||||
auto *dst = imp->data(0);
|
||||
for (size_t i = discard(); i < total; ++i) {
|
||||
// imp->_set(get(i, result_num), i);
|
||||
dst[i] = src[i];
|
||||
}
|
||||
return imp;
|
||||
}
|
||||
|
||||
price_t IndicatorImp::get(size_t pos, size_t num) const {
|
||||
IndicatorImp::value_type IndicatorImp::get(size_t pos, size_t num) const {
|
||||
#if CHECK_ACCESS_BOUND
|
||||
HKU_CHECK_THROW(
|
||||
(num <= MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), std::out_of_range,
|
||||
@ -407,7 +414,7 @@ price_t IndicatorImp::get(size_t pos, size_t num) const {
|
||||
return (*m_pBuffer[num])[pos];
|
||||
}
|
||||
|
||||
void IndicatorImp::_set(price_t val, size_t pos, size_t num) {
|
||||
void IndicatorImp::_set(value_type val, size_t pos, size_t num) {
|
||||
#if CHECK_ACCESS_BOUND
|
||||
HKU_CHECK_THROW(
|
||||
(num <= MAX_RESULT_NUM && m_pBuffer[num] && pos < m_pBuffer[num]->size()), std::out_of_range,
|
||||
@ -430,9 +437,9 @@ Datetime IndicatorImp::getDatetime(size_t pos) const {
|
||||
return pos < k.size() ? k[pos].datetime : Null<Datetime>();
|
||||
}
|
||||
|
||||
price_t IndicatorImp::getByDate(Datetime date, size_t num) {
|
||||
IndicatorImp::value_type IndicatorImp::getByDate(Datetime date, size_t num) {
|
||||
size_t pos = getPos(date);
|
||||
return (pos != Null<size_t>()) ? get(pos, num) : Null<price_t>();
|
||||
return (pos != Null<size_t>()) ? get(pos, num) : Null<value_type>();
|
||||
}
|
||||
|
||||
size_t IndicatorImp::getPos(Datetime date) const {
|
||||
@ -1482,11 +1489,11 @@ void IndicatorImp::execute_corr() {
|
||||
size_t startPos = discard;
|
||||
size_t first_end = startPos + n >= total ? total : startPos + n;
|
||||
|
||||
price_t kx = maxp->get(discard);
|
||||
price_t ky = minp->get(discard);
|
||||
price_t ex = 0.0, ey = 0.0, exy = 0.0, varx = 0.0, vary = 0.0, cov = 0.0;
|
||||
price_t ex2 = 0.0, ey2 = 0.0;
|
||||
price_t ix, iy;
|
||||
value_type kx = maxp->get(discard);
|
||||
value_type ky = minp->get(discard);
|
||||
value_type ex = 0.0, ey = 0.0, exy = 0.0, varx = 0.0, vary = 0.0, cov = 0.0;
|
||||
value_type ex2 = 0.0, ey2 = 0.0;
|
||||
value_type ix, iy;
|
||||
|
||||
auto *dst0 = this->data(0);
|
||||
auto *dst1 = this->data(1);
|
||||
@ -1497,9 +1504,9 @@ void IndicatorImp::execute_corr() {
|
||||
iy = mindata[i] - ky;
|
||||
ex += ix;
|
||||
ey += iy;
|
||||
price_t powx2 = ix * ix;
|
||||
price_t powy2 = iy * iy;
|
||||
price_t powxy = ix * iy;
|
||||
value_type powx2 = ix * ix;
|
||||
value_type powy2 = iy * iy;
|
||||
value_type powxy = ix * iy;
|
||||
exy += powxy;
|
||||
ex2 += powx2;
|
||||
ey2 += powy2;
|
||||
@ -1516,8 +1523,8 @@ void IndicatorImp::execute_corr() {
|
||||
iy = mindata[i] - ky;
|
||||
ex += maxdata[i] - maxdata[i - n];
|
||||
ey += mindata[i] - mindata[i - n];
|
||||
price_t preix = maxdata[i - n] - kx;
|
||||
price_t preiy = mindata[i - n] - ky;
|
||||
value_type preix = maxdata[i - n] - kx;
|
||||
value_type preiy = mindata[i - n] - ky;
|
||||
ex2 += ix * ix - preix * preix;
|
||||
ey2 += iy * iy - preiy * preiy;
|
||||
exy += ix * iy - preix * preiy;
|
||||
|
@ -81,7 +81,11 @@ public:
|
||||
INVALID
|
||||
};
|
||||
|
||||
typedef price_t value_type;
|
||||
#if HKU_USE_LOW_PRECISION
|
||||
typedef float value_type;
|
||||
#else
|
||||
typedef double value_type;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/** 默认构造函数 */
|
||||
@ -102,9 +106,9 @@ public:
|
||||
|
||||
size_t size() const;
|
||||
|
||||
price_t get(size_t pos, size_t num = 0) const;
|
||||
value_type get(size_t pos, size_t num = 0) const;
|
||||
|
||||
price_t getByDate(Datetime, size_t num = 0);
|
||||
value_type getByDate(Datetime, size_t num = 0);
|
||||
|
||||
Datetime getDatetime(size_t pos) const;
|
||||
|
||||
@ -125,7 +129,7 @@ public:
|
||||
* 使用IndicatorImp(const Indicator&...)构造函数后,计算结果使用该函数,
|
||||
* 未做越界保护
|
||||
*/
|
||||
void _set(price_t val, size_t pos, size_t num = 0);
|
||||
void _set(value_type val, size_t pos, size_t num = 0);
|
||||
|
||||
/**
|
||||
* 准备内存
|
||||
@ -235,7 +239,7 @@ protected:
|
||||
string m_name;
|
||||
size_t m_discard;
|
||||
size_t m_result_num;
|
||||
PriceList* m_pBuffer[MAX_RESULT_NUM];
|
||||
vector<value_type>* m_pBuffer[MAX_RESULT_NUM];
|
||||
|
||||
bool m_need_calculate;
|
||||
OPType m_optype;
|
||||
@ -282,7 +286,7 @@ private:
|
||||
for (size_t i = 0; i < act_result_num; ++i) {
|
||||
size_t count = size();
|
||||
ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
|
||||
PriceList& values = *m_pBuffer[i];
|
||||
vector<value_type>& values = *m_pBuffer[i];
|
||||
for (size_t j = 0; j < count; j++) {
|
||||
if (std::isnan(values[j])) {
|
||||
ar& boost::serialization::make_nvp<string>("item", nan);
|
||||
@ -290,7 +294,7 @@ private:
|
||||
inf = values[j] > 0 ? "+inf" : "-inf";
|
||||
ar& boost::serialization::make_nvp<string>("item", inf);
|
||||
} else {
|
||||
ar& boost::serialization::make_nvp<price_t>("item", values[j]);
|
||||
ar& boost::serialization::make_nvp<value_type>("item", values[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -313,10 +317,10 @@ private:
|
||||
size_t act_result_num = 0;
|
||||
ar& BOOST_SERIALIZATION_NVP(act_result_num);
|
||||
for (size_t i = 0; i < act_result_num; ++i) {
|
||||
m_pBuffer[i] = new PriceList();
|
||||
m_pBuffer[i] = new vector<value_type>();
|
||||
size_t count = 0;
|
||||
ar& bs::make_nvp<size_t>(format("count_{}", i).c_str(), count);
|
||||
PriceList& values = *m_pBuffer[i];
|
||||
vector<value_type>& values = *m_pBuffer[i];
|
||||
values.resize(count);
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
std::string vstr;
|
||||
|
@ -18,14 +18,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ABS();
|
||||
Indicator ABS(price_t);
|
||||
Indicator ABS(Indicator::value_type);
|
||||
Indicator ABS(const Indicator& ind);
|
||||
|
||||
inline Indicator ABS(const Indicator& ind) {
|
||||
return ABS()(ind);
|
||||
}
|
||||
|
||||
inline Indicator ABS(price_t val) {
|
||||
inline Indicator ABS(Indicator::value_type val) {
|
||||
return ABS(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ACOS();
|
||||
Indicator ACOS(price_t);
|
||||
Indicator ACOS(Indicator::value_type);
|
||||
Indicator ACOS(const Indicator& ind);
|
||||
|
||||
inline Indicator ACOS(const Indicator& ind) {
|
||||
return ACOS()(ind);
|
||||
}
|
||||
|
||||
inline Indicator ACOS(price_t val) {
|
||||
inline Indicator ACOS(Indicator::value_type val) {
|
||||
return ACOS(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ASIN();
|
||||
Indicator ASIN(price_t);
|
||||
Indicator ASIN(Indicator::value_type);
|
||||
Indicator ASIN(const Indicator& ind);
|
||||
|
||||
inline Indicator ASIN(const Indicator& ind) {
|
||||
return ASIN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator ASIN(price_t val) {
|
||||
inline Indicator ASIN(Indicator::value_type val) {
|
||||
return ASIN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ATAN();
|
||||
Indicator ATAN(price_t);
|
||||
Indicator ATAN(Indicator::value_type);
|
||||
Indicator ATAN(const Indicator& ind);
|
||||
|
||||
inline Indicator ATAN(const Indicator& ind) {
|
||||
return ATAN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator ATAN(price_t val) {
|
||||
inline Indicator ATAN(Indicator::value_type val) {
|
||||
return ATAN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API BARSLAST();
|
||||
Indicator BARSLAST(price_t);
|
||||
Indicator BARSLAST(Indicator::value_type);
|
||||
Indicator BARSLAST(const Indicator& ind);
|
||||
|
||||
inline Indicator BARSLAST(const Indicator& ind) {
|
||||
return BARSLAST()(ind);
|
||||
}
|
||||
|
||||
inline Indicator BARSLAST(price_t val) {
|
||||
inline Indicator BARSLAST(Indicator::value_type val) {
|
||||
return BARSLAST(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API BARSSINCE();
|
||||
Indicator BARSSINCE(price_t);
|
||||
Indicator BARSSINCE(Indicator::value_type);
|
||||
Indicator BARSSINCE(const Indicator& ind);
|
||||
|
||||
inline Indicator BARSSINCE(const Indicator& ind) {
|
||||
return BARSSINCE()(ind);
|
||||
}
|
||||
|
||||
inline Indicator BARSSINCE(price_t val) {
|
||||
inline Indicator BARSSINCE(Indicator::value_type val) {
|
||||
return BARSSINCE(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -23,13 +23,13 @@ namespace hku {
|
||||
* </pre>
|
||||
*/
|
||||
Indicator BETWEEN(const Indicator&, const Indicator&, const Indicator&);
|
||||
Indicator BETWEEN(const Indicator&, const Indicator&, price_t);
|
||||
Indicator BETWEEN(const Indicator&, price_t, const Indicator&);
|
||||
Indicator BETWEEN(const Indicator&, price_t, price_t);
|
||||
Indicator BETWEEN(price_t, const Indicator&, const Indicator&);
|
||||
Indicator BETWEEN(price_t, const Indicator&, price_t);
|
||||
Indicator BETWEEN(price_t, price_t, const Indicator&);
|
||||
Indicator BETWEEN(price_t, price_t, price_t);
|
||||
Indicator BETWEEN(const Indicator&, const Indicator&, Indicator::value_type);
|
||||
Indicator BETWEEN(const Indicator&, Indicator::value_type, const Indicator&);
|
||||
Indicator BETWEEN(const Indicator&, Indicator::value_type, Indicator::value_type);
|
||||
Indicator BETWEEN(Indicator::value_type, const Indicator&, const Indicator&);
|
||||
Indicator BETWEEN(Indicator::value_type, const Indicator&, Indicator::value_type);
|
||||
Indicator BETWEEN(Indicator::value_type, Indicator::value_type, const Indicator&);
|
||||
Indicator BETWEEN(Indicator::value_type, Indicator::value_type, Indicator::value_type);
|
||||
|
||||
inline Indicator BETWEEN(const Indicator& a, const Indicator& b, const Indicator& c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
@ -37,43 +37,44 @@ inline Indicator BETWEEN(const Indicator& a, const Indicator& b, const Indicator
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(const Indicator& a, const Indicator& b, price_t c) {
|
||||
inline Indicator BETWEEN(const Indicator& a, const Indicator& b, Indicator::value_type c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(const Indicator& a, price_t b, const Indicator& c) {
|
||||
inline Indicator BETWEEN(const Indicator& a, Indicator::value_type b, const Indicator& c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(const Indicator& a, price_t b, price_t c) {
|
||||
inline Indicator BETWEEN(const Indicator& a, Indicator::value_type b, Indicator::value_type c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(price_t a, const Indicator& b, const Indicator& c) {
|
||||
inline Indicator BETWEEN(Indicator::value_type a, const Indicator& b, const Indicator& c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(price_t a, const Indicator& b, price_t c) {
|
||||
inline Indicator BETWEEN(Indicator::value_type a, const Indicator& b, Indicator::value_type c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(price_t a, price_t b, const Indicator& c) {
|
||||
inline Indicator BETWEEN(Indicator::value_type a, Indicator::value_type b, const Indicator& c) {
|
||||
Indicator result = IF(((b > c) & (a < b) & (a > c)) | ((b < c) & (a > b) & (a < c)), 1, 0);
|
||||
result.name("BETWEEN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator BETWEEN(price_t a, price_t b, price_t c) {
|
||||
inline Indicator BETWEEN(Indicator::value_type a, Indicator::value_type b,
|
||||
Indicator::value_type c) {
|
||||
Indicator result =
|
||||
CVAL((((b > c) && (a < b) && (a > c)) || ((b < c) && (a > b) && (a < c))) ? 1 : 0);
|
||||
result.name("BETWEEN");
|
||||
|
@ -22,14 +22,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API CEILING();
|
||||
Indicator CEILING(price_t);
|
||||
Indicator CEILING(Indicator::value_type);
|
||||
Indicator CEILING(const Indicator& ind);
|
||||
|
||||
inline Indicator CEILING(const Indicator& ind) {
|
||||
return CEILING()(ind);
|
||||
}
|
||||
|
||||
inline Indicator CEILING(price_t val) {
|
||||
inline Indicator CEILING(Indicator::value_type val) {
|
||||
return CEILING(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API COS();
|
||||
Indicator COS(price_t);
|
||||
Indicator COS(Indicator::value_type);
|
||||
Indicator COS(const Indicator& ind);
|
||||
|
||||
inline Indicator COS(const Indicator& ind) {
|
||||
return COS()(ind);
|
||||
}
|
||||
|
||||
inline Indicator COS(price_t val) {
|
||||
inline Indicator COS(Indicator::value_type val) {
|
||||
return COS(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,9 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator CROSS(const Indicator& x, const Indicator& y);
|
||||
Indicator CROSS(const Indicator& x, price_t);
|
||||
Indicator CROSS(price_t, const Indicator& y);
|
||||
Indicator CROSS(price_t, price_t);
|
||||
Indicator CROSS(const Indicator& x, Indicator::value_type);
|
||||
Indicator CROSS(Indicator::value_type, const Indicator& y);
|
||||
Indicator CROSS(Indicator::value_type, Indicator::value_type);
|
||||
|
||||
inline Indicator CROSS(const Indicator& x, const Indicator& y) {
|
||||
Indicator result = (REF(x, 1) < REF(y, 1)) & (x > y);
|
||||
@ -31,15 +31,15 @@ inline Indicator CROSS(const Indicator& x, const Indicator& y) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator CROSS(const Indicator& x, price_t y) {
|
||||
inline Indicator CROSS(const Indicator& x, Indicator::value_type y) {
|
||||
return CROSS(x, CVAL(x, y));
|
||||
}
|
||||
|
||||
inline Indicator CROSS(price_t x, const Indicator& y) {
|
||||
inline Indicator CROSS(Indicator::value_type x, const Indicator& y) {
|
||||
return CROSS(CVAL(y, x), y);
|
||||
}
|
||||
|
||||
inline Indicator CROSS(price_t x, price_t y) {
|
||||
inline Indicator CROSS(Indicator::value_type x, Indicator::value_type y) {
|
||||
return CROSS(CVAL(x), CVAL(y));
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API EXP();
|
||||
Indicator EXP(price_t);
|
||||
Indicator EXP(Indicator::value_type);
|
||||
Indicator EXP(const Indicator& ind);
|
||||
|
||||
inline Indicator EXP(const Indicator& ind) {
|
||||
return EXP()(ind);
|
||||
}
|
||||
|
||||
inline Indicator EXP(price_t val) {
|
||||
inline Indicator EXP(Indicator::value_type val) {
|
||||
return EXP(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API FLOOR();
|
||||
Indicator FLOOR(price_t);
|
||||
Indicator FLOOR(Indicator::value_type);
|
||||
Indicator FLOOR(const Indicator& ind);
|
||||
|
||||
inline Indicator FLOOR(const Indicator& ind) {
|
||||
return FLOOR()(ind);
|
||||
}
|
||||
|
||||
inline Indicator FLOOR(price_t val) {
|
||||
inline Indicator FLOOR(Indicator::value_type val) {
|
||||
return FLOOR(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API INTPART();
|
||||
Indicator INTPART(price_t);
|
||||
Indicator INTPART(Indicator::value_type);
|
||||
Indicator INTPART(const Indicator& ind);
|
||||
|
||||
inline Indicator INTPART(const Indicator& ind) {
|
||||
return INTPART()(ind);
|
||||
}
|
||||
|
||||
inline Indicator INTPART(price_t val) {
|
||||
inline Indicator INTPART(Indicator::value_type val) {
|
||||
return INTPART(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API LN();
|
||||
Indicator LN(price_t);
|
||||
Indicator LN(Indicator::value_type);
|
||||
Indicator LN(const Indicator& ind);
|
||||
|
||||
inline Indicator LN(const Indicator& ind) {
|
||||
return LN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator LN(price_t val) {
|
||||
inline Indicator LN(Indicator::value_type val) {
|
||||
return LN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API LOG();
|
||||
Indicator LOG(price_t);
|
||||
Indicator LOG(Indicator::value_type);
|
||||
Indicator LOG(const Indicator& ind);
|
||||
|
||||
inline Indicator LOG(const Indicator& ind) {
|
||||
return LOG()(ind);
|
||||
}
|
||||
|
||||
inline Indicator LOG(price_t val) {
|
||||
inline Indicator LOG(Indicator::value_type val) {
|
||||
return LOG(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -39,27 +39,27 @@ inline Indicator LONGCROSS(const Indicator& x, const Indicator& y, const Indicat
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(const Indicator& x, price_t y, int n = 3) {
|
||||
inline Indicator LONGCROSS(const Indicator& x, Indicator::value_type y, int n = 3) {
|
||||
return LONGCROSS(x, CVAL(x, y), n);
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(const Indicator& x, price_t y, const Indicator& n) {
|
||||
inline Indicator LONGCROSS(const Indicator& x, Indicator::value_type y, const Indicator& n) {
|
||||
return LONGCROSS(x, CVAL(x, y), n);
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(price_t x, const Indicator& y, int n = 3) {
|
||||
inline Indicator LONGCROSS(Indicator::value_type x, const Indicator& y, int n = 3) {
|
||||
return LONGCROSS(CVAL(y, x), y, n);
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(price_t x, const Indicator& y, const Indicator& n) {
|
||||
inline Indicator LONGCROSS(Indicator::value_type x, const Indicator& y, const Indicator& n) {
|
||||
return LONGCROSS(CVAL(y, x), y, n);
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(price_t x, price_t y, int n = 3) {
|
||||
inline Indicator LONGCROSS(Indicator::value_type x, Indicator::value_type y, int n = 3) {
|
||||
return LONGCROSS(CVAL(x), CVAL(y), n);
|
||||
}
|
||||
|
||||
inline Indicator LONGCROSS(price_t x, price_t y, const Indicator& n) {
|
||||
inline Indicator LONGCROSS(Indicator::value_type x, Indicator::value_type y, const Indicator& n) {
|
||||
return LONGCROSS(CVAL(x), CVAL(y), n);
|
||||
}
|
||||
|
||||
|
@ -28,13 +28,13 @@ inline Indicator MAX(const Indicator& ind1, const Indicator& ind2) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator MAX(const Indicator& ind, price_t val) {
|
||||
inline Indicator MAX(const Indicator& ind, Indicator::value_type val) {
|
||||
Indicator result = IF(ind > val, ind, val);
|
||||
result.name("MAX");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator MAX(price_t val, const Indicator& ind) {
|
||||
inline Indicator MAX(Indicator::value_type val, const Indicator& ind) {
|
||||
Indicator result = IF(val > ind, val, ind);
|
||||
result.name("MAX");
|
||||
return result;
|
||||
|
@ -28,13 +28,13 @@ inline Indicator MIN(const Indicator& ind1, const Indicator& ind2) {
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator MIN(const Indicator& ind, price_t val) {
|
||||
inline Indicator MIN(const Indicator& ind, Indicator::value_type val) {
|
||||
Indicator result = IF(ind < val, ind, val);
|
||||
result.name("MIN");
|
||||
return result;
|
||||
}
|
||||
|
||||
inline Indicator MIN(price_t val, const Indicator& ind) {
|
||||
inline Indicator MIN(Indicator::value_type val, const Indicator& ind) {
|
||||
Indicator result = IF(val < ind, val, ind);
|
||||
result.name("MIN");
|
||||
return result;
|
||||
|
@ -24,23 +24,23 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator MOD(const Indicator& ind1, const Indicator& ind2);
|
||||
Indicator MOD(const Indicator& ind1, price_t ind2);
|
||||
Indicator MOD(price_t ind1, const Indicator& ind2);
|
||||
Indicator MOD(price_t ind1, price_t ind2);
|
||||
Indicator MOD(const Indicator& ind1, Indicator::value_type ind2);
|
||||
Indicator MOD(Indicator::value_type ind1, const Indicator& ind2);
|
||||
Indicator MOD(Indicator::value_type ind1, Indicator::value_type ind2);
|
||||
|
||||
inline Indicator MOD(const Indicator& ind1, const Indicator& ind2) {
|
||||
return (ind1 % ind2);
|
||||
}
|
||||
|
||||
inline Indicator MOD(const Indicator& ind1, price_t ind2) {
|
||||
inline Indicator MOD(const Indicator& ind1, Indicator::value_type ind2) {
|
||||
return ind1 % CVAL(ind1, ind2);
|
||||
}
|
||||
|
||||
inline Indicator MOD(price_t ind1, const Indicator& ind2) {
|
||||
inline Indicator MOD(Indicator::value_type ind1, const Indicator& ind2) {
|
||||
return CVAL(ind2, ind1) % ind2;
|
||||
}
|
||||
|
||||
inline Indicator MOD(price_t ind1, price_t ind2) {
|
||||
inline Indicator MOD(Indicator::value_type ind1, Indicator::value_type ind2) {
|
||||
return CVAL(ind1) % CVAL(ind2);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ inline Indicator POW(const Indicator& ind, const Indicator& n) {
|
||||
return POW(IndParam(n))(ind);
|
||||
}
|
||||
|
||||
inline Indicator POW(price_t val, int n) {
|
||||
inline Indicator POW(Indicator::value_type val, int n) {
|
||||
return POW(CVAL(val), n);
|
||||
}
|
||||
|
||||
|
@ -39,12 +39,19 @@ Indicator HKU_API PRICELIST(const Indicator& ind, int result_index = 0);
|
||||
Indicator HKU_API PRICELIST(int result_index = 0);
|
||||
|
||||
/**
|
||||
* 包装 price_t 数组成Indicator,用于计算其他指标
|
||||
* 包装数组成Indicator,用于计算其他指标
|
||||
* @param data price_t[]
|
||||
* @param total 数组大小
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API PRICELIST(price_t* data, size_t total);
|
||||
// Indicator HKU_API PRICELIST(double* data, size_t total);
|
||||
template <typename ValueT>
|
||||
Indicator PRICELIST(ValueT* data, size_t total) {
|
||||
HKU_IF_RETURN(!data || total == 0, PRICELIST(PriceList()));
|
||||
PriceList tmp(total);
|
||||
std::copy(data, data + total, tmp.begin());
|
||||
return PRICELIST(tmp);
|
||||
}
|
||||
|
||||
} // namespace hku
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API REVERSE();
|
||||
Indicator REVERSE(price_t);
|
||||
Indicator REVERSE(Indicator::value_type);
|
||||
Indicator REVERSE(const Indicator& ind);
|
||||
|
||||
inline Indicator REVERSE(const Indicator& ind) {
|
||||
return REVERSE()(ind);
|
||||
}
|
||||
|
||||
inline Indicator REVERSE(price_t val) {
|
||||
inline Indicator REVERSE(Indicator::value_type val) {
|
||||
return REVERSE(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROUND(int ndigits = 2);
|
||||
Indicator ROUND(price_t, int ndigits = 2);
|
||||
Indicator ROUND(Indicator::value_type, int ndigits = 2);
|
||||
Indicator ROUND(const Indicator& ind, int ndigits = 2);
|
||||
|
||||
inline Indicator ROUND(const Indicator& ind, int n) {
|
||||
return ROUND(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROUND(price_t val, int n) {
|
||||
inline Indicator ROUND(Indicator::value_type val, int n) {
|
||||
return ROUND(CVAL(val), n);
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROUNDDOWN(int ndigits = 2);
|
||||
Indicator ROUNDDOWN(price_t, int ndigits = 2);
|
||||
Indicator ROUNDDOWN(Indicator::value_type, int ndigits = 2);
|
||||
Indicator ROUNDDOWN(const Indicator& ind, int ndigits = 2);
|
||||
|
||||
inline Indicator ROUNDDOWN(const Indicator& ind, int n) {
|
||||
return ROUNDDOWN(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROUNDDOWN(price_t val, int n) {
|
||||
inline Indicator ROUNDDOWN(Indicator::value_type val, int n) {
|
||||
return ROUNDDOWN(CVAL(val), n);
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API ROUNDUP(int ndigits = 2);
|
||||
Indicator ROUNDUP(price_t, int ndigits = 2);
|
||||
Indicator ROUNDUP(Indicator::value_type, int ndigits = 2);
|
||||
Indicator ROUNDUP(const Indicator& ind, int ndigits = 2);
|
||||
|
||||
inline Indicator ROUNDUP(const Indicator& ind, int n) {
|
||||
return ROUNDUP(n)(ind);
|
||||
}
|
||||
|
||||
inline Indicator ROUNDUP(price_t val, int n) {
|
||||
inline Indicator ROUNDUP(Indicator::value_type val, int n) {
|
||||
return ROUNDUP(CVAL(val), n);
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API SGN();
|
||||
Indicator SGN(price_t);
|
||||
Indicator SGN(Indicator::value_type);
|
||||
Indicator SGN(const Indicator& ind);
|
||||
|
||||
inline Indicator SGN(const Indicator& ind) {
|
||||
return SGN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator SGN(price_t val) {
|
||||
inline Indicator SGN(Indicator::value_type val) {
|
||||
return SGN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API SIN();
|
||||
Indicator SIN(price_t);
|
||||
Indicator SIN(Indicator::value_type);
|
||||
Indicator SIN(const Indicator& ind);
|
||||
|
||||
inline Indicator SIN(const Indicator& ind) {
|
||||
return SIN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator SIN(price_t val) {
|
||||
inline Indicator SIN(Indicator::value_type val) {
|
||||
return SIN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -25,14 +25,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API SQRT();
|
||||
Indicator SQRT(price_t);
|
||||
Indicator SQRT(Indicator::value_type);
|
||||
Indicator SQRT(const Indicator& ind);
|
||||
|
||||
inline Indicator SQRT(const Indicator& ind) {
|
||||
return SQRT()(ind);
|
||||
}
|
||||
|
||||
inline Indicator SQRT(price_t val) {
|
||||
inline Indicator SQRT(Indicator::value_type val) {
|
||||
return SQRT(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@ namespace hku {
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API TAN();
|
||||
Indicator TAN(price_t);
|
||||
Indicator TAN(Indicator::value_type);
|
||||
Indicator TAN(const Indicator& ind);
|
||||
|
||||
inline Indicator TAN(const Indicator& ind) {
|
||||
return TAN()(ind);
|
||||
}
|
||||
|
||||
inline Indicator TAN(price_t val) {
|
||||
inline Indicator TAN(Indicator::value_type val) {
|
||||
return TAN(CVAL(val));
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,4 @@ Indicator HKU_API PRICELIST(int result_index) {
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API PRICELIST(price_t* data, size_t total) {
|
||||
return data ? PRICELIST(PriceList(data, data + total), 0)
|
||||
: Indicator(make_shared<IPriceList>());
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -124,6 +124,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 提供double的Null值
|
||||
*/
|
||||
template <>
|
||||
class Null<float> {
|
||||
public:
|
||||
Null() {}
|
||||
operator float() const {
|
||||
return (std::numeric_limits<float>::quiet_NaN)();
|
||||
}
|
||||
};
|
||||
|
||||
/** @} */
|
||||
} // namespace hku
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Created on: 2009-11-20
|
||||
* Author: fasiondog
|
||||
*/
|
||||
#include <cmath>
|
||||
|
||||
#include "arithmetic.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
@ -17,32 +17,32 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
double HKU_API roundEx(double number, int ndigits) {
|
||||
// 切换至:ROUND_HALF_EVEN 银行家舍入法
|
||||
double pow1, pow2, y, z;
|
||||
double x = number;
|
||||
if (ndigits >= 0) {
|
||||
pow1 = pow(10.0, (double)ndigits);
|
||||
pow2 = 1.0;
|
||||
y = (x * pow1) * pow2;
|
||||
} else {
|
||||
pow1 = pow(10.0, (double)-ndigits);
|
||||
pow2 = 1.0;
|
||||
y = x / pow1;
|
||||
}
|
||||
// double HKU_API roundEx(double number, int ndigits) {
|
||||
// // 切换至:ROUND_HALF_EVEN 银行家舍入法
|
||||
// double pow1, pow2, y, z;
|
||||
// double x = number;
|
||||
// if (ndigits >= 0) {
|
||||
// pow1 = pow(10.0, (double)ndigits);
|
||||
// pow2 = 1.0;
|
||||
// y = (x * pow1) * pow2;
|
||||
// } else {
|
||||
// pow1 = pow(10.0, (double)-ndigits);
|
||||
// pow2 = 1.0;
|
||||
// y = x / pow1;
|
||||
// }
|
||||
|
||||
z = round(y);
|
||||
if (fabs(y - z) == 0.5)
|
||||
/* halfway between two integers; use round-half-even */
|
||||
z = 2.0 * round(y / 2.0);
|
||||
// z = round(y);
|
||||
// if (fabs(y - z) == 0.5)
|
||||
// /* halfway between two integers; use round-half-even */
|
||||
// z = 2.0 * round(y / 2.0);
|
||||
|
||||
if (ndigits >= 0)
|
||||
z = (z / pow2) / pow1;
|
||||
else
|
||||
z *= pow1;
|
||||
// if (ndigits >= 0)
|
||||
// z = (z / pow2) / pow1;
|
||||
// else
|
||||
// z *= pow1;
|
||||
|
||||
return z;
|
||||
}
|
||||
// return z;
|
||||
// }
|
||||
|
||||
double HKU_API roundUp(double number, int ndigits) {
|
||||
double f;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#ifndef HIKYUU_UTILITIES_ARITHMETIC_H
|
||||
#define HIKYUU_UTILITIES_ARITHMETIC_H
|
||||
|
||||
#include <cmath>
|
||||
#include <cctype>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
@ -75,7 +76,34 @@ std::string HKU_API gb_to_utf8(const std::string& szinput);
|
||||
* @param ndigits 保留小数位数
|
||||
* @return 处理过的数据
|
||||
*/
|
||||
double HKU_API roundEx(double number, int ndigits = 0);
|
||||
// double HKU_API roundEx(double number, int ndigits = 0);
|
||||
template <typename ValueT>
|
||||
ValueT roundEx(ValueT number, int ndigits = 0) {
|
||||
// 切换至:ROUND_HALF_EVEN 银行家舍入法
|
||||
ValueT pow1, pow2, y, z;
|
||||
ValueT x = number;
|
||||
if (ndigits >= 0) {
|
||||
pow1 = std::pow<ValueT>(10.0, (ValueT)ndigits);
|
||||
pow2 = 1.0;
|
||||
y = (x * pow1) * pow2;
|
||||
} else {
|
||||
pow1 = std::pow<ValueT>(10.0, (ValueT)-ndigits);
|
||||
pow2 = 1.0;
|
||||
y = x / pow1;
|
||||
}
|
||||
|
||||
z = std::round(y);
|
||||
if (std::fabs(y - z) == 0.5)
|
||||
/* halfway between two integers; use round-half-even */
|
||||
z = 2.0 * std::round(y / 2.0);
|
||||
|
||||
if (ndigits >= 0)
|
||||
z = (z / pow2) / pow1;
|
||||
else
|
||||
z *= pow1;
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* 向上截取,如10.1截取后为11
|
||||
|
@ -43,7 +43,7 @@ TEST_CASE("test_ACOS") {
|
||||
result = ACOS(-0.1);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::acos(-0.1));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::acos(-0.1)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -58,17 +58,17 @@ TEST_CASE("test_AMA") {
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result.getResultNumber(), 2);
|
||||
CHECK_EQ(result[0], 6063);
|
||||
CHECK_LT(std::fabs(result[9] - 6103.6781), 0.000001);
|
||||
CHECK_LT(std::fabs(result[10] - 6120.760197), 0.000001);
|
||||
CHECK_LT(std::fabs(result[18] - 6216.376893), 0.000001);
|
||||
CHECK_LT(std::fabs(result[19] - 6239.100742), 0.000001);
|
||||
CHECK_EQ(result[9], doctest::Approx(6103.6781));
|
||||
CHECK_EQ(result[10], doctest::Approx(6120.760197));
|
||||
CHECK_EQ(result[18], doctest::Approx(6216.376893));
|
||||
CHECK_EQ(result[19], doctest::Approx(6239.100742));
|
||||
|
||||
CHECK_EQ(result.get(0, 1), 1.0);
|
||||
CHECK_LT(std::fabs(result.get(9, 1) - 0.557895), 0.000001);
|
||||
CHECK_LT(std::fabs(result.get(10, 1) - 0.611111), 0.000001);
|
||||
CHECK_LT(std::fabs(result.get(11, 1) - 0.826484), 0.000001);
|
||||
CHECK_LT(std::fabs(result.get(18, 1) - 0.517799), 0.000001);
|
||||
CHECK_LT(std::fabs(result.get(19, 1) - 0.585526), 0.000001);
|
||||
CHECK_EQ(result.get(9, 1), doctest::Approx(0.557895));
|
||||
CHECK_EQ(result.get(10, 1), doctest::Approx(0.611111));
|
||||
CHECK_EQ(result.get(11, 1), doctest::Approx(0.826484));
|
||||
CHECK_EQ(result.get(18, 1), doctest::Approx(0.517799));
|
||||
CHECK_EQ(result.get(19, 1), doctest::Approx(0.585526));
|
||||
|
||||
/** @arg operator() */
|
||||
Indicator ama = AMA(10, 2, 30);
|
||||
|
@ -43,7 +43,7 @@ TEST_CASE("test_ASIN") {
|
||||
result = ASIN(-0.1);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::asin(-0.1));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::asin(-0.1)));
|
||||
|
||||
result = ASIN(1.01);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
|
@ -43,7 +43,7 @@ TEST_CASE("test_ATAN") {
|
||||
result = ATAN(-11);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::atan(-11));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::atan(-11)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -43,7 +43,7 @@ TEST_CASE("test_COS") {
|
||||
result = COS(-11);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::cos(-11));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::cos(-11)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -41,7 +41,7 @@ TEST_CASE("test_EXP") {
|
||||
result = EXP(1);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::exp(1));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::exp(1)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -77,7 +77,7 @@ TEST_CASE("test_HHV") {
|
||||
16302.7, 16302.7, 16302.7, 16302.7, 16302.7, 16302.7, 16302.7,
|
||||
16302.7, 16302.7, 8211.5, 8107.4, 8107.4, 8107.4, 9430.0};
|
||||
for (size_t i = 0; i < 20; i++) {
|
||||
CHECK_EQ(result[i], expect[i]);
|
||||
CHECK_EQ(result[i], doctest::Approx(expect[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,48 +66,48 @@ TEST_CASE("test_IKData") {
|
||||
ki = KDATA(kdata);
|
||||
CHECK_EQ(ki.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(ki.get(i, 0), kdata[i].openPrice);
|
||||
CHECK_EQ(ki.get(i, 1), kdata[i].highPrice);
|
||||
CHECK_EQ(ki.get(i, 2), kdata[i].lowPrice);
|
||||
CHECK_EQ(ki.get(i, 3), kdata[i].closePrice);
|
||||
CHECK_EQ(ki.get(i, 4), kdata[i].transAmount);
|
||||
CHECK_EQ(ki.get(i, 5), kdata[i].transCount);
|
||||
CHECK_EQ(ki.get(i, 0), doctest::Approx(kdata[i].openPrice));
|
||||
CHECK_EQ(ki.get(i, 1), doctest::Approx(kdata[i].highPrice));
|
||||
CHECK_EQ(ki.get(i, 2), doctest::Approx(kdata[i].lowPrice));
|
||||
CHECK_EQ(ki.get(i, 3), doctest::Approx(kdata[i].closePrice));
|
||||
CHECK_EQ(ki.get(i, 4), doctest::Approx(kdata[i].transAmount));
|
||||
CHECK_EQ(ki.get(i, 5), doctest::Approx(kdata[i].transCount));
|
||||
}
|
||||
|
||||
open = OPEN(kdata);
|
||||
CHECK_EQ(open.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(open[i], kdata[i].openPrice);
|
||||
CHECK_EQ(open[i], doctest::Approx(kdata[i].openPrice));
|
||||
}
|
||||
|
||||
high = HIGH(kdata);
|
||||
CHECK_EQ(high.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(high[i], kdata[i].highPrice);
|
||||
CHECK_EQ(high[i], doctest::Approx(kdata[i].highPrice));
|
||||
}
|
||||
|
||||
low = LOW(kdata);
|
||||
CHECK_EQ(low.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(low[i], kdata[i].lowPrice);
|
||||
CHECK_EQ(low[i], doctest::Approx(kdata[i].lowPrice));
|
||||
}
|
||||
|
||||
close = CLOSE(kdata);
|
||||
CHECK_EQ(close.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(close[i], kdata[i].closePrice);
|
||||
CHECK_EQ(close[i], doctest::Approx(kdata[i].closePrice));
|
||||
}
|
||||
|
||||
amount = AMO(kdata);
|
||||
CHECK_EQ(amount.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(amount[i], kdata[i].transAmount);
|
||||
CHECK_EQ(amount[i], doctest::Approx(kdata[i].transAmount));
|
||||
}
|
||||
|
||||
count = VOL(kdata);
|
||||
CHECK_EQ(count.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(count[i], kdata[i].transCount);
|
||||
CHECK_EQ(count[i], doctest::Approx(kdata[i].transCount));
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,54 +126,54 @@ TEST_CASE("test_IKData_setContext") {
|
||||
ki.setContext(stock, query);
|
||||
CHECK_EQ(ki.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(ki.get(i, 0), kdata[i].openPrice);
|
||||
CHECK_EQ(ki.get(i, 1), kdata[i].highPrice);
|
||||
CHECK_EQ(ki.get(i, 2), kdata[i].lowPrice);
|
||||
CHECK_EQ(ki.get(i, 3), kdata[i].closePrice);
|
||||
CHECK_EQ(ki.get(i, 4), kdata[i].transAmount);
|
||||
CHECK_EQ(ki.get(i, 5), kdata[i].transCount);
|
||||
CHECK_EQ(ki.get(i, 0), doctest::Approx(kdata[i].openPrice));
|
||||
CHECK_EQ(ki.get(i, 1), doctest::Approx(kdata[i].highPrice));
|
||||
CHECK_EQ(ki.get(i, 2), doctest::Approx(kdata[i].lowPrice));
|
||||
CHECK_EQ(ki.get(i, 3), doctest::Approx(kdata[i].closePrice));
|
||||
CHECK_EQ(ki.get(i, 4), doctest::Approx(kdata[i].transAmount));
|
||||
CHECK_EQ(ki.get(i, 5), doctest::Approx(kdata[i].transCount));
|
||||
}
|
||||
|
||||
open = OPEN();
|
||||
open.setContext(stock, query);
|
||||
CHECK_EQ(open.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(open[i], kdata[i].openPrice);
|
||||
CHECK_EQ(open[i], doctest::Approx(kdata[i].openPrice));
|
||||
}
|
||||
|
||||
high = HIGH();
|
||||
high.setContext(stock, query);
|
||||
CHECK_EQ(high.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(high[i], kdata[i].highPrice);
|
||||
CHECK_EQ(high[i], doctest::Approx(kdata[i].highPrice));
|
||||
}
|
||||
|
||||
low = LOW();
|
||||
low.setContext(stock, query);
|
||||
CHECK_EQ(low.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(low[i], kdata[i].lowPrice);
|
||||
CHECK_EQ(low[i], doctest::Approx(kdata[i].lowPrice));
|
||||
}
|
||||
|
||||
close = CLOSE();
|
||||
close.setContext(stock, query);
|
||||
CHECK_EQ(close.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(close[i], kdata[i].closePrice);
|
||||
CHECK_EQ(close[i], doctest::Approx(kdata[i].closePrice));
|
||||
}
|
||||
|
||||
amount = AMO();
|
||||
amount.setContext(stock, query);
|
||||
CHECK_EQ(amount.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(amount[i], kdata[i].transAmount);
|
||||
CHECK_EQ(amount[i], doctest::Approx(kdata[i].transAmount));
|
||||
}
|
||||
|
||||
count = VOL();
|
||||
count.setContext(stock, query);
|
||||
CHECK_EQ(count.size(), kdata.size());
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
CHECK_EQ(count[i], kdata[i].transCount);
|
||||
CHECK_EQ(count[i], doctest::Approx(kdata[i].transCount));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,9 +270,9 @@ TEST_CASE("test_operator_division") {
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
if (data1[i] == 0.0) {
|
||||
CHECK_UNARY(std::isinf(result[i]));
|
||||
CHECK_UNARY((std::isinf(result[i]) || std::isnan(result[i])));
|
||||
} else {
|
||||
CHECK_EQ(result[i], data2[i] / data1[i]);
|
||||
CHECK_EQ(result[i], doctest::Approx(data2[i] / data1[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,9 +293,9 @@ TEST_CASE("test_operator_division") {
|
||||
CHECK_EQ(result.size(), k.size());
|
||||
for (size_t i = 0; i < result.size(); ++i) {
|
||||
if (data1[i] == 0.0) {
|
||||
CHECK_UNARY(std::isinf(result[i]));
|
||||
CHECK_UNARY(std::isinf(result[i]) || std::isnan(result[i]));
|
||||
} else {
|
||||
CHECK_EQ(result[i], (k[i] / data1[i]));
|
||||
CHECK_EQ(result[i], doctest::Approx(k[i] / data1[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -749,11 +749,11 @@ TEST_CASE("test_getResult_getResultAsPriceList") {
|
||||
CHECK_EQ(result2.size(), 10);
|
||||
CHECK_EQ(result1[0], 29.5);
|
||||
CHECK_LT(std::fabs(result1[1] - 27.58), 0.0001);
|
||||
CHECK_EQ(result1[9], 26.45);
|
||||
CHECK_EQ(result1[9], doctest::Approx(26.45));
|
||||
|
||||
CHECK_EQ(result2[0], 29.8);
|
||||
CHECK_EQ(result2[1], 28.38);
|
||||
CHECK_EQ(result2[9], 26.55);
|
||||
CHECK_EQ(result2[0], doctest::Approx(29.8));
|
||||
CHECK_EQ(result2[1], doctest::Approx(28.38));
|
||||
CHECK_EQ(result2[9], doctest::Approx(26.55));
|
||||
}
|
||||
|
||||
/** @par 检测点 */
|
||||
|
@ -56,16 +56,16 @@ TEST_CASE("test_MA") {
|
||||
CHECK_EQ(ma.empty(), false);
|
||||
CHECK_EQ(ma.size(), kdata.size());
|
||||
CHECK_EQ(ma.discard(), 0);
|
||||
CHECK_LT(std::fabs(ma[0] - 2415.197), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[1] - 2397.1715), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[2] - 2395.890), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[3] - 2392.89075), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[4] - 2394.1114), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[5] - 2396.14767), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[6] - 2395.62443), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[7] - 2393.03375), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[8] - 2389.709), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[9] - 2383.4041), 0.00001);
|
||||
CHECK_EQ(ma[0], doctest::Approx(2415.197));
|
||||
CHECK_EQ(ma[1], doctest::Approx(2397.1715));
|
||||
CHECK_EQ(ma[2], doctest::Approx(2395.890));
|
||||
CHECK_EQ(ma[3], doctest::Approx(2392.89075));
|
||||
CHECK_EQ(ma[4], doctest::Approx(2394.1114));
|
||||
CHECK_EQ(ma[5], doctest::Approx(2396.14767));
|
||||
CHECK_EQ(ma[6], doctest::Approx(2395.62443));
|
||||
CHECK_EQ(ma[7], doctest::Approx(2393.03375));
|
||||
CHECK_EQ(ma[8], doctest::Approx(2389.709));
|
||||
CHECK_EQ(ma[9], doctest::Approx(2383.4041));
|
||||
|
||||
/** @arg n = 10 且数据大小刚好为9 时, 正常关联数据 */
|
||||
kdata = stock.getKData(KQuery(-9));
|
||||
@ -74,12 +74,12 @@ TEST_CASE("test_MA") {
|
||||
CHECK_EQ(ma.empty(), false);
|
||||
CHECK_EQ(ma.size(), kdata.size());
|
||||
CHECK_EQ(ma.discard(), 0);
|
||||
CHECK_LT(std::fabs(ma[0] - 2379.146), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[1] - 2386.2365), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[2] - 2385.45533), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[3] - 2388.84), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[7] - 2386.523), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[8] - 2379.87156), 0.00001);
|
||||
CHECK_EQ(ma[0], doctest::Approx(2379.146));
|
||||
CHECK_EQ(ma[1], doctest::Approx(2386.2365));
|
||||
CHECK_EQ(ma[2], doctest::Approx(2385.45533));
|
||||
CHECK_EQ(ma[3], doctest::Approx(2388.84));
|
||||
CHECK_EQ(ma[7], doctest::Approx(2386.523));
|
||||
CHECK_EQ(ma[8], doctest::Approx(2379.87156));
|
||||
|
||||
/** @arg n = 10 且数据大小为11 时, 正常关联数据 */
|
||||
kdata = stock.getKData(KQuery(-11));
|
||||
@ -88,10 +88,10 @@ TEST_CASE("test_MA") {
|
||||
CHECK_EQ(ma.empty(), false);
|
||||
CHECK_EQ(ma.size(), kdata.size());
|
||||
CHECK_EQ(ma.discard(), 0);
|
||||
CHECK_LT(std::fabs(ma[0] - 2400.984), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[8] - 2393.91711), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[9] - 2390.8365), 0.00001);
|
||||
CHECK_LT(std::fabs(ma[10] - 2383.4041), 0.00001);
|
||||
CHECK_EQ(ma[0], doctest::Approx(2400.984));
|
||||
CHECK_EQ(ma[8], doctest::Approx(2393.91711));
|
||||
CHECK_EQ(ma[9], doctest::Approx(2390.8365));
|
||||
CHECK_EQ(ma[10], doctest::Approx(2383.4041));
|
||||
|
||||
/** @arg n = 1 */
|
||||
kdata = stock.getKData(KQuery(-11));
|
||||
|
@ -76,17 +76,17 @@ TEST_CASE("test_MACD") {
|
||||
CHECK_EQ(diff.size(), 20);
|
||||
CHECK_EQ(dea.size(), 20);
|
||||
|
||||
CHECK_EQ(diff[0], fast[0]);
|
||||
CHECK_EQ(diff[1], fast[1]);
|
||||
CHECK_EQ(diff[19], fast[19]);
|
||||
CHECK_EQ(diff[0], doctest::Approx(fast[0]));
|
||||
CHECK_EQ(diff[1], doctest::Approx(fast[1]));
|
||||
CHECK_EQ(diff[19], doctest::Approx(fast[19]));
|
||||
|
||||
CHECK_EQ(dea[0], slow[0]);
|
||||
CHECK_LT(std::fabs(dea[1] - slow[1]), 0.0001);
|
||||
CHECK_EQ(dea[19], slow[19]);
|
||||
|
||||
CHECK_EQ(bar[0], bmacd[0]);
|
||||
CHECK_EQ(bar[1], bmacd[1]);
|
||||
CHECK_EQ(bar[19], bmacd[19]);
|
||||
CHECK_EQ(bar[0], doctest::Approx(bmacd[0]));
|
||||
CHECK_EQ(bar[1], doctest::Approx(bmacd[1]));
|
||||
CHECK_EQ(bar[19], doctest::Approx(bmacd[19]));
|
||||
|
||||
/** @arg n1 = 3 n2 = 2 n3 = 1*/
|
||||
macd = MACD(ind, 3, 2, 1);
|
||||
@ -104,17 +104,17 @@ TEST_CASE("test_MACD") {
|
||||
CHECK_EQ(diff.size(), 20);
|
||||
CHECK_EQ(dea.size(), 20);
|
||||
|
||||
CHECK_EQ(diff[0], fast[0]);
|
||||
CHECK_EQ(diff[1], fast[1]);
|
||||
CHECK_EQ(diff[19], fast[19]);
|
||||
CHECK_EQ(diff[0], doctest::Approx(fast[0]));
|
||||
CHECK_EQ(diff[1], doctest::Approx(fast[1]));
|
||||
CHECK_EQ(diff[19], doctest::Approx(fast[19]));
|
||||
|
||||
CHECK_EQ(dea[0], slow[0]);
|
||||
CHECK_EQ(dea[1], slow[1]);
|
||||
CHECK_EQ(dea[19], slow[19]);
|
||||
CHECK_EQ(dea[0], doctest::Approx(slow[0]));
|
||||
CHECK_EQ(dea[1], doctest::Approx(slow[1]));
|
||||
CHECK_EQ(dea[19], doctest::Approx(slow[19]));
|
||||
|
||||
CHECK_EQ(bar[0], bmacd[0]);
|
||||
CHECK_EQ(bar[1], bmacd[1]);
|
||||
CHECK_EQ(bar[19], bmacd[19]);
|
||||
CHECK_EQ(bar[0], doctest::Approx(bmacd[0]));
|
||||
CHECK_EQ(bar[1], doctest::Approx(bmacd[1]));
|
||||
CHECK_EQ(bar[19], doctest::Approx(bmacd[19]));
|
||||
|
||||
/** @arg n1 = 3 n2 = 5 n3 = 2*/
|
||||
macd = MACD(ind, 3, 5, 2);
|
||||
@ -132,17 +132,17 @@ TEST_CASE("test_MACD") {
|
||||
CHECK_EQ(diff.size(), 20);
|
||||
CHECK_EQ(dea.size(), 20);
|
||||
|
||||
CHECK_EQ(diff[0], fast[0]);
|
||||
CHECK_EQ(diff[1], fast[1]);
|
||||
CHECK_EQ(diff[19], fast[19]);
|
||||
CHECK_EQ(diff[0], doctest::Approx(fast[0]));
|
||||
CHECK_EQ(diff[1], doctest::Approx(fast[1]));
|
||||
CHECK_EQ(diff[19], doctest::Approx(fast[19]));
|
||||
|
||||
CHECK_EQ(dea[0], slow[0]);
|
||||
CHECK_EQ(dea[1], slow[1]);
|
||||
CHECK_EQ(dea[19], slow[19]);
|
||||
CHECK_EQ(dea[0], doctest::Approx(slow[0]));
|
||||
CHECK_EQ(dea[1], doctest::Approx(slow[1]));
|
||||
CHECK_EQ(dea[19], doctest::Approx(slow[19]));
|
||||
|
||||
CHECK_EQ(bar[0], bmacd[0]);
|
||||
CHECK_EQ(bar[1], bmacd[1]);
|
||||
CHECK_EQ(bar[19], bmacd[19]);
|
||||
CHECK_EQ(bar[0], doctest::Approx(bmacd[0]));
|
||||
CHECK_EQ(bar[1], doctest::Approx(bmacd[1]));
|
||||
CHECK_EQ(bar[19], doctest::Approx(bmacd[19]));
|
||||
|
||||
/** @arg operator() */
|
||||
Indicator expect = MACD(ind, 3, 5, 2);
|
||||
|
@ -28,7 +28,6 @@ TEST_CASE("test_PRICELIST") {
|
||||
result = PRICELIST(tmp_list);
|
||||
CHECK_EQ(result.size(), tmp_list.size());
|
||||
CHECK_EQ(result.empty(), true);
|
||||
|
||||
/** @arg PriceList 非空 */
|
||||
for (size_t i = 0; i < 10; ++i) {
|
||||
tmp_list.push_back(i);
|
||||
@ -45,6 +44,7 @@ TEST_CASE("test_PRICELIST") {
|
||||
result = PRICELIST(p_tmp, 10);
|
||||
CHECK_EQ(result.size(), 0);
|
||||
CHECK_EQ(result.empty(), true);
|
||||
#if 0
|
||||
|
||||
/** @arg 数组指针非空 */
|
||||
price_t tmp[10];
|
||||
@ -97,6 +97,7 @@ TEST_CASE("test_PRICELIST") {
|
||||
for (size_t i = 0; i < result.size(); ++i) {
|
||||
CHECK_EQ(result[i], ikdata.get(i, 1));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -62,9 +62,9 @@ TEST_CASE("test_SAFTYLOSS") {
|
||||
CHECK_EQ(result.size(), close.size());
|
||||
CHECK_EQ(result.discard(), 1);
|
||||
CHECK_UNARY(std::isnan(result[0]));
|
||||
CHECK_EQ(result[1], 27.67);
|
||||
CHECK_EQ(result[2], 28.05);
|
||||
CHECK_EQ(result[3], 27.45);
|
||||
CHECK_EQ(result[1], doctest::Approx(27.67));
|
||||
CHECK_EQ(result[2], doctest::Approx(28.05));
|
||||
CHECK_EQ(result[3], doctest::Approx(27.45));
|
||||
CHECK_LT(std::fabs(result[19] - 25.54), 0.0001);
|
||||
|
||||
result = SAFTYLOSS(close, 2, 2, 1.0);
|
||||
@ -73,9 +73,9 @@ TEST_CASE("test_SAFTYLOSS") {
|
||||
CHECK_EQ(result.discard(), 2);
|
||||
CHECK_UNARY(std::isnan(result[0]));
|
||||
CHECK_UNARY(std::isnan(result[1]));
|
||||
CHECK_EQ(result[2], 28.05);
|
||||
CHECK_EQ(result[3], 28.05);
|
||||
CHECK_EQ(result[4], 27.45);
|
||||
CHECK_EQ(result[2], doctest::Approx(28.05));
|
||||
CHECK_EQ(result[3], doctest::Approx(28.05));
|
||||
CHECK_EQ(result[4], doctest::Approx(27.45));
|
||||
CHECK_LT(std::fabs(result[19] - 25.54), 0.0001);
|
||||
|
||||
result = SAFTYLOSS(close, 3, 2, 2.0);
|
||||
|
@ -43,7 +43,7 @@ TEST_CASE("test_SIN") {
|
||||
result = SIN(-11);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::sin(-11));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::sin(-11)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -74,7 +74,7 @@ TEST_CASE("test_SMA") {
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result.size(), data.size());
|
||||
CHECK_EQ(result[0], 0);
|
||||
CHECK_EQ(result[1], 0.05);
|
||||
CHECK_EQ(result[1], doctest::Approx(0.05));
|
||||
CHECK_EQ(result[5], doctest::Approx(0.4031).epsilon(0.01));
|
||||
CHECK_EQ(result[9], doctest::Approx(0.8002).epsilon(0.01));
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ TEST_CASE("test_TAN") {
|
||||
result = TAN(-11);
|
||||
CHECK_EQ(result.size(), 1);
|
||||
CHECK_EQ(result.discard(), 0);
|
||||
CHECK_EQ(result[0], std::tan(-11));
|
||||
CHECK_EQ(result[0], doctest::Approx(std::tan(-11)));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -39,7 +39,7 @@ TEST_CASE("test_VIGOR") {
|
||||
CHECK_EQ(vigor.size(), 10);
|
||||
CHECK_UNARY_FALSE(vigor.empty());
|
||||
CHECK_UNARY(std::isnan(vigor[0]));
|
||||
CHECK_LT(std::fabs(vigor[1] + 11761.36), 0.0001);
|
||||
CHECK_EQ(vigor[1], doctest::Approx(-11761.36));
|
||||
|
||||
vigor = VIGOR(kdata, 2);
|
||||
CHECK_EQ(vigor.discard(), 1);
|
||||
|
@ -25,7 +25,7 @@ TEST_CASE("test_round") {
|
||||
CHECK(roundEx(x) == 10.0);
|
||||
CHECK(roundDown(x) == 10.0);
|
||||
CHECK(roundUp(x) == 11.0);
|
||||
CHECK(roundEx(x, 1) == 10.1);
|
||||
CHECK_EQ(roundEx(x, 1), doctest::Approx(10.1));
|
||||
CHECK(roundDown(x, 1) == 10.1);
|
||||
CHECK(roundUp(x, 1) == 10.2);
|
||||
|
||||
@ -33,7 +33,7 @@ TEST_CASE("test_round") {
|
||||
CHECK(roundEx(x) == 11);
|
||||
CHECK(roundDown(x) == 10);
|
||||
CHECK(roundUp(x) == 11.0);
|
||||
CHECK(roundEx(x, 1) == 10.6);
|
||||
CHECK_EQ(roundEx(x, 1), doctest::Approx(10.6));
|
||||
CHECK(roundDown(x, 1) == 10.5);
|
||||
CHECK(roundUp(x, 1) == 10.6);
|
||||
|
||||
@ -41,7 +41,7 @@ TEST_CASE("test_round") {
|
||||
CHECK(roundEx(x) == -10);
|
||||
CHECK(roundDown(x) == -10);
|
||||
CHECK(roundUp(x) == -11.0);
|
||||
CHECK(roundEx(x, 1) == -10.1);
|
||||
CHECK_EQ(roundEx(x, 1), doctest::Approx(-10.1));
|
||||
CHECK(roundDown(x, 1) == -10.1);
|
||||
CHECK(roundUp(x, 1) == -10.2);
|
||||
|
||||
@ -49,9 +49,9 @@ TEST_CASE("test_round") {
|
||||
CHECK(roundEx(x) == -11);
|
||||
CHECK(roundDown(x) == -10);
|
||||
CHECK(roundUp(x) == -11.0);
|
||||
CHECK(roundEx(x, 1) == -10.6);
|
||||
CHECK_EQ(roundEx(x, 1), doctest::Approx(-10.6));
|
||||
CHECK(roundDown(x, 1) == -10.5);
|
||||
CHECK(roundUp(x, 1) == -10.6);
|
||||
CHECK_EQ(roundUp(x, 1), doctest::Approx(-10.6));
|
||||
}
|
||||
|
||||
TEST_CASE("test_string_to_upper") {
|
||||
|
@ -12,7 +12,16 @@ using namespace hku;
|
||||
namespace py = pybind11;
|
||||
|
||||
void export_util(py::module& m) {
|
||||
m.def("roundEx", roundEx, py::arg("number"), py::arg("ndigits") = 0,
|
||||
m.def("roundEx", roundEx<double>, py::arg("number"), py::arg("ndigits") = 0,
|
||||
R"(roundEx(number[, ndigits=0])
|
||||
|
||||
四舍五入,ROUND_HALF_EVEN 银行家舍入法
|
||||
|
||||
:param float number 待四舍五入的数据
|
||||
:param int ndigits 保留小数位数
|
||||
:rype: float)");
|
||||
|
||||
m.def("roundEx", roundEx<float>, py::arg("number"), py::arg("ndigits") = 0,
|
||||
R"(roundEx(number[, ndigits=0])
|
||||
|
||||
四舍五入,ROUND_HALF_EVEN 银行家舍入法
|
||||
|
@ -177,65 +177,65 @@ set_context(self, stock, query)
|
||||
.def(
|
||||
"to_np",
|
||||
[](const Indicator& self) {
|
||||
py::array_t<price_t> ret;
|
||||
py::array_t<Indicator::value_type> ret;
|
||||
auto imp = self.getImp();
|
||||
HKU_IF_RETURN(!imp, ret);
|
||||
ret = py::array_t<price_t>(self.size(), imp->data(0));
|
||||
ret = py::array_t<Indicator::value_type>(self.size(), imp->data(0));
|
||||
return ret;
|
||||
},
|
||||
"转化为np.array,如果indicator存在多个值,只返回第一个")
|
||||
|
||||
.def(py::self + py::self)
|
||||
.def(py::self + price_t())
|
||||
.def(price_t() + py::self)
|
||||
.def(py::self + Indicator::value_type())
|
||||
.def(Indicator::value_type() + py::self)
|
||||
|
||||
.def(py::self - py::self)
|
||||
.def(py::self - price_t())
|
||||
.def(price_t() - py::self)
|
||||
.def(py::self - Indicator::value_type())
|
||||
.def(Indicator::value_type() - py::self)
|
||||
|
||||
.def(py::self * py::self)
|
||||
.def(py::self * price_t())
|
||||
.def(price_t() * py::self)
|
||||
.def(py::self * Indicator::value_type())
|
||||
.def(Indicator::value_type() * py::self)
|
||||
|
||||
.def(py::self / py::self)
|
||||
.def(py::self / price_t())
|
||||
.def(price_t() / py::self)
|
||||
.def(py::self / Indicator::value_type())
|
||||
.def(Indicator::value_type() / py::self)
|
||||
|
||||
.def(py::self == py::self)
|
||||
.def(py::self == price_t())
|
||||
.def(price_t() == py::self)
|
||||
.def(py::self == Indicator::value_type())
|
||||
.def(Indicator::value_type() == py::self)
|
||||
|
||||
.def(py::self != py::self)
|
||||
.def(py::self != price_t())
|
||||
.def(price_t() != py::self)
|
||||
.def(py::self != Indicator::value_type())
|
||||
.def(Indicator::value_type() != py::self)
|
||||
|
||||
.def(py::self >= py::self)
|
||||
.def(py::self >= price_t())
|
||||
.def(price_t() >= py::self)
|
||||
.def(py::self >= Indicator::value_type())
|
||||
.def(Indicator::value_type() >= py::self)
|
||||
|
||||
.def(py::self <= py::self)
|
||||
.def(py::self <= price_t())
|
||||
.def(price_t() <= py::self)
|
||||
.def(py::self <= Indicator::value_type())
|
||||
.def(Indicator::value_type() <= py::self)
|
||||
|
||||
.def(py::self > py::self)
|
||||
.def(py::self > price_t())
|
||||
.def(price_t() > py::self)
|
||||
.def(py::self > Indicator::value_type())
|
||||
.def(Indicator::value_type() > py::self)
|
||||
|
||||
.def(py::self < py::self)
|
||||
.def(py::self < price_t())
|
||||
.def(price_t() < py::self)
|
||||
.def(py::self < Indicator::value_type())
|
||||
.def(Indicator::value_type() < py::self)
|
||||
|
||||
.def(py::self % py::self)
|
||||
.def(py::self % price_t())
|
||||
.def(price_t() % py::self)
|
||||
.def(py::self % Indicator::value_type())
|
||||
.def(Indicator::value_type() % py::self)
|
||||
|
||||
.def(py::self & py::self)
|
||||
.def(py::self & price_t())
|
||||
.def(price_t() & py::self)
|
||||
.def(py::self & Indicator::value_type())
|
||||
.def(Indicator::value_type() & py::self)
|
||||
|
||||
.def(py::self | py::self)
|
||||
.def(py::self | price_t())
|
||||
.def(price_t() | py::self)
|
||||
.def(py::self | Indicator::value_type())
|
||||
.def(Indicator::value_type() | py::self)
|
||||
|
||||
DEF_PICKLE(Indicator);
|
||||
}
|
||||
|
@ -161,9 +161,9 @@ Indicator (*HSL_1)() = HSL;
|
||||
Indicator (*HSL_2)(const KData&) = HSL;
|
||||
|
||||
Indicator (*IF_1)(const Indicator&, const Indicator&, const Indicator&) = IF;
|
||||
Indicator (*IF_2)(const Indicator&, price_t, const Indicator&) = IF;
|
||||
Indicator (*IF_3)(const Indicator&, const Indicator&, price_t) = IF;
|
||||
Indicator (*IF_4)(const Indicator&, price_t, price_t) = IF;
|
||||
Indicator (*IF_2)(const Indicator&, Indicator::value_type, const Indicator&) = IF;
|
||||
Indicator (*IF_3)(const Indicator&, const Indicator&, Indicator::value_type) = IF;
|
||||
Indicator (*IF_4)(const Indicator&, Indicator::value_type, Indicator::value_type) = IF;
|
||||
|
||||
Indicator (*COUNT_1)(int) = COUNT;
|
||||
Indicator (*COUNT_2)(const IndParam&) = COUNT;
|
||||
@ -178,43 +178,44 @@ Indicator (*SUM_4)(const Indicator&, const Indicator&) = SUM;
|
||||
Indicator (*SUM_5)(const Indicator&, int) = SUM;
|
||||
|
||||
Indicator (*ABS_1)() = ABS;
|
||||
Indicator (*ABS_2)(price_t) = ABS;
|
||||
Indicator (*ABS_2)(Indicator::value_type) = ABS;
|
||||
Indicator (*ABS_3)(const Indicator&) = ABS;
|
||||
|
||||
Indicator (*NOT_1)() = NOT;
|
||||
Indicator (*NOT_2)(const Indicator&) = NOT;
|
||||
|
||||
Indicator (*SGN_1)() = SGN;
|
||||
Indicator (*SGN_2)(price_t) = SGN;
|
||||
Indicator (*SGN_2)(Indicator::value_type) = SGN;
|
||||
Indicator (*SGN_3)(const Indicator&) = SGN;
|
||||
|
||||
Indicator (*EXP_1)() = EXP;
|
||||
Indicator (*EXP_2)(price_t) = EXP;
|
||||
Indicator (*EXP_2)(Indicator::value_type) = EXP;
|
||||
Indicator (*EXP_3)(const Indicator&) = EXP;
|
||||
|
||||
Indicator (*MAX_1)(const Indicator&, const Indicator&) = MAX;
|
||||
Indicator (*MAX_2)(const Indicator&, price_t) = MAX;
|
||||
Indicator (*MAX_3)(price_t, const Indicator&) = MAX;
|
||||
Indicator (*MAX_2)(const Indicator&, Indicator::value_type) = MAX;
|
||||
Indicator (*MAX_3)(Indicator::value_type, const Indicator&) = MAX;
|
||||
|
||||
Indicator (*MIN_1)(const Indicator&, const Indicator&) = MIN;
|
||||
Indicator (*MIN_2)(const Indicator&, price_t) = MIN;
|
||||
Indicator (*MIN_3)(price_t, const Indicator&) = MIN;
|
||||
Indicator (*MIN_2)(const Indicator&, Indicator::value_type) = MIN;
|
||||
Indicator (*MIN_3)(Indicator::value_type, const Indicator&) = MIN;
|
||||
|
||||
Indicator (*BETWEEN_1)(const Indicator&, const Indicator&, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_2)(const Indicator&, const Indicator&, price_t) = BETWEEN;
|
||||
Indicator (*BETWEEN_3)(const Indicator&, price_t, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_4)(const Indicator&, price_t, price_t) = BETWEEN;
|
||||
Indicator (*BETWEEN_5)(price_t, const Indicator&, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_6)(price_t, const Indicator&, price_t) = BETWEEN;
|
||||
Indicator (*BETWEEN_7)(price_t, price_t, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_8)(price_t, price_t, price_t) = BETWEEN;
|
||||
Indicator (*BETWEEN_2)(const Indicator&, const Indicator&, Indicator::value_type) = BETWEEN;
|
||||
Indicator (*BETWEEN_3)(const Indicator&, Indicator::value_type, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_4)(const Indicator&, Indicator::value_type, Indicator::value_type) = BETWEEN;
|
||||
Indicator (*BETWEEN_5)(Indicator::value_type, const Indicator&, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_6)(Indicator::value_type, const Indicator&, Indicator::value_type) = BETWEEN;
|
||||
Indicator (*BETWEEN_7)(Indicator::value_type, Indicator::value_type, const Indicator&) = BETWEEN;
|
||||
Indicator (*BETWEEN_8)(Indicator::value_type, Indicator::value_type,
|
||||
Indicator::value_type) = BETWEEN;
|
||||
|
||||
Indicator (*LN_1)() = LN;
|
||||
Indicator (*LN_2)(price_t) = LN;
|
||||
Indicator (*LN_2)(Indicator::value_type) = LN;
|
||||
Indicator (*LN_3)(const Indicator&) = LN;
|
||||
|
||||
Indicator (*LOG_1)() = LOG;
|
||||
Indicator (*LOG_2)(price_t) = LOG;
|
||||
Indicator (*LOG_2)(Indicator::value_type) = LOG;
|
||||
Indicator (*LOG_3)(const Indicator&) = LOG;
|
||||
|
||||
Indicator (*HHVBARS_1)(int) = HHVBARS;
|
||||
@ -234,35 +235,35 @@ 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 (*POW_6)(Indicator::value_type, int) = POW;
|
||||
|
||||
Indicator (*SQRT_1)() = SQRT;
|
||||
Indicator (*SQRT_2)(const Indicator&) = SQRT;
|
||||
Indicator (*SQRT_3)(price_t) = SQRT;
|
||||
Indicator (*SQRT_3)(Indicator::value_type) = SQRT;
|
||||
|
||||
Indicator (*ROUND_1)(int) = ROUND;
|
||||
Indicator (*ROUND_2)(const Indicator&, int) = ROUND;
|
||||
Indicator (*ROUND_3)(price_t, int) = ROUND;
|
||||
Indicator (*ROUND_3)(Indicator::value_type, int) = ROUND;
|
||||
|
||||
Indicator (*ROUNDUP_1)(int) = ROUNDUP;
|
||||
Indicator (*ROUNDUP_2)(const Indicator&, int) = ROUNDUP;
|
||||
Indicator (*ROUNDUP_3)(price_t, int) = ROUNDUP;
|
||||
Indicator (*ROUNDUP_3)(Indicator::value_type, int) = ROUNDUP;
|
||||
|
||||
Indicator (*ROUNDDOWN_1)(int) = ROUNDDOWN;
|
||||
Indicator (*ROUNDDOWN_2)(const Indicator&, int) = ROUNDDOWN;
|
||||
Indicator (*ROUNDDOWN_3)(price_t, int) = ROUNDDOWN;
|
||||
Indicator (*ROUNDDOWN_3)(Indicator::value_type, int) = ROUNDDOWN;
|
||||
|
||||
Indicator (*FLOOR_1)() = FLOOR;
|
||||
Indicator (*FLOOR_2)(const Indicator&) = FLOOR;
|
||||
Indicator (*FLOOR_3)(price_t) = FLOOR;
|
||||
Indicator (*FLOOR_3)(Indicator::value_type) = FLOOR;
|
||||
|
||||
Indicator (*CEILING_1)() = CEILING;
|
||||
Indicator (*CEILING_2)(const Indicator&) = CEILING;
|
||||
Indicator (*CEILING_3)(price_t) = CEILING;
|
||||
Indicator (*CEILING_3)(Indicator::value_type) = CEILING;
|
||||
|
||||
Indicator (*INTPART_1)() = INTPART;
|
||||
Indicator (*INTPART_2)(const Indicator&) = INTPART;
|
||||
Indicator (*INTPART_3)(price_t) = INTPART;
|
||||
Indicator (*INTPART_3)(Indicator::value_type) = INTPART;
|
||||
|
||||
Indicator (*EXIST_1)(int) = EXIST;
|
||||
Indicator (*EXIST_2)(const IndParam&) = EXIST;
|
||||
@ -290,36 +291,36 @@ Indicator (*LAST_11)(const Indicator&, const Indicator&, const Indicator&) = LAS
|
||||
|
||||
Indicator (*SIN_1)() = SIN;
|
||||
Indicator (*SIN_2)(const Indicator&) = SIN;
|
||||
Indicator (*SIN_3)(price_t) = SIN;
|
||||
Indicator (*SIN_3)(Indicator::value_type) = SIN;
|
||||
|
||||
Indicator (*ASIN_1)() = ASIN;
|
||||
Indicator (*ASIN_2)(const Indicator&) = ASIN;
|
||||
Indicator (*ASIN_3)(price_t) = ASIN;
|
||||
Indicator (*ASIN_3)(Indicator::value_type) = ASIN;
|
||||
|
||||
Indicator (*COS_1)() = COS;
|
||||
Indicator (*COS_2)(const Indicator&) = COS;
|
||||
Indicator (*COS_3)(price_t) = COS;
|
||||
Indicator (*COS_3)(Indicator::value_type) = COS;
|
||||
|
||||
Indicator (*ACOS_1)() = ACOS;
|
||||
Indicator (*ACOS_2)(const Indicator&) = ACOS;
|
||||
Indicator (*ACOS_3)(price_t) = ACOS;
|
||||
Indicator (*ACOS_3)(Indicator::value_type) = ACOS;
|
||||
|
||||
Indicator (*TAN_1)() = TAN;
|
||||
Indicator (*TAN_2)(const Indicator&) = TAN;
|
||||
Indicator (*TAN_3)(price_t) = TAN;
|
||||
Indicator (*TAN_3)(Indicator::value_type) = TAN;
|
||||
|
||||
Indicator (*ATAN_1)() = ATAN;
|
||||
Indicator (*ATAN_2)(const Indicator&) = ATAN;
|
||||
Indicator (*ATAN_3)(price_t) = ATAN;
|
||||
Indicator (*ATAN_3)(Indicator::value_type) = ATAN;
|
||||
|
||||
Indicator (*REVERSE_1)() = REVERSE;
|
||||
Indicator (*REVERSE_2)(const Indicator&) = REVERSE;
|
||||
Indicator (*REVERSE_3)(price_t) = REVERSE;
|
||||
Indicator (*REVERSE_3)(Indicator::value_type) = REVERSE;
|
||||
|
||||
Indicator (*MOD_1)(const Indicator&, const Indicator&) = MOD;
|
||||
Indicator (*MOD_2)(const Indicator&, price_t) = MOD;
|
||||
Indicator (*MOD_3)(price_t, const Indicator&) = MOD;
|
||||
Indicator (*MOD_4)(price_t, price_t) = MOD;
|
||||
Indicator (*MOD_2)(const Indicator&, Indicator::value_type) = MOD;
|
||||
Indicator (*MOD_3)(Indicator::value_type, const Indicator&) = MOD;
|
||||
Indicator (*MOD_4)(Indicator::value_type, Indicator::value_type) = MOD;
|
||||
|
||||
Indicator (*VAR_1)(int) = VAR;
|
||||
Indicator (*VAR_2)(const IndParam&) = VAR;
|
||||
@ -334,18 +335,19 @@ Indicator (*VARP_4)(const Indicator&, const Indicator&) = VARP;
|
||||
Indicator (*VARP_5)(const Indicator&, int) = VARP;
|
||||
|
||||
Indicator (*CROSS_1)(const Indicator&, const Indicator&) = CROSS;
|
||||
Indicator (*CROSS_2)(const Indicator&, price_t) = CROSS;
|
||||
Indicator (*CROSS_3)(price_t, const Indicator&) = CROSS;
|
||||
Indicator (*CROSS_4)(price_t, price_t) = CROSS;
|
||||
Indicator (*CROSS_2)(const Indicator&, Indicator::value_type) = CROSS;
|
||||
Indicator (*CROSS_3)(Indicator::value_type, const Indicator&) = CROSS;
|
||||
Indicator (*CROSS_4)(Indicator::value_type, Indicator::value_type) = CROSS;
|
||||
|
||||
Indicator (*LONGCROSS_1)(const Indicator&, const Indicator&, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_2)(const Indicator&, const Indicator&, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_3)(const Indicator&, price_t, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_4)(const Indicator&, price_t, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_5)(price_t, const Indicator&, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_6)(price_t, const Indicator&, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_7)(price_t, price_t, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_8)(price_t, price_t, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_3)(const Indicator&, Indicator::value_type, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_4)(const Indicator&, Indicator::value_type, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_5)(Indicator::value_type, const Indicator&, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_6)(Indicator::value_type, const Indicator&, const Indicator&) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_7)(Indicator::value_type, Indicator::value_type, int) = LONGCROSS;
|
||||
Indicator (*LONGCROSS_8)(Indicator::value_type, Indicator::value_type,
|
||||
const Indicator&) = LONGCROSS;
|
||||
|
||||
Indicator (*FILTER_1)(int) = FILTER;
|
||||
Indicator (*FILTER_2)(const IndParam&) = FILTER;
|
||||
@ -355,11 +357,11 @@ Indicator (*FILTER_5)(const Indicator&, int) = FILTER;
|
||||
|
||||
Indicator (*BARSSINCE_1)() = BARSSINCE;
|
||||
Indicator (*BARSSINCE_2)(const Indicator&) = BARSSINCE;
|
||||
Indicator (*BARSSINCE_3)(price_t) = BARSSINCE;
|
||||
Indicator (*BARSSINCE_3)(Indicator::value_type) = BARSSINCE;
|
||||
|
||||
Indicator (*BARSLAST_1)() = BARSLAST;
|
||||
Indicator (*BARSLAST_2)(const Indicator&) = BARSLAST;
|
||||
Indicator (*BARSLAST_3)(price_t) = BARSLAST;
|
||||
Indicator (*BARSLAST_3)(Indicator::value_type) = BARSLAST;
|
||||
|
||||
Indicator (*SUMBARS_1)(double) = SUMBARS;
|
||||
Indicator (*SUMBARS_2)(const IndParam&) = SUMBARS;
|
||||
|
@ -73,6 +73,12 @@ option("feedback")
|
||||
set_description("Enable send feedback.")
|
||||
option_end()
|
||||
|
||||
option("low_precision")
|
||||
set_default(false)
|
||||
set_showmenu(true)
|
||||
set_category("hikyuu")
|
||||
set_description("Enable send feedback.")
|
||||
option_end()
|
||||
|
||||
-- project
|
||||
set_project("hikyuu")
|
||||
@ -108,6 +114,8 @@ set_configvar("HKU_ENABLE_MYSQL_KDATA", get_config("mysql") and 1 or 0)
|
||||
set_configvar("HKU_ENABLE_SQLITE_KDATA", get_config("sqlite") and 1 or 0)
|
||||
set_configvar("HKU_ENABLE_TDX_KDATA", get_config("tdx") and 1 or 0)
|
||||
|
||||
set_configvar("HKU_USE_LOW_PRECISION", get_config("low_precision") and 1 or 0)
|
||||
|
||||
set_warnings("all")
|
||||
|
||||
-- set language: C99, c++ standard
|
||||
|
Loading…
Reference in New Issue
Block a user