hikyuu2/hikyuu_pywrap/trade_sys/_Signal.cpp
2020-07-15 00:23:48 +08:00

217 lines
7.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* _Signal.cpp
*
* Created on: 2013-3-18
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/signal/build_in.h>
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class SignalWrap : public SignalBase, public wrapper<SignalBase> {
public:
SignalWrap() : SignalBase() {}
SignalWrap(const string& name) : SignalBase(name) {}
void _reset() {
if (override func = this->get_override("_reset")) {
func();
} else {
SignalBase::_reset();
}
}
void default_reset() {
this->SignalBase::_reset();
}
SignalPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate")();
}
};
string (SignalBase::*sg_get_name)() const = &SignalBase::name;
void (SignalBase::*sg_set_name)(const string&) = &SignalBase::name;
void export_Signal() {
class_<SignalWrap, boost::noncopyable>("SignalBase", R"(信号指示器基类
- alternate (bool|True) 线线
- _calculate :
- _clone :
- _reset : )",
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", sg_get_name, sg_set_name, "名称")
.add_property("to", &SignalBase::getTO, &SignalBase::setTO, "设置或获取交易对象")
.def("get_param", &SignalBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &SignalBase::setParam<object>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &SignalBase::haveParam, "是否存在指定参数")
.def("should_buy", &SignalBase::shouldBuy, R"(should_buy(self, datetime)
:param Datetime datetime:
:rtype: bool)")
.def("should_sell", &SignalBase::shouldSell, R"(should_sell(self, datetime)
:param Datetime datetime:
:rtype: bool)")
.def("get_buy_signal", &SignalBase::getBuySignal, R"(get_buy_signal(self)
:rtype: DatetimeList)")
.def("get_sell_signal", &SignalBase::getSellSignal, R"(get_sell_signal(self)
:rtype: DatetimeList)")
.def("_add_buy_signal", &SignalBase::_addBuySignal, R"(_add_buy_signal(self, datetime)
_calculate中调用
:param Datetime datetime: )")
.def("_add_sell_signal", &SignalBase::_addSellSignal, R"(_add_sell_signal(self, datetime)
_calculate中调用
:param Datetime datetime: )")
.def("reset", &SignalBase::reset, "复位操作")
.def("clone", &SignalBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&SignalBase::_calculate), "【重载接口】子类计算接口")
.def("_reset", &SignalBase::_reset, &SignalWrap::default_reset,
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&SignalBase::_clone), "【重载接口】子类克隆接口")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<SignalBase>())
#endif
;
register_ptr_to_python<SignalPtr>();
def("SG_Bool", SG_Bool, (arg("buy"), arg("sell"), arg("kpart") = "CLOSE"),
R"(SG_Bool(buy, sell[, kpart='CLOSE'])
使bool数组的Indicator分别作为买入
:param Indicator buy: Indicator中相应位置>0
:param Indicator sell: Indicator中相应位置>0
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Single", SG_Single,
(arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1, arg("kpart") = "CLOSE"),
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
线使 [BOOK1]_ 线线::
filter = percentage * STDEV((AMA-AMA[1], N)
Buy When AMA - AMA[1] > filter
or Buy When AMA - AMA[2] > filter
or Buy When AMA - AMA[3] > filter
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Single2", SG_Single2,
(arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1, arg("kpart") = "CLOSE"),
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1, kpart='CLOSE'])
线2 [BOOK1]_::
filter = percentage * STDEV((AMA-AMA[1], N)
Buy When AMA - @lowest(AMA,n) > filter
Sell When @highest(AMA, n) - AMA > filter
:param Indicator ind:
:param int filer_n: N日周期
:param float filter_p:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
def("SG_Cross", SG_Cross, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"),
R"(SG_Cross(fast, slow[, kpart = "CLOSE"])
线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
SG_Cross(OP(MA(n=10)), OP(MA(n=30)))
:param Indicator fast: 线
:param Indicator slow: 线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: )");
def("SG_CrossGold", SG_CrossGold, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"),
R"(SG_CrossGold(fast, slow[, kpart = "CLOSE"])
线穿线线线
线穿线线线::
SG_CrossGold(OP(MA(n=10)), OP(MA(n=30)))
:param Indicator fast: 线
:param Indicator slow: 线
:param string kpart: OPEN|HIGH|LOW|CLOSE|AMO|VOL|KDATA
:return: )");
def("SG_Flex", SG_Flex, (arg("op"), arg("slow_n"), arg("kpart") = "CLOSE"),
R"(SG_Flex(ind, slow_n[, kpart = 'CLOSE'])
使EMA(slow_n)线线线穿线线穿线
:param Indicator ind:
:param int slow_n: 线EMA周期
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: )");
}