hikyuu2/libs/hikyuu_python/trade_sys/_Signal.cpp

87 lines
2.9 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Signal.cpp
*
* Created on: 2013-3-18
* Author: fasiondog
*/
#include <boost/python.hpp>
2016-04-11 01:27:04 +08:00
#include <hikyuu/trade_sys/signal/build_in.h>
2016-04-03 00:08:31 +08:00
#include "../_Parameter.h"
2015-01-07 01:26:14 +08:00
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class SignalWrap : public SignalBase, public wrapper<SignalBase> {
public:
2016-04-03 00:08:31 +08:00
SignalWrap(): SignalBase() {}
SignalWrap(const string& name) : SignalBase(name) {}
2015-01-07 01:26:14 +08:00
void _reset() {
2016-04-03 00:08:31 +08:00
if (override func = this->get_override("_reset")) {
func();
} else {
SignalBase::_reset();
}
}
void default_reset() {
this->SignalBase::_reset();
2015-01-07 01:26:14 +08:00
}
SignalPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
2016-04-03 00:08:31 +08:00
this->get_override("_calculate")();
2015-01-07 01:26:14 +08:00
}
};
2016-04-03 00:08:31 +08:00
string (SignalBase::*get_name)() const = &SignalBase::name;
void (SignalBase::*set_name)(const string&) = &SignalBase::name;
2015-01-07 01:26:14 +08:00
void export_Signal() {
2016-04-03 00:08:31 +08:00
class_<SignalWrap, boost::noncopyable>("SignalBase", init<>())
.def(init<const string&>())
2015-01-07 01:26:14 +08:00
.def(self_ns::str(self))
2016-04-03 00:08:31 +08:00
.add_property("name", get_name, set_name)
//因为Indicator无法使用params['name']的形式所以统一使用setParm/getParam
//.add_property("params",
// make_function(&SignalBase::getParameter,
// return_internal_reference<>()))
.def("getParam", &SignalBase::getParam<boost::any>)
.def("setParam", &SignalBase::setParam<object>)
2015-01-07 01:26:14 +08:00
.def("setTO", &SignalBase::setTO)
2016-04-03 00:08:31 +08:00
.def("getTO", &SignalBase::getTO)
2015-01-07 01:26:14 +08:00
.def("shouldBuy", &SignalBase::shouldBuy)
.def("shouldSell", &SignalBase::shouldSell)
.def("getBuySignal", &SignalBase::getBuySignal)
.def("getSellSignal", &SignalBase::getSellSignal)
.def("_addBuySignal", &SignalBase::_addBuySignal)
.def("_addSellSignal", &SignalBase::_addSellSignal)
.def("reset", &SignalBase::reset)
.def("clone", &SignalBase::clone)
.def("_calculate", pure_virtual(&SignalBase::_calculate))
2016-04-03 00:08:31 +08:00
.def("_reset", &SignalBase::_reset, &SignalWrap::default_reset)
2015-01-07 01:26:14 +08:00
.def("_clone", pure_virtual(&SignalBase::_clone))
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<SignalBase>())
#endif
;
register_ptr_to_python<SignalPtr>();
2016-04-18 19:54:42 +08:00
def("SG_Single", SG_Single, (arg("ind"), arg("filter_n")=10,
2016-04-03 00:08:31 +08:00
arg("filter_p")=0.1, arg("kpart")="CLOSE"));
2016-04-18 19:54:42 +08:00
def("SG_Single2", SG_Single2, (arg("ind"), arg("filter_n")=10,
arg("filter_p")=0.1, arg("kpart")="CLOSE"));
def("SG_Cross", SG_Cross, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"));
def("SG_CrossGold", SG_CrossGold, (arg("fast"), arg("slow"), arg("kpart") = "CLOSE"));
2016-04-18 19:54:42 +08:00
def("SG_Flex", SG_Flex, (arg("op"), arg("slow_n"), arg("kpart") = "CLOSE"));
2015-01-07 01:26:14 +08:00
}