mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-01 11:28:32 +08:00
update
This commit is contained in:
parent
318175142e
commit
6944fa74b0
@ -32,18 +32,14 @@ Indicator::~Indicator() {
|
|||||||
Indicator Indicator::operator()(const Indicator& ind) {
|
Indicator Indicator::operator()(const Indicator& ind) {
|
||||||
std::cout << "Indicator Indicator::operator()(const Indicator& ind)" << std::endl;
|
std::cout << "Indicator Indicator::operator()(const Indicator& ind)" << std::endl;
|
||||||
//return m_imp ? Indicator((*m_imp)(ind)) : Indicator();
|
//return m_imp ? Indicator((*m_imp)(ind)) : Indicator();
|
||||||
IndicatorImpPtr p;
|
if (!m_imp || !ind.getImp()) {
|
||||||
if (!m_imp) {
|
return Indicator();
|
||||||
return Indicator(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
p = m_imp->clone();
|
|
||||||
if (!ind.getImp()) {
|
|
||||||
return Indicator(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IndicatorImpPtr p = m_imp->clone();
|
||||||
|
p->calculate(ind);
|
||||||
p->add(IndicatorImp::OP, IndicatorImpPtr(), ind.getImp()->clone());
|
p->add(IndicatorImp::OP, IndicatorImpPtr(), ind.getImp()->clone());
|
||||||
//p->calculate();
|
//p->calculate(ind);
|
||||||
return Indicator(p);
|
return Indicator(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,16 +89,21 @@ size_t Indicator::size() const {
|
|||||||
return m_imp ? m_imp->size() : 0;
|
return m_imp ? m_imp->size() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
HKU_API Indicator operator+(const Indicator& ind1, const Indicator& ind2) {
|
HKU_API Indicator operator+(const Indicator& ind1, const Indicator& ind2) {
|
||||||
if (ind1.size() == 0 || ind1.size() != ind2.size()) {
|
if (!ind1.getImp() || !ind2.getImp()) {
|
||||||
return Indicator();
|
return Indicator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IndicatorImpPtr imp = make_shared<IndicatorImp>();
|
||||||
|
imp->add(IndicatorImp::ADD, ind1.getImp()->clone(), ind2.getImp()->clone());
|
||||||
|
|
||||||
size_t result_number = std::min(ind1.getResultNumber(), ind2.getResultNumber());
|
size_t result_number = std::min(ind1.getResultNumber(), ind2.getResultNumber());
|
||||||
size_t total = ind1.size();
|
size_t total = std::min(ind1.size(), ind2.size());
|
||||||
size_t discard = std::max(ind1.discard(), ind2.discard());
|
size_t discard = std::max(ind1.discard(), ind2.discard());
|
||||||
IndicatorImpPtr imp(new IndicatorImp());
|
if (discard > total)
|
||||||
|
discard = total;
|
||||||
|
|
||||||
imp->_readyBuffer(total, result_number);
|
imp->_readyBuffer(total, result_number);
|
||||||
imp->setDiscard(discard);
|
imp->setDiscard(discard);
|
||||||
for (size_t i = discard; i < total; ++i) {
|
for (size_t i = discard; i < total; ++i) {
|
||||||
@ -114,7 +115,7 @@ HKU_API Indicator operator+(const Indicator& ind1, const Indicator& ind2) {
|
|||||||
return Indicator(imp);
|
return Indicator(imp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
HKU_API Indicator operator+(const Indicator& ind, price_t val) {
|
HKU_API Indicator operator+(const Indicator& ind, price_t val) {
|
||||||
if (ind.size() == 0) {
|
if (ind.size() == 0) {
|
||||||
return Indicator();
|
return Indicator();
|
||||||
|
@ -127,7 +127,7 @@ private:
|
|||||||
#endif /* HKU_SUPPORT_SERIALIZATION */
|
#endif /* HKU_SUPPORT_SERIALIZATION */
|
||||||
};
|
};
|
||||||
|
|
||||||
#if 0
|
|
||||||
/**
|
/**
|
||||||
* Indicator实例相加,两者的size必须相等,否在返回空
|
* Indicator实例相加,两者的size必须相等,否在返回空
|
||||||
* @return 1) 相加的两个实例的size必须相等,否在返回空实例
|
* @return 1) 相加的两个实例的size必须相等,否在返回空实例
|
||||||
@ -135,6 +135,7 @@ private:
|
|||||||
* @ingroup Indicator
|
* @ingroup Indicator
|
||||||
*/
|
*/
|
||||||
HKU_API Indicator operator+(const Indicator&, const Indicator&);
|
HKU_API Indicator operator+(const Indicator&, const Indicator&);
|
||||||
|
#if 0
|
||||||
HKU_API Indicator operator+(const Indicator&, price_t);
|
HKU_API Indicator operator+(const Indicator&, price_t);
|
||||||
HKU_API Indicator operator+(price_t, const Indicator&);
|
HKU_API Indicator operator+(price_t, const Indicator&);
|
||||||
|
|
||||||
|
@ -180,11 +180,9 @@ void IndicatorImp::add(OPType op, IndicatorImpPtr left, IndicatorImpPtr right) {
|
|||||||
m_right = right;
|
m_right = right;
|
||||||
if (m_left) m_left->m_parent = this;
|
if (m_left) m_left->m_parent = this;
|
||||||
m_right->m_parent = this;
|
m_right->m_parent = this;
|
||||||
|
|
||||||
calculate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IndicatorImp::calculate() {
|
void IndicatorImp::calculate(const Indicator& ind) {
|
||||||
if (!check()) {
|
if (!check()) {
|
||||||
HKU_WARN("Invalid param! " << long_name());
|
HKU_WARN("Invalid param! " << long_name());
|
||||||
return;
|
return;
|
||||||
@ -192,15 +190,18 @@ void IndicatorImp::calculate() {
|
|||||||
|
|
||||||
switch (m_optype) {
|
switch (m_optype) {
|
||||||
case LEAF:
|
case LEAF:
|
||||||
_calculate();
|
_calculate(Indicator());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OP:
|
case OP:
|
||||||
m_right->calculate();
|
m_right->calculate(ind);
|
||||||
|
this->calculate(Indicator(m_right));
|
||||||
//m_left->calculate();
|
//m_left->calculate();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ADD: {
|
case ADD: {
|
||||||
|
m_right->calculate(Indicator());
|
||||||
|
m_left->calculate(Indicator());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ public:
|
|||||||
/** 返回形如:Name(param1=val,param2=val,...) */
|
/** 返回形如:Name(param1=val,param2=val,...) */
|
||||||
string long_name() const;
|
string long_name() const;
|
||||||
|
|
||||||
void calculate();
|
void calculate(const Indicator&);
|
||||||
|
|
||||||
void setContext(const Stock&, const KQuery&);
|
void setContext(const Stock&, const KQuery&);
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
// ===================
|
// ===================
|
||||||
virtual bool check() { return false;}
|
virtual bool check() { return false;}
|
||||||
|
|
||||||
virtual void _calculate() {}
|
virtual void _calculate(const Indicator&) {}
|
||||||
|
|
||||||
virtual IndicatorImpPtr _clone() { return make_shared<IndicatorImp>(); }
|
virtual IndicatorImpPtr _clone() { return make_shared<IndicatorImp>(); }
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ BOOST_SERIALIZATION_ASSUME_ABSTRACT(IndicatorImp)
|
|||||||
virtual IndicatorImpPtr operator()(const Indicator& ind) { \
|
virtual IndicatorImpPtr operator()(const Indicator& ind) { \
|
||||||
IndicatorImpPtr p = make_shared<classname>(); \
|
IndicatorImpPtr p = make_shared<classname>(); \
|
||||||
p->setParameter(m_params); \
|
p->setParameter(m_params); \
|
||||||
p->calculate(); \
|
p->calculate(ind); \
|
||||||
return p; \
|
return p; \
|
||||||
} \
|
} \
|
||||||
virtual IndicatorImpPtr _clone() { return make_shared<classname>(); } \
|
virtual IndicatorImpPtr _clone() { return make_shared<classname>(); } \
|
||||||
|
Loading…
Reference in New Issue
Block a user