2015-01-07 01:26:14 +08:00
|
|
|
/*
|
|
|
|
* Indicator.cpp
|
|
|
|
*
|
|
|
|
* Created on: 2012-10-15
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Indicator.h"
|
2019-03-22 23:12:28 +08:00
|
|
|
#include "crt/CVAL.h"
|
2015-01-07 01:26:14 +08:00
|
|
|
|
|
|
|
namespace hku {
|
|
|
|
|
|
|
|
HKU_API std::ostream & operator<<(std::ostream& os, const Indicator& indicator) {
|
|
|
|
os << indicator.m_imp;
|
|
|
|
return os;
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator::Indicator(const IndicatorImpPtr& imp): m_imp(imp) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator::Indicator(const Indicator& indicator) {
|
|
|
|
m_imp = indicator.m_imp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Indicator::~Indicator() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-14 01:53:13 +08:00
|
|
|
string Indicator::formula() const {
|
|
|
|
return m_imp ? m_imp->formula() : "Indicator";
|
|
|
|
}
|
|
|
|
|
2019-03-15 23:35:09 +08:00
|
|
|
void Indicator::setContext(const Stock& stock, const KQuery& query) {
|
|
|
|
if (m_imp) m_imp->setContext(stock, query);
|
|
|
|
}
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
Indicator& Indicator::operator=(const Indicator& indicator) {
|
|
|
|
if (this == &indicator)
|
|
|
|
return *this;
|
|
|
|
|
|
|
|
if (m_imp != indicator.m_imp)
|
|
|
|
m_imp = indicator.m_imp;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
string Indicator::name() const {
|
|
|
|
return m_imp ? m_imp->name() : "IndicatorImp";
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:08:31 +08:00
|
|
|
void Indicator::name(const string& name) {
|
|
|
|
if (m_imp) {
|
|
|
|
m_imp->name(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
string Indicator::long_name() const {
|
|
|
|
return m_imp ? m_imp->long_name() : "IndicatorImp()";
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Indicator::discard() const {
|
|
|
|
return m_imp ? m_imp->discard() : 0 ;
|
|
|
|
}
|
|
|
|
|
2016-04-03 00:08:31 +08:00
|
|
|
void Indicator::setDiscard(size_t discard) {
|
|
|
|
if (m_imp)
|
|
|
|
m_imp->setDiscard(discard);
|
|
|
|
}
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
size_t Indicator::getResultNumber() const {
|
|
|
|
return m_imp ? m_imp->getResultNumber() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Indicator::empty() const {
|
|
|
|
return (!m_imp || m_imp->size() == 0) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Indicator::size() const {
|
|
|
|
return m_imp ? m_imp->size() : 0;
|
|
|
|
}
|
|
|
|
|
2019-03-17 23:07:30 +08:00
|
|
|
Indicator Indicator::operator()(const Indicator& ind) {
|
|
|
|
if (!m_imp)
|
|
|
|
return Indicator();
|
|
|
|
|
|
|
|
if (!ind.getImp())
|
|
|
|
return Indicator(m_imp);
|
|
|
|
|
|
|
|
IndicatorImpPtr p = m_imp->clone();
|
|
|
|
p->add(IndicatorImp::OP, IndicatorImpPtr(), ind.getImp()->clone());
|
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator+(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::ADD, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator-(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::SUB, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator*(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::MUL, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator/(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::DIV, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator==(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::EQ, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator!=(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::NE, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator>(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::GT, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator<(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::LT, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator>=(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-17 23:07:30 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::GE, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-17 23:07:30 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator<=(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2015-01-07 01:26:14 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
2019-03-15 01:49:07 +08:00
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::LE, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-15 01:49:07 +08:00
|
|
|
return p->calculate();
|
2015-01-07 01:26:14 +08:00
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator&(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-18 03:00:42 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::AND, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-18 03:00:42 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
HKU_API Indicator operator|(const Indicator& ind1, const Indicator& ind2) {
|
|
|
|
if (!ind1.getImp() || !ind2.getImp()) {
|
2019-03-18 03:00:42 +08:00
|
|
|
return Indicator();
|
|
|
|
}
|
|
|
|
|
|
|
|
IndicatorImpPtr p = make_shared<IndicatorImp>();
|
2019-03-22 23:12:28 +08:00
|
|
|
p->add(IndicatorImp::OR, ind1.getImp()->clone(), ind2.getImp()->clone());
|
2019-03-18 03:00:42 +08:00
|
|
|
return p->calculate();
|
|
|
|
}
|
|
|
|
|
2019-03-22 23:12:28 +08:00
|
|
|
|
|
|
|
HKU_API Indicator operator+(const Indicator& ind, price_t val) {
|
|
|
|
return ind + CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator+(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) + ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator-(const Indicator& ind, price_t val) {
|
|
|
|
return ind - CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator-(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) - ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator*(const Indicator& ind, price_t val) {
|
|
|
|
return ind * CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator*(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) * ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator/(const Indicator& ind, price_t val) {
|
|
|
|
return ind / CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator/(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) / ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator==(const Indicator& ind, price_t val) {
|
|
|
|
return ind == CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator==(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) == ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator!=(const Indicator& ind, price_t val) {
|
|
|
|
return ind != CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator!=(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) != ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator>(const Indicator& ind, price_t val) {
|
|
|
|
return ind > CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator>(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) > ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator<(const Indicator& ind, price_t val) {
|
|
|
|
return ind < CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator<(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) < ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator>=(const Indicator& ind, price_t val) {
|
|
|
|
return ind >= CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator>=(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) >= ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator<=(const Indicator& ind, price_t val) {
|
|
|
|
return ind <= CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator<=(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) <= ind;
|
|
|
|
}
|
|
|
|
|
2019-03-23 02:27:28 +08:00
|
|
|
HKU_API Indicator operator&(const Indicator& ind, price_t val) {
|
|
|
|
return ind & CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator&(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) & ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator|(const Indicator& ind, price_t val) {
|
|
|
|
return ind | CVAL(ind, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
HKU_API Indicator operator|(price_t val, const Indicator& ind) {
|
|
|
|
return CVAL(ind, val) | ind;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-07 01:26:14 +08:00
|
|
|
} /* namespace hku */
|