Skip to content

Commit

Permalink
优化双指标输入指标实现
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Feb 3, 2025
1 parent a4b3c57 commit 164b82b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 50 deletions.
34 changes: 3 additions & 31 deletions hikyuu_cpp/hikyuu/indicator_talib/imp/TaMavp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
*/

#include <ta-lib/ta_func.h>
#include "hikyuu/indicator/crt/ALIGN.h"
#include "hikyuu/indicator/crt/CVAL.h"
#include "hikyuu/indicator/crt/SLICE.h"
#include "hikyuu/indicator/crt/PRICELIST.h"
#include "hikyuu/indicator/imp/IContext.h"
#include "hikyuu/indicator/crt/CONTEXT.h"
#include "TaMavp.h"

#if HKU_SUPPORT_SERIALIZATION
Expand All @@ -20,19 +14,17 @@ BOOST_CLASS_EXPORT(hku::TaMavp)

namespace hku {

TaMavp::TaMavp() : IndicatorImp("TA_MAVP", 1) {
TaMavp::TaMavp() : Indicator2InImp("TA_MAVP", 1) {
setParam<int>("min_n", 2);
setParam<int>("max_n", 30);
setParam<int>("matype", 0);
setParam<bool>("fill_null", true);
}

TaMavp::TaMavp(const Indicator& ref_ind, int min_n, int max_n, int matype, bool fill_null)
: IndicatorImp("TA_MAVP", 1), m_ref_ind(ref_ind) {
: Indicator2InImp("TA_MAVP", ref_ind, fill_null, 1) {
setParam<int>("min_n", min_n);
setParam<int>("max_n", max_n);
setParam<int>("matype", matype);
setParam<bool>("fill_null", fill_null);
}

TaMavp::~TaMavp() {}
Expand All @@ -47,31 +39,11 @@ void TaMavp::_checkParam(const string& name) const {
}
}

IndicatorImpPtr TaMavp::_clone() {
auto p = make_shared<TaMavp>();
p->m_ref_ind = m_ref_ind.clone();
return p;
}

void TaMavp::_calculate(const Indicator& ind) {
size_t total = ind.size();
HKU_IF_RETURN(total == 0, void());

_readyBuffer(total, 2);

auto k = getContext();
m_ref_ind.setContext(k);
Indicator ref = m_ref_ind;
auto dates = ref.getDatetimeList();
if (dates.empty()) {
if (ref.size() > ind.size()) {
ref = SLICE(ref, ref.size() - ind.size(), ref.size());
} else if (ref.size() < ind.size()) {
ref = CVAL(ind, 0.) + ref;
}
} else if (k != ind.getContext()) {
ref = ALIGN(m_ref_ind, ind, getParam<bool>("fill_null"));
}
Indicator ref = prepare(ind);

int min_n = getParam<int>("min_n");
int max_n = getParam<int>("max_n");
Expand Down
24 changes: 5 additions & 19 deletions hikyuu_cpp/hikyuu/indicator_talib/imp/TaMavp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,20 @@
#pragma once

#include "hikyuu/indicator/Indicator.h"
#include "hikyuu/indicator/Indicator2InImp.h"

namespace hku {

class TaMavp : public IndicatorImp {
class TaMavp : public Indicator2InImp {
INDICATOR2IN_IMP(TaMavp)
INDICATOR2IN_IMP_NO_PRIVATE_MEMBER_SERIALIZATION

public:
TaMavp();
TaMavp(const Indicator& ref_ind, int min_n, int max_n, int matype, bool fill_null);
virtual ~TaMavp();

virtual void _checkParam(const string& name) const override;
virtual void _calculate(const Indicator& data) override;
virtual IndicatorImpPtr _clone() override;

private:
Indicator m_ref_ind;

//============================================
// 序列化支持
//============================================
#if HKU_SUPPORT_SERIALIZATION
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(IndicatorImp);
ar& BOOST_SERIALIZATION_NVP(m_ref_ind);
}
#endif
};

} // namespace hku

0 comments on commit 164b82b

Please sign in to comment.