mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
update
This commit is contained in:
parent
dfc01243a3
commit
1bbe573ce4
@ -7,7 +7,6 @@
|
||||
#include <stdexcept>
|
||||
#include "Indicator.h"
|
||||
#include "../Log.h"
|
||||
#include "crt/PRICELIST.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
|
@ -26,5 +26,6 @@
|
||||
#include "crt/REF.h"
|
||||
#include "crt/HHV.h"
|
||||
#include "crt/LLV.h"
|
||||
#include "crt/WEAVE.h"
|
||||
|
||||
#endif /* INDICATOR_BUILD_IN_H_ */
|
||||
|
@ -26,6 +26,10 @@ namespace hku {
|
||||
*/
|
||||
Indicator HKU_API VIGOR(const KData& kdata, int n = 2);
|
||||
|
||||
Indicator HKU_API VIGOR(const Indicator& ind, int n = 2);
|
||||
|
||||
Indicator HKU_API VIGOR(int n = 2);
|
||||
|
||||
} /* namespace */
|
||||
|
||||
#endif /* VIGOR_H_ */
|
||||
|
29
libs/hikyuu/indicator/crt/WEAVE.h
Normal file
29
libs/hikyuu/indicator/crt/WEAVE.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* SMA.h
|
||||
*
|
||||
* Created on: 2017年4月19日
|
||||
* Author: fasiondog
|
||||
*/
|
||||
|
||||
#ifndef INDICATOR_CRT_WEAVE_H_
|
||||
#define INDICATOR_CRT_WEAVE_H_
|
||||
|
||||
#include "../Indicator.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
/**
|
||||
* 将ind的结果组合在一起放在一个Indicator中。如ind = WEAVE(ind1); ind=ind(ind2)。
|
||||
* 则此时ind包含两个结果,result1为ind1的数据,result2为ind2的数据
|
||||
* @param data 待计算的数据
|
||||
* @ingroup Indicator
|
||||
*/
|
||||
Indicator HKU_API WEAVE(const Indicator& ind);
|
||||
|
||||
Indicator HKU_API WEAVE();
|
||||
|
||||
} /* namespace */
|
||||
|
||||
|
||||
|
||||
#endif /* INDICATOR_CRT_WEAVE_H_ */
|
@ -82,7 +82,7 @@ void Ama::_calculate(const Indicator& data) {
|
||||
|
||||
|
||||
Indicator HKU_API AMA(int n, int fast_n, int slow_n) {
|
||||
IndicatorImpPtr p(new Ama());
|
||||
IndicatorImpPtr p = make_shared<Ama>();
|
||||
p->setParam<int>("n", n);
|
||||
p->setParam<int>("fast_n", fast_n);
|
||||
p->setParam<int>("slow_n", slow_n);
|
||||
@ -91,7 +91,7 @@ Indicator HKU_API AMA(int n, int fast_n, int slow_n) {
|
||||
|
||||
Indicator HKU_API AMA(const Indicator& indicator,
|
||||
int n, int fast_n, int slow_n) {
|
||||
IndicatorImpPtr p(new Ama());
|
||||
IndicatorImpPtr p = make_shared<Ama>();
|
||||
p->setParam<int>("n", n);
|
||||
p->setParam<int>("fast_n", fast_n);
|
||||
p->setParam<int>("slow_n", slow_n);
|
||||
|
@ -48,13 +48,13 @@ void Atr::_calculate(const Indicator& indicator) {
|
||||
}
|
||||
|
||||
Indicator HKU_API ATR(int n) {
|
||||
IndicatorImpPtr p(new Atr());
|
||||
IndicatorImpPtr p = make_shared<Atr>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API ATR(const Indicator& data, int n) {
|
||||
IndicatorImpPtr p(new Atr());
|
||||
IndicatorImpPtr p = make_shared<Atr>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(data);
|
||||
return Indicator(p);
|
||||
|
@ -40,7 +40,7 @@ Indicator HKU_API DIFF() {
|
||||
}
|
||||
|
||||
Indicator HKU_API DIFF(const Indicator& data) {
|
||||
IndicatorImpPtr p(new Diff());
|
||||
IndicatorImpPtr p = make_shared<Diff>();
|
||||
p->calculate(data);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
@ -50,13 +50,13 @@ void Ema::_calculate(const Indicator& indicator) {
|
||||
|
||||
|
||||
Indicator HKU_API EMA(int n) {
|
||||
IndicatorImpPtr p(new Ema());
|
||||
IndicatorImpPtr p = make_shared<Ema>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API EMA(const Indicator& data, int n) {
|
||||
IndicatorImpPtr p(new Ema());
|
||||
IndicatorImpPtr p = make_shared<Ema>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(data);
|
||||
return Indicator(p);
|
||||
|
@ -57,13 +57,13 @@ void HighLine::_calculate(const Indicator& data) {
|
||||
|
||||
|
||||
Indicator HKU_API HHV(int n =20) {
|
||||
IndicatorImpPtr p(new HighLine);
|
||||
IndicatorImpPtr p = make_shared<HighLine>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API HHV(const Indicator& ind, int n =20) {
|
||||
IndicatorImpPtr p(new HighLine);
|
||||
IndicatorImpPtr p = make_shared<HighLine>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(ind);
|
||||
return Indicator(p);
|
||||
|
@ -6,7 +6,6 @@
|
||||
*/
|
||||
|
||||
#include "IKData.h"
|
||||
#include "../crt/PRICELIST.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
namespace hku {
|
||||
|
@ -93,7 +93,7 @@ Indicator HKU_API PRICELIST(const PriceList& data, int discard) {
|
||||
}
|
||||
|
||||
Indicator HKU_API PRICELIST(const Indicator& data, int result_num) {
|
||||
IndicatorImpPtr p(new IPriceList());
|
||||
IndicatorImpPtr p = make_shared<IPriceList>();
|
||||
p->setParam<int>("result_num", result_num);
|
||||
p->calculate(data);
|
||||
return Indicator(p);
|
||||
|
@ -55,13 +55,13 @@ void LowLine::_calculate(const Indicator& data) {
|
||||
}
|
||||
|
||||
Indicator HKU_API LLV(int n =20) {
|
||||
IndicatorImpPtr p(new LowLine);
|
||||
IndicatorImpPtr p = make_shared<LowLine>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API LLV(const Indicator& ind, int n =20) {
|
||||
IndicatorImpPtr p(new LowLine);
|
||||
IndicatorImpPtr p = make_shared<LowLine>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(ind);
|
||||
return Indicator(p);
|
||||
|
@ -69,7 +69,7 @@ void Macd::_calculate(const Indicator& data) {
|
||||
|
||||
|
||||
Indicator HKU_API MACD(int n1, int n2, int n3) {
|
||||
IndicatorImpPtr p(new Macd());
|
||||
IndicatorImpPtr p = make_shared<Macd>();
|
||||
p->setParam<int>("n1", n1);
|
||||
p->setParam<int>("n2", n2);
|
||||
p->setParam<int>("n3", n3);
|
||||
@ -77,7 +77,7 @@ Indicator HKU_API MACD(int n1, int n2, int n3) {
|
||||
}
|
||||
|
||||
Indicator HKU_API MACD(const Indicator& data, int n1, int n2, int n3) {
|
||||
IndicatorImpPtr p(new Macd());
|
||||
IndicatorImpPtr p = make_shared<Macd>();
|
||||
p->setParam<int>("n1", n1);
|
||||
p->setParam<int>("n2", n2);
|
||||
p->setParam<int>("n3", n3);
|
||||
|
@ -39,13 +39,13 @@ void RightShift::_calculate(const Indicator& data) {
|
||||
}
|
||||
|
||||
Indicator HKU_API REF(int n) {
|
||||
IndicatorImpPtr p(new RightShift);
|
||||
IndicatorImpPtr p = make_shared<RightShift>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API REF(const Indicator& ind, int n) {
|
||||
IndicatorImpPtr p(new RightShift);
|
||||
IndicatorImpPtr p = make_shared<RightShift>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(ind);
|
||||
return Indicator(p);
|
||||
|
@ -86,7 +86,7 @@ void SaftyLoss::_calculate(const Indicator& data) {
|
||||
|
||||
|
||||
Indicator HKU_API SAFTYLOSS(int n1, int n2, double p) {
|
||||
IndicatorImpPtr result(new SaftyLoss());
|
||||
IndicatorImpPtr result = make_shared<SaftyLoss>();
|
||||
result->setParam<int>("n1", n1);
|
||||
result->setParam<int>("n2", n2);
|
||||
result->setParam<double>("p", p);
|
||||
@ -95,7 +95,7 @@ Indicator HKU_API SAFTYLOSS(int n1, int n2, double p) {
|
||||
|
||||
|
||||
Indicator HKU_API SAFTYLOSS(const Indicator& data, int n1, int n2, double p) {
|
||||
IndicatorImpPtr result(new SaftyLoss());
|
||||
IndicatorImpPtr result = make_shared<SaftyLoss>();
|
||||
result->setParam<int>("n1", n1);
|
||||
result->setParam<int>("n2", n2);
|
||||
result->setParam<double>("p", p);
|
||||
|
@ -49,13 +49,13 @@ void Sma::_calculate(const Indicator& indicator) {
|
||||
|
||||
|
||||
Indicator HKU_API SMA(int n) {
|
||||
IndicatorImpPtr p(new Sma());
|
||||
IndicatorImpPtr p = make_shared<Sma>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API SMA(const Indicator& indicator, int n){
|
||||
IndicatorImpPtr p(new Sma());
|
||||
IndicatorImpPtr p = make_shared<Sma>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(indicator);
|
||||
return Indicator(p);
|
||||
|
@ -49,13 +49,13 @@ void StdDeviation::_calculate(const Indicator& data) {
|
||||
|
||||
|
||||
Indicator HKU_API STDEV(int n) {
|
||||
IndicatorImpPtr p(new StdDeviation());
|
||||
IndicatorImpPtr p = make_shared<StdDeviation>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API STDEV(const Indicator& data, int n) {
|
||||
IndicatorImpPtr p(new StdDeviation());
|
||||
IndicatorImpPtr p = make_shared<StdDeviation>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(data);
|
||||
return Indicator(p);
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
namespace hku {
|
||||
|
||||
Vigor::Vigor(): IndicatorImp("VIGOR") {
|
||||
Vigor::Vigor(): IndicatorImp("VIGOR", 1) {
|
||||
setParam<int>("n", 2);
|
||||
}
|
||||
|
||||
@ -48,9 +48,62 @@ Vigor::~Vigor() {
|
||||
|
||||
}
|
||||
|
||||
bool Vigor::check() {
|
||||
int n = getParam<int>("n");
|
||||
if (n < 1) {
|
||||
HKU_ERROR("Invalide param[n] must >= 1 ! [Vigor::Vigor]");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Vigor::_calculate(const Indicator& ind) {
|
||||
if (ind.getResultNumber() < 6) {
|
||||
HKU_ERROR("ind's result_num must > 6! [Vigor::_calculate]");
|
||||
return;
|
||||
}
|
||||
|
||||
size_t total = ind.size();
|
||||
if (0 == total) {
|
||||
return;
|
||||
}
|
||||
|
||||
int n = getParam<int>("n");
|
||||
|
||||
m_discard = 1 + ind.discard();
|
||||
if (0 == total) {
|
||||
return;
|
||||
}
|
||||
|
||||
PriceList tmp(total, Null<price_t>());
|
||||
for (size_t i = m_discard; i < total; ++i) {
|
||||
//tmp[i] = (kdata[i].closePrice - kdata[i-1].closePrice) * kdata[i].transCount;
|
||||
tmp[i] = (ind.get(i,3) - ind.get(i-1,3)) * ind.get(i,5);
|
||||
}
|
||||
|
||||
Indicator ema = EMA(PRICELIST(tmp, m_discard), n);
|
||||
for (size_t i = 0; i < total; ++i) {
|
||||
_set(ema[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Indicator HKU_API VIGOR(const KData& data, int n) {
|
||||
return Indicator(IndicatorImpPtr(new Vigor(data, n)));
|
||||
}
|
||||
|
||||
Indicator HKU_API VIGOR(int n) {
|
||||
IndicatorImpPtr p = make_shared<Vigor>();
|
||||
p->setParam<int>("n", n);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API VIGOR(const Indicator& indicator, int n){
|
||||
IndicatorImpPtr p = make_shared<Vigor>();
|
||||
p->setParam<int>("n", n);
|
||||
p->calculate(indicator);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -19,6 +19,7 @@ namespace hku {
|
||||
* n: 用于EMA平滑的周期窗口,必须为大于0的整数
|
||||
*/
|
||||
class Vigor: public IndicatorImp {
|
||||
INDICATOR_IMP(Vigor)
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
|
88
libs/hikyuu/indicator/imp/Weave.cpp
Normal file
88
libs/hikyuu/indicator/imp/Weave.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Weave.cpp
|
||||
*
|
||||
* Created on: 2017年4月19日
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#include <hikyuu/indicator/imp/Weave.h>
|
||||
|
||||
namespace hku {
|
||||
|
||||
Weave::Weave(): IndicatorImp("WEAVE") {
|
||||
|
||||
}
|
||||
|
||||
Weave::~Weave() {
|
||||
|
||||
}
|
||||
|
||||
bool Weave::check() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Weave::_calculate(const Indicator& ind) {
|
||||
size_t total = ind.size();
|
||||
if (m_result_num != 0 && total != size()) {
|
||||
HKU_ERROR("ind's size must be equal weave's size! [Weave::_calculate]");
|
||||
return;
|
||||
}
|
||||
|
||||
if (total == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t old_m_result_num = m_result_num;
|
||||
m_result_num = ind.getResultNumber() + m_result_num;
|
||||
if (m_result_num > MAX_RESULT_NUM) {
|
||||
HKU_WARN("Weave only can contains " << MAX_RESULT_NUM <<
|
||||
"reult_num! [Weave::_calculate]");
|
||||
m_result_num = MAX_RESULT_NUM;
|
||||
}
|
||||
|
||||
if (m_discard < ind.discard()) {
|
||||
m_discard = ind.discard();
|
||||
}
|
||||
|
||||
price_t null_price = Null<price_t>();
|
||||
for (size_t i = old_m_result_num; i < m_result_num; ++i) {
|
||||
m_pBuffer[i] = new PriceList(total, null_price);
|
||||
for (size_t j = m_discard; j < total; ++j) {
|
||||
(*m_pBuffer[i])[j] = ind.get(j, i-old_m_result_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IndicatorImpPtr Weave::operator()(const Indicator& ind) {
|
||||
Weave* p = new Weave();
|
||||
p->m_discard = m_discard;
|
||||
p->m_result_num = m_result_num;
|
||||
|
||||
size_t self_size = size();
|
||||
if (m_result_num != 0) {
|
||||
p->_readyBuffer(self_size, m_result_num);
|
||||
if (self_size != 0) {
|
||||
for (size_t i = 0; i < m_result_num; ++i) {
|
||||
for (size_t j = m_discard; j < self_size; ++j) {
|
||||
p->_set(get(j,i), j, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
p->_calculate(ind);
|
||||
return IndicatorImpPtr(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API WEAVE() {
|
||||
IndicatorImpPtr p = make_shared<Weave>();
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
Indicator HKU_API WEAVE(const Indicator& ind) {
|
||||
IndicatorImpPtr p = make_shared<Weave>();
|
||||
p->calculate(ind);
|
||||
return Indicator(p);
|
||||
}
|
||||
|
||||
} /* namespace hku */
|
29
libs/hikyuu/indicator/imp/Weave.h
Normal file
29
libs/hikyuu/indicator/imp/Weave.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Weave.h
|
||||
*
|
||||
* Created on: 2017年4月19日
|
||||
* Author: Administrator
|
||||
*/
|
||||
|
||||
#ifndef INDICATOR_IMP_WEAVE_H_
|
||||
#define INDICATOR_IMP_WEAVE_H_
|
||||
|
||||
#include "../indicator.h"
|
||||
|
||||
namespace hku {
|
||||
|
||||
class Weave: public IndicatorImp {
|
||||
INDICATOR_IMP_NO_PRIVATE_MEMBER_SERIALIZATION
|
||||
|
||||
public:
|
||||
Weave();
|
||||
virtual ~Weave();
|
||||
|
||||
virtual bool check();
|
||||
virtual void _calculate(const Indicator& data);
|
||||
virtual IndicatorImpPtr operator()(const Indicator& ind);
|
||||
};
|
||||
|
||||
} /* namespace hku */
|
||||
|
||||
#endif /* INDICATOR_IMP_WEAVE_H_ */
|
@ -31,6 +31,7 @@ void export_Indicator() {
|
||||
.add_property("name", read_name, write_name)
|
||||
.add_property("long_name", &Indicator::long_name)
|
||||
.add_property("discard", &Indicator::discard)
|
||||
.def("setDiscard", &Indicator::setDiscard)
|
||||
.def("getParam", &Indicator::getParam<boost::any>)
|
||||
.def("setParam", &Indicator::setParam<object>)
|
||||
.def("size", &Indicator::size)
|
||||
|
@ -67,6 +67,10 @@ void export_IndicatorImp() {
|
||||
.def(self_ns::str(self))
|
||||
.add_property("name", read_name, write_name)
|
||||
.add_property("discard", &IndicatorImp::discard)
|
||||
.def("getParameter", &IndicatorImp::getParameter,
|
||||
return_value_policy<copy_const_reference>())
|
||||
.def("getParam", &IndicatorImp::getParam<boost::any>)
|
||||
.def("setParam", &IndicatorImp::setParam<object>)
|
||||
.def("setDiscard", &IndicatorImp::setDiscard)
|
||||
.def("_set", &IndicatorImp::_set, _set_overloads())
|
||||
.def("_readyBuffer", &IndicatorImp::_readyBuffer)
|
||||
|
@ -89,6 +89,13 @@ Indicator (*HHV_2)(const Indicator&, int) = HHV;
|
||||
Indicator (*LLV_1)(int) = LLV;
|
||||
Indicator (*LLV_2)(const Indicator&, int) = LLV;
|
||||
|
||||
Indicator (*VIGOR_1)(const KData&, int) = VIGOR;
|
||||
Indicator (*VIGOR_2)(int) = VIGOR;
|
||||
Indicator (*VIGOR_3)(const Indicator&, int) = VIGOR;
|
||||
|
||||
Indicator (*WEAVE_1)() = WEAVE;
|
||||
Indicator (*WEAVE_2)(const Indicator&) = WEAVE;
|
||||
|
||||
void export_Indicator_build_in() {
|
||||
def("KDATA", KDATA1);
|
||||
def("KDATA", KDATA2);
|
||||
@ -145,7 +152,11 @@ void export_Indicator_build_in() {
|
||||
|
||||
def("MACD", MACD_1, (arg("n1")=12, arg("n2")=26, arg("n3")=9));
|
||||
def("MACD", MACD_2, (arg("data"), arg("n1")=12, arg("n2")=26, arg("n3")=9));
|
||||
def("VIGOR", VIGOR, (arg("kdata"), arg("n")=2));
|
||||
|
||||
def("VIGOR", VIGOR_1, (arg("kdata"), arg("n")=2));
|
||||
def("VIGOR", VIGOR_2, (arg("n")=2));
|
||||
def("VIGOR", VIGOR_3, (arg("ind"), arg("n")=2));
|
||||
|
||||
def("SAFTYLOSS", SAFTYLOSS_1, (arg("n1")=10, arg("n2")=3, arg("p")=2.0));
|
||||
def("SAFTYLOSS", SAFTYLOSS_2, (arg("data"), arg("n1")=10, arg("n2")=3, arg("p")=2.0));
|
||||
def("DIFF", DIFF_1);
|
||||
@ -164,6 +175,9 @@ void export_Indicator_build_in() {
|
||||
|
||||
def("LLV", LLV_1, (arg("n")=20));
|
||||
def("LLV", LLV_2, (arg("data"), arg("n")=20));
|
||||
|
||||
def("WEAVE", WEAVE_1);
|
||||
def("WEAVE", WEAVE_2);
|
||||
}
|
||||
|
||||
|
||||
|
@ -210,7 +210,7 @@ try:
|
||||
def KData_to_np(kdata):
|
||||
"""转化为numpy结构数组"""
|
||||
k_type = np.dtype({'names':['datetime','open', 'high', 'low','close',
|
||||
'amount', 'count'],
|
||||
'amount', 'volume'],
|
||||
'formats':['datetime64[D]','d','d','d','d','d','d']})
|
||||
return np.array([(k.datetime, k.openPrice, k.highPrice,
|
||||
k.lowPrice, k.closePrice, k.transAmount,
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,11 +16,11 @@ from hikyuu.indicator import Indicator, MACD, CLOSE
|
||||
from hikyuu.trade_manage import BUSINESS
|
||||
from hikyuu.trade_sys.system import getSystemPartName
|
||||
|
||||
def create_one_axes_figure(figsize=(10,8)):
|
||||
def create_one_axes_figure(figsize=(10,6)):
|
||||
"""生成一个含有1个坐标轴的figure,并返回坐标轴列表
|
||||
返回:(ax1,ax2)
|
||||
"""
|
||||
rect1 = [0.05, 0.35, 0.9, 0.60]
|
||||
rect1 = [0.05, 0.05, 0.9, 0.90]
|
||||
fg=figure(figsize=figsize)
|
||||
ax1 = fg.add_axes(rect1)
|
||||
return ax1
|
||||
|
Loading…
Reference in New Issue
Block a user