diff --git a/docs/source/indicator/indicator.rst b/docs/source/indicator/indicator.rst index f198184e..cda1f3cf 100644 --- a/docs/source/indicator/indicator.rst +++ b/docs/source/indicator/indicator.rst @@ -203,6 +203,24 @@ * result(0): MACD_BAR:MACD直柱,即MACD快线-MACD慢线 * result(1): DIFF: 快线,即(短期EMA-长期EMA) * result(2): DEA: 慢线,即快线的n3周期EMA平滑 + + +.. py:function:: MAX(ind1, ind2) + + 求最大值, MAX(A,B)返回A和B中的较大值。 + + :param Indicator ind1: A + :param Indicator ind2: B + :rtype: Indicator + + +.. py:function:: MIN(ind1, ind2) + + 求最小值, MIN(A,B)返回A和B中的较小值。 + + :param Indicator ind1: A + :param Indicator ind2: B + :rtype: Indicator .. py:function:: NOT([data]) diff --git a/docs/source/release.rst b/docs/source/release.rst index 4f128c9c..f3ba938f 100644 --- a/docs/source/release.rst +++ b/docs/source/release.rst @@ -6,7 +6,7 @@ 1. HikyuuTDX 新增当前财务信息及历史财务信息下载 2. Stock 新增 getFinanceInfo、getHistoryFinanceInfo 支持当前及历史财务信息 -3. 新增 LIUTONGPAN(流通盘)、HSL(换手率)、COUNT、IF、SUM、NOT、EXP、SGN、ABS指标 +3. 新增 LIUTONGPAN(流通盘)、HSL(换手率)、COUNT、IF、SUM、NOT、EXP、SGN、ABS、MAX、MIN指标 4. Kdata添加便捷方法获取OPEN/CLOSE等基本行情数据,如:: k = sm['sh000001'].getKData(Query(-100)) @@ -33,7 +33,7 @@ C = CLOSE() H = HIGH() L = LOW() - MTR =SUM(H-L > ABS(H - REF(C,1) > ABS(REF(C,1) - L)),N); + MTR = SUM(MAX(MAX(H-L,ABS(H-REF(C,1))),ABS(REF(C,1)-L)),N); HD = H-REF(H,1) LD = REF(L,1)-L DMP = SUM(IF(HD>0 & HD>LD, HD, 0), N) diff --git a/hikyuu/indicator/indicator_doc.py b/hikyuu/indicator/indicator_doc.py index c27b99f1..8443768b 100644 --- a/hikyuu/indicator/indicator_doc.py +++ b/hikyuu/indicator/indicator_doc.py @@ -261,6 +261,28 @@ MACD([data, n1=12, n2=26, n3=9]) """ +MAX.__doc__ = """ +MAX(ind1, ind2) + + 求最大值, MAX(A,B)返回A和B中的较大值。 + + :param Indicator ind1: A + :param Indicator ind2: B + :rtype: Indicator +""" + + +MIN.__doc__ = """ +MIN(ind1, ind2) + + 求最小值, MIN(A,B)返回A和B中的较小值。 + + :param Indicator ind1: A + :param Indicator ind2: B + :rtype: Indicator +""" + + NOT.__doc__ = """ NOT([data]) diff --git a/hikyuu_cpp/hikyuu/indicator/build_in.h b/hikyuu_cpp/hikyuu/indicator/build_in.h index c34dd1e1..74f1fef2 100644 --- a/hikyuu_cpp/hikyuu/indicator/build_in.h +++ b/hikyuu_cpp/hikyuu/indicator/build_in.h @@ -24,6 +24,8 @@ #include "crt/LIUTONGPAN.h" #include "crt/MA.h" #include "crt/MACD.h" +#include "crt/MAX.h" +#include "crt/MIN.h" #include "crt/NOT.h" #include "crt/POS.h" #include "crt/PRICELIST.h" diff --git a/hikyuu_cpp/hikyuu/indicator/crt/MAX.h b/hikyuu_cpp/hikyuu/indicator/crt/MAX.h new file mode 100644 index 00000000..cb50fcbb --- /dev/null +++ b/hikyuu_cpp/hikyuu/indicator/crt/MAX.h @@ -0,0 +1,40 @@ +/* + * MAX.h + * + * Created on: 2019年4月8日 + * Author: fasiondog + */ + +#ifndef INDICATOR_CRT_MAX_H_ +#define INDICATOR_CRT_MAX_H_ + +#include "CVAL.h" + +namespace hku { + +Indicator MAX(const Indicator&, const Indicator&); +Indicator MAX(const Indicator&, price_t val); +Indicator MAX(price_t val, const Indicator& ind); + +inline Indicator MAX(const Indicator& ind1, const Indicator& ind2) { + Indicator result = IF(ind1 > ind2, ind1, ind2); + result.name("MAX"); + return result; +} + +inline Indicator MAX(const Indicator& ind, price_t val) { + Indicator result = IF(ind > val, ind, val); + result.name("MAX"); + return result; +} + +inline Indicator MAX(price_t val, const Indicator& ind) { + Indicator result = IF(val > ind, val, ind); + result.name("MAX"); + return result; +} + +} + + +#endif /* INDICATOR_CRT_MAX_H_ */ diff --git a/hikyuu_cpp/hikyuu/indicator/crt/MIN.h b/hikyuu_cpp/hikyuu/indicator/crt/MIN.h new file mode 100644 index 00000000..a45095b4 --- /dev/null +++ b/hikyuu_cpp/hikyuu/indicator/crt/MIN.h @@ -0,0 +1,40 @@ +/* + * MIN.h + * + * Created on: 2019年4月8日 + * Author: fasiondog + */ + +#ifndef INDICATOR_CRT_MIN_H_ +#define INDICATOR_CRT_MIN_H_ + +#include "CVAL.h" + +namespace hku { + +Indicator MIN(const Indicator&, const Indicator&); +Indicator MIN(const Indicator&, price_t val); +Indicator MIN(price_t val, const Indicator& ind); + +inline Indicator MIN(const Indicator& ind1, const Indicator& ind2) { + Indicator result = IF(ind1 < ind2, ind1, ind2); + result.name("MIN"); + return result; +} + +inline Indicator MIN(const Indicator& ind, price_t val) { + Indicator result = IF(ind < val, ind, val); + result.name("MIN"); + return result; +} + +inline Indicator MIN(price_t val, const Indicator& ind) { + Indicator result = IF(val < ind, val, ind); + result.name("MIN"); + return result; +} + +} + + +#endif /* INDICATOR_CRT_MIN_H_ */ diff --git a/hikyuu_pywrap/indicator/_build_in.cpp b/hikyuu_pywrap/indicator/_build_in.cpp index f11cd8a0..fdc900fd 100644 --- a/hikyuu_pywrap/indicator/_build_in.cpp +++ b/hikyuu_pywrap/indicator/_build_in.cpp @@ -117,6 +117,13 @@ Indicator (*SGN_2)(const Indicator&) = SGN; Indicator (*EXP_1)() = EXP; Indicator (*EXP_2)(const Indicator&) = EXP; +Indicator (*MAX_1)(const Indicator&, const Indicator&) = MAX; +Indicator (*MAX_2)(const Indicator&, price_t) = MAX; +Indicator (*MAX_3)(price_t, const Indicator&) = MAX; + +Indicator (*MIN_1)(const Indicator&, const Indicator&) = MIN; +Indicator (*MIN_2)(const Indicator&, price_t) = MIN; +Indicator (*MIN_3)(price_t, const Indicator&) = MIN; void export_Indicator_build_in() { def("KDATA", KDATA1); @@ -217,6 +224,14 @@ void export_Indicator_build_in() { def("EXP", EXP_1); def("EXP", EXP_2); + + def("MAX", MAX_1); + def("MAX", MAX_2); + def("MAX", MAX_3); + + def("MIN", MIN_1); + def("MIN", MIN_2); + def("MIN", MIN_3); }