hikyuu2/hikyuu_pywrap/trade_sys/_Signal.cpp
2024-05-18 12:37:38 +08:00

228 lines
7.9 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 <hikyuu/trade_sys/signal/build_in.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PySignalBase : public SignalBase {
PY_CLONE(PySignalBase, SignalBase)
public:
using SignalBase::SignalBase;
PySignalBase(const SignalBase& base) : SignalBase(base) {}
void _calculate(const KData& kdata) override {
PYBIND11_OVERLOAD_PURE(void, SignalBase, _calculate, kdata);
}
void _reset() override {
PYBIND11_OVERLOAD(void, SignalBase, _reset, );
}
};
void export_Signal(py::module& m) {
py::class_<SignalBase, SGPtr, PySignalBase>(m, "SignalBase", py::dynamic_attr(),
R"(信号指示器基类
- alternate (bool|True) 线线
- _calculate :
- _clone :
- _reset : )")
.def(py::init<>())
.def(py::init<const string&>())
.def(py::init<const SignalBase&>())
.def("__str__", to_py_str<SignalBase>)
.def("__repr__", to_py_str<SignalBase>)
.def_property("name", py::overload_cast<>(&SignalBase::name, py::const_),
py::overload_cast<const string&>(&SignalBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &SignalBase::getTO, &SignalBase::setTO, py::return_value_policy::copy,
"设置或获取交易对象")
.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<boost::any>, 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("next_time_should_buy", &SignalBase::nextTimeShouldBuy,
R"(next_time_should_byu(self)
)")
.def("next_time_should_sell", &SignalBase::nextTimeShouldSell, R"(next_time_should_sell(self)
)")
.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", &SignalBase::_calculate, R"(_calculate(self, kdata)
)")
.def("_reset", &SignalBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
DEF_PICKLE(SGPtr);
m.def("SG_Bool", SG_Bool, py::arg("buy"), py::arg("sell"),
R"(SG_Bool(buy, sell)
使bool数组的Indicator分别作为买入
:param Indicator buy: Indicator中相应位置>0
:param Indicator sell: Indicator中相应位置>0
:return: )");
m.def("SG_Single", SG_Single, py::arg("ind"), py::arg("filter_n") = 10,
py::arg("filter_p") = 0.1,
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1])
线使 [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:
:return: )");
m.def("SG_Single2", SG_Single2, py::arg("ind"), py::arg("filter_n") = 10,
py::arg("filter_p") = 0.1,
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1])
线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:
:return: )");
m.def("SG_Cross", SG_Cross, py::arg("fast"), py::arg("slow"),
R"(SG_Cross(fast, slow)
线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
SG_Cross(MA(C, n=10), MA(C, n=30))
:param Indicator fast: 线
:param Indicator slow: 线
:return: )");
m.def("SG_CrossGold", SG_CrossGold, py::arg("fast"), py::arg("slow"),
R"(SG_CrossGold(fast, slow)
线穿线线线
线穿线线线::
SG_CrossGold(MA(C, n=10), MA(C, n=30))
:param Indicator fast: 线
:param Indicator slow: 线
:return: )");
m.def("SG_Flex", SG_Flex, py::arg("op"), py::arg("slow_n"),
R"(SG_Flex(ind, slow_n)
使EMA(slow_n)线线线穿线线穿线
:param Indicator ind:
:param int slow_n: 线EMA周期
:return: )");
m.def("SG_Band",
py::overload_cast<const Indicator&, const Indicator&, const Indicator&>(SG_Band),
py::arg("ind"), py::arg("lower"), py::arg("upper"));
m.def("SG_Band", py::overload_cast<const Indicator&, price_t, price_t>(SG_Band), py::arg("ind"),
py::arg("lower"), py::arg("upper"),
R"(SG_Band(ind, lower, upper)
,
::
SG_Band(MA(C, n=10), 100, 200)
SG_Band(CLOSE, MA(LOW), MA(HIGH)))");
m.def("SG_AllwaysBuy", SG_AllwaysBuy, R"(SG_AllwaysBuy()
SG PF 使)");
m.def("SG_Cycle", SG_Cycle, R"(SG_Cycle()
SGPF使用 PF )");
}