-
Notifications
You must be signed in to change notification settings - Fork 621
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
156 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2025 hikyuu.org | ||
* | ||
* Created on: 2025-02-03 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#include "hikyuu/indicator/crt/ALIGN.h" | ||
#include "hikyuu/indicator/crt/CVAL.h" | ||
#include "hikyuu/indicator/crt/SLICE.h" | ||
#include "hikyuu/indicator/crt/CONTEXT.h" | ||
#include "Indicator2InImp.h" | ||
|
||
#if HKU_SUPPORT_SERIALIZATION | ||
BOOST_CLASS_EXPORT(hku::Indicator2InImp) | ||
#endif | ||
|
||
namespace hku { | ||
|
||
Indicator2InImp::Indicator2InImp() : IndicatorImp("Indicator2InImp") { | ||
setParam<bool>("fill_null", true); | ||
} | ||
|
||
Indicator2InImp::Indicator2InImp(const string& name, size_t result_num) | ||
: IndicatorImp(name, result_num) { | ||
setParam<bool>("fill_null", true); | ||
} | ||
|
||
Indicator2InImp::Indicator2InImp(const string& name, const Indicator& ref_ind, bool fill_null, | ||
size_t result_num) | ||
: IndicatorImp(name, result_num), m_ref_ind(ref_ind) { | ||
setParam<bool>("fill_null", fill_null); | ||
} | ||
|
||
Indicator2InImp::~Indicator2InImp() {} | ||
|
||
IndicatorImpPtr Indicator2InImp::_clone() { | ||
auto p = make_shared<Indicator2InImp>(); | ||
p->m_ref_ind = m_ref_ind.clone(); | ||
return p; | ||
} | ||
|
||
Indicator Indicator2InImp::prepare(const Indicator& ind) { | ||
auto k = getContext(); | ||
m_ref_ind.setContext(k); | ||
|
||
Indicator ref = m_ref_ind; | ||
auto dates = ref.getDatetimeList(); | ||
if (dates.empty()) { | ||
// 如果不是时间序列,则以 ind 为基准,按右端对齐,不足用 nan 填充, 超长则截断左端 | ||
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")); | ||
} | ||
|
||
return ref; | ||
} | ||
|
||
} // namespace hku |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2025 hikyuu.org | ||
* | ||
* Created on: 2025-02-03 | ||
* Author: fasiondog | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "Indicator.h" | ||
|
||
namespace hku { | ||
|
||
class Indicator2InImp : public IndicatorImp { | ||
public: | ||
Indicator2InImp(); | ||
explicit Indicator2InImp(const string& name, size_t result_num = 1); | ||
Indicator2InImp(const string& name, const Indicator& ref_a, bool fill_null = false, | ||
size_t result_num = 1); | ||
virtual ~Indicator2InImp(); | ||
|
||
virtual IndicatorImpPtr _clone() override; | ||
|
||
protected: | ||
Indicator prepare(const Indicator& ind); | ||
|
||
protected: | ||
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 | ||
}; | ||
|
||
#if HKU_SUPPORT_SERIALIZATION | ||
#define INDICATOR2IN_IMP_NO_PRIVATE_MEMBER_SERIALIZATION \ | ||
private: \ | ||
friend class boost::serialization::access; \ | ||
template <class Archive> \ | ||
void serialize(Archive& ar, const unsigned int version) { \ | ||
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(Indicator2InImp); \ | ||
} | ||
#else | ||
#define INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION | ||
#endif | ||
|
||
#define INDICATOR2IN_IMP(classname) \ | ||
public: \ | ||
virtual void _calculate(const Indicator& data) override; \ | ||
virtual IndicatorImpPtr _clone() override { \ | ||
auto p = make_shared<classname>(); \ | ||
p->m_ref_ind = m_ref_ind.clone(); \ | ||
return p; \ | ||
} | ||
|
||
} // namespace hku |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.