mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 10:59:43 +08:00
update
This commit is contained in:
parent
529bf2d690
commit
cf2d987c52
@ -53,8 +53,8 @@ Indicator.__ge__ = indicator_ge
|
||||
Indicator.__le__ = indicator_le
|
||||
Indicator.__gt__ = indicator_gt
|
||||
Indicator.__lt__ = indicator_lt
|
||||
Indicator.__and__ = IND_AND
|
||||
Indicator.__or__ = IND_OR
|
||||
Indicator.__and__ = indicator_and
|
||||
Indicator.__or__ = indicator_or
|
||||
|
||||
Indicator.__radd__ = lambda self, other: self.__add__(other)
|
||||
Indicator.__rsub__ = lambda self, other: CVAL(self, other).__sub__(self)
|
||||
@ -71,26 +71,6 @@ Indicator.__rand__ = lambda self, other: CVAL(self, other).__and__(self)
|
||||
Indicator.__ror__ = lambda self, other: CVAL(self, other).__or__(self)
|
||||
|
||||
|
||||
Operand.__radd__ = lambda self, other: self.__add__(other)
|
||||
Operand.__rsub__ = lambda self, other: Operand(CVAL(other)).__sub__(self)
|
||||
Operand.__rmul__ = lambda self, other: self.__mul__(other)
|
||||
Operand.__rdiv__ = lambda self, other: Operand(CVAL(other)).__div__(self)
|
||||
Operand.__rtruediv__ = lambda self, other: Operand(CVAL(other)).__truediv__(self)
|
||||
Operand.__req__ = lambda self, other: self.__eq__(other)
|
||||
Operand.__rne__ = lambda self, other: self.__ne__(other)
|
||||
Operand.__rgt__ = lambda self, other: Operand(CVAL(other)).__gt__(self)
|
||||
Operand.__rlt__ = lambda self, other: Operand(CVAL(other)).__lt__(self)
|
||||
Operand.__rge__ = lambda self, other: Operand(CVAL(other)).__ge__(self)
|
||||
Operand.__rle__ = lambda self, other: Operand(CVAL(other)).__le__(self)
|
||||
|
||||
Operand.__and__ = OP_AND
|
||||
Operand.__or__ = OP_OR
|
||||
Operand.__rand__ = lambda self, other: CVAL(self, other).__and__(self)
|
||||
Operand.__ror__ = lambda self, other: CVAL(self, other).__or__(self)
|
||||
|
||||
OP = Operand
|
||||
|
||||
|
||||
def PRICELIST(data, result_num=0, discard=0):
|
||||
"""
|
||||
将 list、tuple、Indicator 转化为普通的 Indicator
|
||||
|
@ -112,11 +112,11 @@ def draw(stock, query=QueryByIndex(-130), ma_n=22, ma_w='auto', vigor_n=13):
|
||||
up = int(umax / umean)
|
||||
lp = int(lmin / lmean)
|
||||
for i in range(up):
|
||||
CVAL(umean * (i + 1), len(kdata)).plot(axes=ax3, color='r', linestyle='--')
|
||||
CVAL(close, umean * (i + 1)).plot(axes=ax3, color='r', linestyle='--')
|
||||
#ax3.hlines(umean * (i + 1),0,len(kdata),color='r',linestyle='--')
|
||||
|
||||
for i in range(lp):
|
||||
CVAL(lmean * (i + 1), len(kdata)).plot(axes=ax3, color='g', linestyle='--')
|
||||
CVAL(close, lmean * (i + 1)).plot(axes=ax3, color='g', linestyle='--')
|
||||
#ax3.hlines(lmean * (i + 1),0,len(kdata),color='g',linestyle='--')
|
||||
|
||||
ax1.set_xlim((0, len(kdata)))
|
||||
|
@ -35,7 +35,7 @@
|
||||
"""
|
||||
|
||||
from hikyuu import Query, StockManager
|
||||
from hikyuu.indicator import (OP, AMA, STDEV, CVAL, PRICELIST, EMA, CLOSE,
|
||||
from hikyuu.indicator import (AMA, STDEV, CVAL, PRICELIST, EMA, CLOSE,
|
||||
HIGH, LOW, OPEN, KDATA, POS)
|
||||
from hikyuu.trade_sys.signal import SG_Single, SG_Cross, SG_Flex
|
||||
from hikyuu.trade_manage import BUSINESS
|
||||
@ -75,8 +75,8 @@ def draw(stock, query = Query(-130),
|
||||
lama.plot(axes = ax1, color = 'g', legend_on = True)
|
||||
|
||||
if sg_type == 'CROSS':
|
||||
fast_op = OP(AMA(n = n))
|
||||
slow_op = OP(OP(EMA(n = 2*n)), fast_op)
|
||||
fast_op = AMA(n = n)
|
||||
slow_op = EMA(n = 2*n)(fast_op)
|
||||
sg = SG_Cross(fast_op, slow_op)
|
||||
sg.plot(axes = ax1, kdata = kdata)
|
||||
ind = slow_op(KDATA(kdata))
|
||||
@ -149,8 +149,8 @@ def draw2(block, query = Query(-130),
|
||||
lama.plot(axes = ax1, color = 'g', legend_on = True)
|
||||
|
||||
if sg_type == 'CROSS':
|
||||
fast_op = OP(OP(AMA(n = n)))
|
||||
slow_op = OP(OP(EMA(n = 2*n)), fast_op)
|
||||
fast_op = AMA(n = n)
|
||||
slow_op = EMA(n = 2*n)(fast_op)
|
||||
sg = SG_Cross(fast_op, slow_op)
|
||||
sg.plot(axes = ax1, kdata = kdata)
|
||||
ind = slow_op(KDATA(kdata))
|
||||
@ -164,10 +164,10 @@ def draw2(block, query = Query(-130),
|
||||
else:
|
||||
print("sg_type only in ('CORSS', 'SINGLE')")
|
||||
|
||||
a = POS(block, query, SG_Flex(OP(AMA(n = 3)), 6))
|
||||
a = POS(block, query, SG_Flex(AMA(n = 3), 6))
|
||||
a.name = "POS(3)"
|
||||
a.plot(axes=ax2, color='b', marker='.', legend_on=True)
|
||||
a = POS(block, query, SG_Flex(OP(AMA(n = 30)), 60))
|
||||
a = POS(block, query, SG_Flex(AMA(n = 30), 60))
|
||||
a.name = "POS(30)"
|
||||
a.plot(axes=ax2, color='g', marker='.', legend_on=True)
|
||||
|
||||
|
@ -34,7 +34,7 @@
|
||||
"""
|
||||
from hikyuu import Query
|
||||
from hikyuu.util.mylog import escapetime
|
||||
from hikyuu.indicator import Indicator, MA, CLOSE, VOL, OP, CVAL, PRICELIST
|
||||
from hikyuu.indicator import Indicator, MA, CLOSE, VOL, CVAL, PRICELIST
|
||||
from hikyuu.trade_sys.signal import SG_Cross
|
||||
from hikyuu.interactive.drawplot import (create_figure,
|
||||
get_current_draw_engine,
|
||||
@ -62,7 +62,7 @@ def draw(stock, query=Query(-130), ma1_n=5, ma2_n=10, ma3_n=20, ma4_n=60,
|
||||
ma4.plot(axes=ax1, legend_on=True)
|
||||
ma5.plot(axes=ax1, legend_on=True)
|
||||
|
||||
sg = SG_Cross(OP(MA(n=ma1_n, type=ma_type)), OP(MA(n=ma2_n, type=ma_type)))
|
||||
sg = SG_Cross(MA(n=ma1_n, type=ma_type), MA(n=ma2_n, type=ma_type))
|
||||
sg.setTO(kdata)
|
||||
sg.plot(axes=ax1, kdata=kdata)
|
||||
|
||||
|
@ -293,4 +293,21 @@ HKU_API Indicator operator<=(price_t val, const Indicator& ind) {
|
||||
return CVAL(ind, val) <= ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator&(const Indicator& ind, price_t val) {
|
||||
return ind & CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator&(price_t val, const Indicator& ind) {
|
||||
return CVAL(ind, val) & ind;
|
||||
}
|
||||
|
||||
HKU_API Indicator operator|(const Indicator& ind, price_t val) {
|
||||
return ind | CVAL(ind, val);
|
||||
}
|
||||
|
||||
HKU_API Indicator operator|(price_t val, const Indicator& ind) {
|
||||
return CVAL(ind, val) | ind;
|
||||
}
|
||||
|
||||
|
||||
} /* namespace hku */
|
||||
|
@ -178,5 +178,11 @@ HKU_API Indicator operator>=(price_t, const Indicator&);
|
||||
HKU_API Indicator operator<=(const Indicator&, price_t);
|
||||
HKU_API Indicator operator<=(price_t, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator&(const Indicator&, price_t);
|
||||
HKU_API Indicator operator&(price_t, const Indicator&);
|
||||
|
||||
HKU_API Indicator operator|(const Indicator&, price_t);
|
||||
HKU_API Indicator operator|(price_t, const Indicator&);
|
||||
|
||||
} /* namespace hku */
|
||||
#endif /* INDICATOR_H_ */
|
||||
|
@ -15,7 +15,7 @@ using namespace hku;
|
||||
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(get_overloads, get, 1, 2)
|
||||
|
||||
/*Indicator (*indicator_add1)(const Indicator&, const Indicator&) = operator+;
|
||||
Indicator (*indicator_add1)(const Indicator&, const Indicator&) = operator+;
|
||||
Indicator (*indicator_sub1)(const Indicator&, const Indicator&) = operator-;
|
||||
Indicator (*indicator_mul1)(const Indicator&, const Indicator&) = operator*;
|
||||
Indicator (*indicator_div1)(const Indicator&, const Indicator&) = operator/;
|
||||
@ -25,6 +25,8 @@ Indicator (*indicator_gt1)(const Indicator&, const Indicator&) = operator>;
|
||||
Indicator (*indicator_lt1)(const Indicator&, const Indicator&) = operator<;
|
||||
Indicator (*indicator_ge1)(const Indicator&, const Indicator&) = operator>=;
|
||||
Indicator (*indicator_le1)(const Indicator&, const Indicator&) = operator<=;
|
||||
Indicator (*indicator_and1)(const Indicator&, const Indicator&) = operator&;
|
||||
Indicator (*indicator_or1)(const Indicator&, const Indicator&) = operator|;
|
||||
|
||||
Indicator (*indicator_add2)(const Indicator&, price_t) = operator+;
|
||||
Indicator (*indicator_sub2)(const Indicator&, price_t) = operator-;
|
||||
@ -36,7 +38,9 @@ Indicator (*indicator_gt2)(const Indicator&, price_t) = operator>;
|
||||
Indicator (*indicator_lt2)(const Indicator&, price_t) = operator<;
|
||||
Indicator (*indicator_ge2)(const Indicator&, price_t) = operator>=;
|
||||
Indicator (*indicator_le2)(const Indicator&, price_t) = operator<=;
|
||||
*/
|
||||
Indicator (*indicator_and2)(const Indicator&, price_t) = operator&;
|
||||
Indicator (*indicator_or2)(const Indicator&, price_t) = operator|;
|
||||
|
||||
|
||||
string (Indicator::*ind_read_name)() const = &Indicator::name;
|
||||
void (Indicator::*ind_write_name)(const string&) = &Indicator::name;
|
||||
@ -60,22 +64,34 @@ void export_Indicator() {
|
||||
.def("getResultAsPriceList", &Indicator::getResultAsPriceList)
|
||||
.def("__len__", &Indicator::size)
|
||||
.def("__call__", &Indicator::operator())
|
||||
|
||||
/* .def("__add__", &Indicator::operator+)
|
||||
.def("__sub__", &Indicator::operator-)
|
||||
.def("__mul__", &Indicator::operator*)
|
||||
.def("__div__", &Indicator::operator/)
|
||||
.def("__truediv__", &Indicator::operator/)
|
||||
.def("__eq__", &Indicator::operator==)
|
||||
.def("__ne__", &Indicator::operator!=)
|
||||
.def("__gt__", &Indicator::operator>)
|
||||
.def("__lt__", &Indicator::operator<)
|
||||
.def("__ge__", &Indicator::operator>=)
|
||||
.def("__le__", &Indicator::operator<=)*/
|
||||
|
||||
#if HKU_PYTHON_SUPPORT_PICKLE
|
||||
.def_pickle(normal_pickle_suite<Indicator>())
|
||||
#endif
|
||||
;
|
||||
|
||||
def("indicator_add", indicator_add1);
|
||||
def("indicator_sub", indicator_sub1);
|
||||
def("indicator_mul", indicator_mul1);
|
||||
def("indicator_div", indicator_div1);
|
||||
def("indicator_eq", indicator_eq1);
|
||||
def("indicator_ne", indicator_ne1);
|
||||
def("indicator_gt", indicator_gt1);
|
||||
def("indicator_lt", indicator_lt1);
|
||||
def("indicator_ge", indicator_ge1);
|
||||
def("indicator_le", indicator_le1);
|
||||
def("indicator_and", indicator_and1);
|
||||
def("indicator_or", indicator_or1);
|
||||
|
||||
def("indicator_add", indicator_add2);
|
||||
def("indicator_sub", indicator_sub2);
|
||||
def("indicator_mul", indicator_mul2);
|
||||
def("indicator_div", indicator_div2);
|
||||
def("indicator_eq", indicator_eq2);
|
||||
def("indicator_ne", indicator_ne2);
|
||||
def("indicator_gt", indicator_gt2);
|
||||
def("indicator_lt", indicator_lt2);
|
||||
def("indicator_ge", indicator_ge2);
|
||||
def("indicator_le", indicator_le2);
|
||||
def("indicator_and", indicator_and2);
|
||||
def("indicator_or", indicator_or2);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user