hikyuu2/hikyuu_cpp/hikyuu/indicator/Indicator.h

257 lines
8.8 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* Indicator.h
*
* Created on: 2012-10-15
* Author: fasiondog
*/
#ifndef INDICATOR_H_
#define INDICATOR_H_
#include "IndicatorImp.h"
namespace hku {
#define IND_EQ_THRESHOLD 0.000001 ///<判断浮点数相等的阈值,两者差值小于此数
2015-01-07 01:26:14 +08:00
/**
* IndicatorImp实现IndicatorImp
* @details IndicatorImp类:
* <pre>
* class Ma: public IndicatorImp {
* public:
* MA(size_t);
* MA(const Indicator&, size_t);
*
* virtual string name() { return "MA"; }
* virtual string toString() { retun "Indicator(MA)"; }
* };
*
* Indicator HKU_API MA(size_t n = 30) {
* return Indicator(IndicatorImpPtr(new MA(n)));
* }
*
2016-04-03 00:08:31 +08:00
* Indicator HKU_API MA(const Indicator& indicator, size_t n = 30);
2015-01-07 01:26:14 +08:00
* </pre>
* @ingroup Indicator
*/
class HKU_API Indicator {
HKU_API friend std::ostream & operator<<(std::ostream &, const Indicator&);
public:
Indicator() {}
Indicator(const IndicatorImpPtr& imp);
Indicator(const Indicator&);
virtual ~Indicator();
Indicator& operator=(const Indicator&);
/** 使用已有参数计算新值返回全新的Indicator */
2016-04-03 00:08:31 +08:00
Indicator operator()(const Indicator& ind);
2015-01-07 01:26:14 +08:00
2019-03-17 23:07:30 +08:00
Indicator operator+(const Indicator&);
Indicator operator-(const Indicator&);
Indicator operator*(const Indicator&);
Indicator operator/(const Indicator&);
Indicator operator==(const Indicator&);
Indicator operator!=(const Indicator&);
Indicator operator>(const Indicator&);
Indicator operator<(const Indicator&);
Indicator operator>=(const Indicator&);
Indicator operator<=(const Indicator&);
2015-01-07 01:26:14 +08:00
/** 指标名称 */
string name() const;
2016-04-03 00:08:31 +08:00
void name(const string& name);
2015-01-07 01:26:14 +08:00
/** 返回形如Name(param1_val,param2_val,...) */
string long_name() const;
2019-03-15 23:35:09 +08:00
void setContext(const Stock&, const KQuery&);
2019-03-14 01:53:13 +08:00
string formula() const;
2015-01-07 01:26:14 +08:00
/** 结果中需抛弃的个数 */
size_t discard() const;
2016-04-03 00:08:31 +08:00
/** 设置抛弃的个数如果小于原有的discard则无效 */
void setDiscard(size_t discard);
2015-01-07 01:26:14 +08:00
/** 返回有几个结果集输出 */
size_t getResultNumber() const;
/** 判断是否为空 **/
bool empty() const;
/** 获取大小 **/
size_t size() const;
/**
* get(pos, 0)
* @note
*/
price_t operator[](size_t pos) const {
return m_imp->get(pos, 0);
}
/**
* num个结果集中指定位置的数据
* @param pos
* @param num
* @note
*/
price_t get(size_t pos, size_t num = 0) const {
return m_imp->get(pos, num);
}
Indicator getResult(size_t num) const {
return m_imp->getResult(num);
}
PriceList getResultAsPriceList(size_t num) const {
return m_imp->getResultAsPriceList(num);
}
2016-04-03 00:08:31 +08:00
template <typename ValueType>
void setParam(const string& name, const ValueType& value) {
if (m_imp) {
m_imp->setParam<ValueType>(name, value);
}
}
template <typename ValueType>
ValueType getParam(const string& name) const {
if (!m_imp) {
throw std::out_of_range("out_of_range in Parameter::get : " + name);
}
return m_imp->getParam<ValueType>(name);
}
2019-03-10 19:16:03 +08:00
IndicatorImpPtr getImp() const { return m_imp; }
2015-01-07 01:26:14 +08:00
protected:
IndicatorImpPtr m_imp;
#if HKU_SUPPORT_SERIALIZATION
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & BOOST_SERIALIZATION_NVP(m_imp);
}
#endif /* HKU_SUPPORT_SERIALIZATION */
};
2019-03-11 01:44:21 +08:00
2015-01-07 01:26:14 +08:00
/**
* Indicator实例相加size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* @ingroup Indicator
*/
2019-03-17 23:07:30 +08:00
//HKU_API Indicator operator+(const Indicator&, const Indicator&);
//HKU_API Indicator operator+(const Indicator&, price_t);
//HKU_API Indicator operator+(price_t, const Indicator&);
2015-01-07 01:26:14 +08:00
/**
* Indicator实例相减size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* @ingroup Indicator
*/
2019-03-17 23:07:30 +08:00
//HKU_API Indicator operator-(const Indicator&, const Indicator&);
//HKU_API Indicator operator-(const Indicator&, price_t);
//HKU_API Indicator operator-(price_t, const Indicator&);
2015-01-07 01:26:14 +08:00
2019-03-17 23:07:30 +08:00
#if 0
2015-01-07 01:26:14 +08:00
/**
* Indicator实例相乘size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* @ingroup Indicator
*/
HKU_API Indicator operator*(const Indicator&, const Indicator&);
HKU_API Indicator operator*(const Indicator&, price_t);
HKU_API Indicator operator*(price_t, const Indicator&);
2015-01-07 01:26:14 +08:00
/**
* Indicator实例相除size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 3Null<price_t>()
* @ingroup Indicator
*/
HKU_API Indicator operator/(const Indicator&, const Indicator&);
HKU_API Indicator operator/(const Indicator&, price_t);
HKU_API Indicator operator/(price_t, const Indicator&);
2015-01-07 01:26:14 +08:00
/**
* Indicator实例相等size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 31.0, 0.0
* @ingroup Indicator
*/
HKU_API Indicator operator==(const Indicator&, const Indicator&);
HKU_API Indicator operator==(const Indicator&, price_t);
HKU_API Indicator operator==(price_t, const Indicator&);
/**
* Indicator实例不相等size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 31.00.0
* @ingroup Indicator
*/
HKU_API Indicator operator!=(const Indicator&, const Indicator&);
HKU_API Indicator operator!=(const Indicator&, price_t);
HKU_API Indicator operator!=(price_t, const Indicator&);
/**
* Indicator实例大于操作size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 3ind1相同位置的值大于ind2相同位置的值则为1.00.0
* @ingroup Indicator
*/
HKU_API Indicator operator>(const Indicator&, const Indicator&);
HKU_API Indicator operator>(const Indicator&, price_t);
HKU_API Indicator operator>(price_t, const Indicator&);
/**
* Indicator实例小于操作size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 3ind1相同位置的值小于ind2相同位置的值则为1.00.0
* @ingroup Indicator
*/
HKU_API Indicator operator<(const Indicator&, const Indicator&);
HKU_API Indicator operator<(const Indicator&, price_t);
HKU_API Indicator operator<(price_t, const Indicator&);
/**
* Indicator实例大于操作size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 3ind1相同位置的值大于等于ind2相同位置的值则为1.00.0
* @ingroup Indicator
*/
HKU_API Indicator operator>=(const Indicator&, const Indicator&);
HKU_API Indicator operator>=(const Indicator&, price_t);
HKU_API Indicator operator>=(price_t, const Indicator&);
/**
* Indicator实例小于操作size必须相等
* @return 1) size必须相等
* 2resultNumber不等resultNumber
* 3ind1相同位置的值小于等于ind2相同位置的值则为1.00.0
* @ingroup Indicator
*/
HKU_API Indicator operator<=(const Indicator&, const Indicator&);
HKU_API Indicator operator<=(const Indicator&, price_t);
HKU_API Indicator operator<=(price_t, const Indicator&);
2019-03-10 19:16:03 +08:00
#endif
2015-01-07 01:26:14 +08:00
} /* namespace hku */
#endif /* INDICATOR_H_ */