From a46d82478675f107843c83becd0516d19794c354 Mon Sep 17 00:00:00 2001 From: fasiondog Date: Sun, 24 Mar 2019 01:59:03 +0800 Subject: [PATCH] update --- hikyuu/interactive/kaufman.py | 10 +++---- hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp | 27 ++++++++++++++++--- hikyuu_cpp/hikyuu/indicator/IndicatorImp.h | 1 + .../hikyuu/indicator/imp/IPriceList.cpp | 4 +-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/hikyuu/interactive/kaufman.py b/hikyuu/interactive/kaufman.py index d6ec2370..81782086 100644 --- a/hikyuu/interactive/kaufman.py +++ b/hikyuu/interactive/kaufman.py @@ -95,11 +95,11 @@ def draw(stock, query = Query(-130), cer.plot(axes=ax2, color='b', marker='o', label=label, legend_on=False, text_on=True) - total = len(kdata) - CVAL(0.8, total).plot(axes=ax2,color='r',linestyle='--') - CVAL(-0.6, total).plot(axes=ax2,color='r',linestyle='--') - CVAL(-0.8, total).plot(axes=ax2,color='r',linestyle='--') - CVAL(0, total).plot(axes=ax2,color='k',linestyle='-') + c = CLOSE(kdata) + CVAL(c, 0.8).plot(axes=ax2,color='r',linestyle='--') + CVAL(c, -0.6).plot(axes=ax2,color='r',linestyle='--') + CVAL(c, -0.8).plot(axes=ax2,color='r',linestyle='--') + CVAL(c, 0).plot(axes=ax2,color='k',linestyle='-') #ax2.hlines(0.8,0,len(kdata),color='r',linestyle='--') #ax2.hlines(-0.6,0,len(kdata),color='r',linestyle='--') #ax2.hlines(-0.8,0,len(kdata),color='r',linestyle='--') diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp index 21f625c5..fea5657f 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.cpp @@ -29,19 +29,22 @@ HKU_API std::ostream & operator<<(std::ostream& os, const IndicatorImpPtr& imp) } IndicatorImp::IndicatorImp() -: m_name("IndicatorImp"), m_discard(0), m_result_num(0), m_optype(LEAF) { +: m_name("IndicatorImp"), m_discard(0), m_result_num(0), + m_optype(LEAF), m_need_calculate(true) { initContext(); memset(m_pBuffer, 0, sizeof(PriceList*) * MAX_RESULT_NUM); } IndicatorImp::IndicatorImp(const string& name) -: m_name(name), m_discard(0), m_result_num(0), m_optype(LEAF) { +: m_name(name), m_discard(0), m_result_num(0), + m_optype(LEAF), m_need_calculate(true) { initContext(); memset(m_pBuffer, 0, sizeof(PriceList*) * MAX_RESULT_NUM); } IndicatorImp::IndicatorImp(const string& name, size_t result_num) -: m_name(name), m_discard(0), m_optype(LEAF) { +: m_name(name), m_discard(0), m_optype(LEAF), + m_need_calculate(true) { initContext(); memset(m_pBuffer, 0, sizeof(PriceList*) * MAX_RESULT_NUM); m_result_num = result_num < MAX_RESULT_NUM ? result_num : MAX_RESULT_NUM; @@ -52,6 +55,8 @@ void IndicatorImp::initContext() { } void IndicatorImp::setContext(const Stock& stock, const KQuery& query) { + m_need_calculate = true; + //子节点设置上下文 if (m_left) m_left->setContext(stock, query); if (m_right) m_right->setContext(stock, query); @@ -86,7 +91,7 @@ void IndicatorImp::_readyBuffer(size_t len, size_t result_num) { } if (result_num == 0) { - HKU_ERROR("result_num is zeror! [IndicatorImp::_readyBuffer]") + HKU_WARN("result_num is zeror! (" << name() << ") [IndicatorImp::_readyBuffer]") return; } @@ -125,7 +130,15 @@ IndicatorImpPtr IndicatorImp::clone() { p->m_name = m_name; p->m_discard = m_discard; p->m_result_num = m_result_num; + p->m_need_calculate = m_need_calculate; p->m_optype = m_optype; + + 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()); + } + } + if (m_left) { p->m_left = m_left->clone(); } @@ -295,6 +308,7 @@ void IndicatorImp::add(OPType op, IndicatorImpPtr left, IndicatorImpPtr right) { new_right = right->getSameNameNeedContextLeaf(right->name()); } + m_need_calculate = true; m_optype = op; m_left = left ? left->clone() : left; m_right = new_right ? new_right : right->clone(); @@ -313,6 +327,10 @@ Indicator IndicatorImp::calculate() { } } + if (!m_need_calculate) { + return shared_from_this(); + } + switch (m_optype) { case LEAF: _calculate(Indicator()); @@ -380,6 +398,7 @@ Indicator IndicatorImp::calculate() { break; } + m_need_calculate = false; return shared_from_this(); } diff --git a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h index 5e346541..36d0b157 100644 --- a/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h +++ b/hikyuu_cpp/hikyuu/indicator/IndicatorImp.h @@ -177,6 +177,7 @@ protected: size_t m_result_num; PriceList *m_pBuffer[MAX_RESULT_NUM]; + bool m_need_calculate; OPType m_optype; IndicatorImpPtr m_left; IndicatorImpPtr m_right; diff --git a/hikyuu_cpp/hikyuu/indicator/imp/IPriceList.cpp b/hikyuu_cpp/hikyuu/indicator/imp/IPriceList.cpp index 465a6ffc..23b8e368 100644 --- a/hikyuu_cpp/hikyuu/indicator/imp/IPriceList.cpp +++ b/hikyuu_cpp/hikyuu/indicator/imp/IPriceList.cpp @@ -9,14 +9,14 @@ namespace hku { -IPriceList::IPriceList() : IndicatorImp("PRICELIST") { +IPriceList::IPriceList() : IndicatorImp("PRICELIST", 1) { setParam("result_index", 0); setParam("data", PriceList()); setParam("discard", 0); } IPriceList::IPriceList(const PriceList& data, int in_discard) -: IndicatorImp("PRICELIST") { +: IndicatorImp("PRICELIST", 1) { setParam("result_index", 0); setParam("data", data); setParam("discard", in_discard);