trade_sys finish

This commit is contained in:
fasiondog 2023-12-27 18:13:05 +08:00
parent 5e3d64ca2e
commit 3da11e708b
13 changed files with 268 additions and 377 deletions

View File

@ -37,7 +37,7 @@ public:
virtual ~OrderBrokerBase(); virtual ~OrderBrokerBase();
/** 获取名称 */ /** 获取名称 */
string name() const; const string& name() const;
/** 设置名称 */ /** 设置名称 */
void name(const string& name); void name(const string& name);
@ -106,7 +106,7 @@ HKU_API std::ostream& operator<<(std::ostream& os, const OrderBrokerBase&);
/** @ingroup OrderBroker */ /** @ingroup OrderBroker */
HKU_API std::ostream& operator<<(std::ostream& os, const OrderBrokerPtr&); HKU_API std::ostream& operator<<(std::ostream& os, const OrderBrokerPtr&);
inline string OrderBrokerBase::name() const { inline const string& OrderBrokerBase::name() const {
return m_name; return m_name;
} }

View File

@ -98,7 +98,7 @@ public:
SignalPtr clone(); SignalPtr clone();
/** 获取名称 */ /** 获取名称 */
string name() const; const string& name() const;
/** 设置名称 */ /** 设置名称 */
void name(const string& name); void name(const string& name);
@ -208,7 +208,7 @@ inline KData SignalBase::getTO() const {
return m_kdata; return m_kdata;
} }
inline string SignalBase::name() const { inline const string& SignalBase::name() const {
return m_name; return m_name;
} }

View File

@ -39,7 +39,7 @@ public:
KData getTO() const; KData getTO() const;
/** 获取名称 */ /** 获取名称 */
string name() const; const string& name() const;
/** 设置名称 */ /** 设置名称 */
void name(const string& name); void name(const string& name);
@ -150,7 +150,7 @@ typedef shared_ptr<SlippageBase> SPPtr;
HKU_API std::ostream& operator<<(std::ostream&, const SlippageBase&); HKU_API std::ostream& operator<<(std::ostream&, const SlippageBase&);
HKU_API std::ostream& operator<<(std::ostream&, const SlippagePtr&); HKU_API std::ostream& operator<<(std::ostream&, const SlippagePtr&);
inline string SlippageBase::name() const { inline const string& SlippageBase::name() const {
return m_name; return m_name;
} }

View File

@ -35,7 +35,7 @@ public:
virtual ~StoplossBase(); virtual ~StoplossBase();
/** 获取名称 */ /** 获取名称 */
string name() const; const string& name() const;
/** 设置名称 */ /** 设置名称 */
void name(const string& name); void name(const string& name);
@ -171,7 +171,7 @@ typedef shared_ptr<StoplossBase> TPPtr;
HKU_API std::ostream& operator<<(std::ostream& os, const StoplossBase&); HKU_API std::ostream& operator<<(std::ostream& os, const StoplossBase&);
HKU_API std::ostream& operator<<(std::ostream& os, const StoplossPtr&); HKU_API std::ostream& operator<<(std::ostream& os, const StoplossPtr&);
inline string StoplossBase::name() const { inline const string& StoplossBase::name() const {
return m_name; return m_name;
} }

View File

@ -42,7 +42,8 @@ void export_OrderBroker(py::module& m) {
.def("__repr__", to_py_str<OrderBrokerBase>) .def("__repr__", to_py_str<OrderBrokerBase>)
.def_property("name", py::overload_cast<void>(&OrderBrokerBase::name, py::const_), .def_property("name", py::overload_cast<void>(&OrderBrokerBase::name, py::const_),
py::overload_cast<const string&>(&OrderBrokerBase::name), "名称(可读写)") py::overload_cast<const string&>(&OrderBrokerBase::name),
py::return_value_policy::copy, "名称(可读写)")
.def("buy", &OrderBrokerBase::buy, R"(buy(self, datetime, market, code, price, num) .def("buy", &OrderBrokerBase::buy, R"(buy(self, datetime, market, code, price, num)

View File

@ -242,9 +242,6 @@ FundsRecord (TradeManagerBase::*getFunds_2)(const Datetime&,
TradeCostPtr (TradeManagerBase::*get_costFunc)() const = &TradeManagerBase::costFunc; TradeCostPtr (TradeManagerBase::*get_costFunc)() const = &TradeManagerBase::costFunc;
void (TradeManagerBase::*set_costFunc)(const TradeCostPtr&) = &TradeManagerBase::costFunc; void (TradeManagerBase::*set_costFunc)(const TradeCostPtr&) = &TradeManagerBase::costFunc;
const string& (TradeManagerBase::*tm_get_name)() const = &TradeManagerBase::name;
void (TradeManagerBase::*tm_set_name)(const string&) = &TradeManagerBase::name;
TradeRecordList (TradeManagerBase::*_getTradeList_1)() const = &TradeManagerBase::getTradeList; TradeRecordList (TradeManagerBase::*_getTradeList_1)() const = &TradeManagerBase::getTradeList;
TradeRecordList (TradeManagerBase::*_getTradeList_2)(const Datetime&, const Datetime&) const = TradeRecordList (TradeManagerBase::*_getTradeList_2)(const Datetime&, const Datetime&) const =
&TradeManagerBase::getTradeList; &TradeManagerBase::getTradeList;
@ -269,9 +266,10 @@ void export_TradeManager(py::module& m) {
.def("__str__", &TradeManagerBase::str) .def("__str__", &TradeManagerBase::str)
.def("__repr__", &TradeManagerBase::str) .def("__repr__", &TradeManagerBase::str)
// .def_property("name", make_function(tm_get_name, .def_property("name", py::overload_cast<>(&TradeManagerBase::name, py::const_),
// return_value_policy<copy_const_reference>()), py::overload_cast<const string&>(&TradeManagerBase::name),
// tm_set_name, "名称") py::return_value_policy::copy, "名称")
.def_property_readonly("init_cash", &TradeManagerBase::initCash, "(只读)初始资金") .def_property_readonly("init_cash", &TradeManagerBase::initCash, "(只读)初始资金")
.def_property_readonly("current_cash", &TradeManagerBase::currentCash, "(只读)当前资金") .def_property_readonly("current_cash", &TradeManagerBase::currentCash, "(只读)当前资金")
.def_property_readonly("init_datetime", &TradeManagerBase::initDatetime, .def_property_readonly("init_datetime", &TradeManagerBase::initDatetime,

View File

@ -5,95 +5,67 @@
* Author: fasiondog * Author: fasiondog
*/ */
#include <boost/python.hpp>
#include <hikyuu/trade_sys/selector/build_in.h> #include <hikyuu/trade_sys/selector/build_in.h>
#include "../_Parameter.h"
#include "../pybind_utils.h" #include "../pybind_utils.h"
#include "../pickle_support.h"
using namespace boost::python; namespace py = pybind11;
using namespace hku; using namespace hku;
class SelectorWrap : public SelectorBase, public wrapper<SelectorBase> { class PySelectorBase : public SelectorBase {
PY_CLONE(PySelectorBase, SelectorBase)
public: public:
SelectorWrap() : SelectorBase() {} using SelectorBase::SelectorBase;
SelectorWrap(const string& name) : SelectorBase(name) {}
virtual ~SelectorWrap() {}
void _reset() { void _reset() override {
if (override func = this->get_override("_reset")) { PYBIND11_OVERLOAD(void, SelectorBase, _reset, );
func();
} else {
SelectorBase::_reset();
}
} }
void default_reset() { void _calculate() override {
this->SelectorBase::_reset(); PYBIND11_OVERLOAD_PURE(void, SelectorBase, _calculate, );
} }
bool isMatchAF(const AFPtr& af) { SystemList getSelectedOnOpen(Datetime date) override {
return this->get_override("is_match_af")(af); PYBIND11_OVERLOAD_PURE_NAME(SystemList, SelectorBase, "get_selected_on_open",
getSelectedOnOpen, date);
} }
SystemList getSelectedOnOpen(Datetime date) { SystemList getSelectedOnClose(Datetime date) override {
return this->get_override("get_selected_on_open")(date); PYBIND11_OVERLOAD_PURE_NAME(SystemList, SelectorBase, "get_selected_on_close",
getSelectedOnClose, date);
} }
SystemList getSelectedOnClose(Datetime date) { bool isMatchAF(const AFPtr& af) override {
return this->get_override("get_selected_on_close")(date); PYBIND11_OVERLOAD_PURE_NAME(bool, SelectorBase, "is_match_af", isMatchAF, af);
}
SelectorPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate")();
} }
}; };
const string& (SelectorBase::*se_get_name)() const = &SelectorBase::name; void export_Selector(py::module& m) {
void (SelectorBase::*se_set_name)(const string&) = &SelectorBase::name; py::class_<SelectorBase, SEPtr, PySelectorBase>(
m, "SelectorBase",
SelectorPtr (*SE_Fixed_1)() = SE_Fixed;
SelectorPtr py_SE_Fixed(py::list stock_list, const SystemPtr& sys) {
return SE_Fixed(python_list_to_vector<StockList>(stock_list), sys);
}
SEPtr (*SE_Signal_1)() = SE_Signal;
SelectorPtr py_SE_Signal(py::list stock_list, const SystemPtr& sys) {
return SE_Signal(python_list_to_vector<StockList>(stock_list), sys);
}
bool py_se_add_stock_list(SelectorBase& se, py::list stock_list, const SystemPtr& protoSys) {
return se.addStockList(python_list_to_vector<StockList>(stock_list), protoSys);
}
void export_Selector() {
class_<SelectorWrap, boost::noncopyable>(
"SelectorBase",
R"(选择器策略基类,实现标的、系统策略的评估和选取算法,自定义选择器策略子类接口: R"(选择器策略基类,实现标的、系统策略的评估和选取算法,自定义选择器策略子类接口:
- get_selected_on_open - - get_selected_on_open -
- get_selected_on_close - - get_selected_on_close -
- _calculate - - _calculate -
- _reset - - _reset -
- _clone - )", - _clone - )")
init<>())
.def(init<const string&>()) .def(py::init<>())
.def(self_ns::str(self)) .def(py::init<const string&>(), R"(初始化构造函数
.def(self_ns::repr(self))
.add_property("name", make_function(se_get_name, return_value_policy<copy_const_reference>()), :param str name: )")
se_set_name, "算法名称")
.add_property("proto_sys_list", .def("__str__", to_py_str<SelectorBase>)
make_function(&SelectorBase::getProtoSystemList, .def("__repr__", to_py_str<SelectorBase>)
return_value_policy<copy_const_reference>()),
"原型系统列表") .def_property("name", py::overload_cast<void>(&SelectorBase::name, py::const_),
.add_property("real_sys_list", py::overload_cast<const string&>(&SelectorBase::name),
make_function(&SelectorBase::getRealSystemList, py::return_value_policy::copy, "算法名称")
return_value_policy<copy_const_reference>()), .def_property_readonly("proto_sys_list", &SelectorBase::getProtoSystemList,
"由 PF 运行时设定的实际运行系统列表") py::return_value_policy::copy, "原型系统列表")
.def_property_readonly("real_sys_list", &SelectorBase::getRealSystemList,
py::return_value_policy::copy, "由 PF 运行时设定的实际运行系统列表")
.def("get_param", &SelectorBase::getParam<boost::any>, R"(get_param(self, name) .def("get_param", &SelectorBase::getParam<boost::any>, R"(get_param(self, name)
@ -103,7 +75,7 @@ void export_Selector() {
:return: :return:
:raises out_of_range: )") :raises out_of_range: )")
.def("set_param", &SelectorBase::setParam<object>, R"(set_param(self, name, value) .def("set_param", &SelectorBase::setParam<boost::any>, R"(set_param(self, name, value)
@ -117,7 +89,7 @@ void export_Selector() {
.def("clone", &SelectorBase::clone, "克隆操作") .def("clone", &SelectorBase::clone, "克隆操作")
.def("remove_all", &SelectorBase::removeAll, "清除所有已加入的原型系统") .def("remove_all", &SelectorBase::removeAll, "清除所有已加入的原型系统")
.def("add_stock", &SelectorBase::addStock, (arg("stock"), arg("sys")), .def("add_stock", &SelectorBase::addStock, py::arg("stock"), py::arg("sys"),
R"(add_stock(self, stock, sys) R"(add_stock(self, stock, sys)
@ -125,7 +97,7 @@ void export_Selector() {
:param Stock stock: :param Stock stock:
:param System sys: )") :param System sys: )")
.def("add_stock_list", py_se_add_stock_list, (arg("stk_list"), arg("sys")), .def("add_stock_list", &SelectorBase::addStockList, py::arg("stk_list"), py::arg("sys"),
R"(add_stock_list(self, stk_list, sys) R"(add_stock_list(self, stk_list, sys)
@ -133,17 +105,16 @@ void export_Selector() {
:param StockList stk_list: :param StockList stk_list:
:param System sys: )") :param System sys: )")
.def("_reset", &SelectorBase::_reset, &SelectorWrap::default_reset, "子类复位操作实现") .def("_reset", &SelectorBase::_reset, "子类复位操作实现")
.def("_clone", pure_virtual(&SelectorBase::_clone), "子类克隆操作实现接口") .def("_calculate", &SelectorBase::_calculate, "【重载接口】子类计算接口")
.def("_calculate", pure_virtual(&SelectorBase::_calculate), "【重载接口】子类计算接口")
.def("is_match_af", pure_virtual(&SelectorBase::isMatchAF), R"(is_match_af(self) .def("is_match_af", &SelectorBase::isMatchAF, R"(is_match_af(self)
AF AF
:param AllocateFundsBase af: )") :param AllocateFundsBase af: )")
.def("get_selected_on_open", pure_virtual(&SelectorBase::getSelectedOnOpen), .def("get_selected_on_open", &SelectorBase::getSelectedOnOpen,
R"(get_selected_on_open(self, datetime) R"(get_selected_on_open(self, datetime)
@ -152,7 +123,7 @@ void export_Selector() {
:return: :return:
:rtype: SystemList)") :rtype: SystemList)")
.def("get_selected_on_close", pure_virtual(&SelectorBase::getSelectedOnClose), .def("get_selected_on_close", &SelectorBase::getSelectedOnClose,
R"(get_selected_on_close(self, datetime) R"(get_selected_on_close(self, datetime)
@ -161,15 +132,11 @@ void export_Selector() {
:return: :return:
:rtype: SystemList)") :rtype: SystemList)")
#if HKU_PYTHON_SUPPORT_PICKLE DEF_PICKLE(SEPtr);
.def_pickle(name_init_pickle_suite<SelectorBase>())
#endif
;
register_ptr_to_python<SelectorPtr>(); m.def("SE_Fixed", py::overload_cast<void>(SE_Fixed));
m.def("SE_Fixed", py::overload_cast<const StockList&, const SystemPtr&>(SE_Fixed),
def("SE_Fixed", SE_Fixed_1); R"(SE_Fixed([stk_list, sys])
def("SE_Fixed", py_SE_Fixed, R"(SE_Fixed([stk_list, sys])
@ -177,8 +144,9 @@ void export_Selector() {
:param System sys: :param System sys:
:return: SE选择器实例)"); :return: SE选择器实例)");
def("SE_Signal", SE_Signal_1); m.def("SE_Signal", py::overload_cast<void>(SE_Signal));
def("SE_Signal", py_SE_Signal, R"(SE_Signal([stk_list, sys]) m.def("SE_Signal", py::overload_cast<const StockList&, const SystemPtr&>(SE_Signal),
R"(SE_Signal([stk_list, sys])

View File

@ -5,45 +5,29 @@
* Author: fasiondog * Author: fasiondog
*/ */
#include <boost/python.hpp>
#include <hikyuu/trade_sys/signal/build_in.h> #include <hikyuu/trade_sys/signal/build_in.h>
#include "../_Parameter.h" #include "../pybind_utils.h"
#include "../pickle_support.h"
using namespace boost::python; namespace py = pybind11;
using namespace hku; using namespace hku;
class SignalWrap : public SignalBase, public wrapper<SignalBase> { class PySignalBase : public SignalBase {
PY_CLONE(PySignalBase, SignalBase)
public: public:
SignalWrap() : SignalBase() {} using SignalBase::SignalBase;
SignalWrap(const string& name) : SignalBase(name) {}
void _reset() { void _calculate() override {
if (override func = this->get_override("_reset")) { PYBIND11_OVERLOAD_PURE(void, SignalBase, _calculate, );
func();
} else {
SignalBase::_reset();
}
} }
void default_reset() { void _reset() override {
this->SignalBase::_reset(); PYBIND11_OVERLOAD(void, SignalBase, _reset, );
}
SignalPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate")();
} }
}; };
string (SignalBase::*sg_get_name)() const = &SignalBase::name; void export_Signal(py::module& m) {
void (SignalBase::*sg_set_name)(const string&) = &SignalBase::name; py::class_<SignalBase, SGPtr, PySignalBase>(m, "SignalBase", R"(信号指示器基类
void export_Signal() {
class_<SignalWrap, boost::noncopyable>("SignalBase", R"(信号指示器基类
@ -54,15 +38,18 @@ void export_Signal() {
- _calculate : - _calculate :
- _clone : - _clone :
- _reset : )", - _reset : )")
init<>())
.def(init<const string&>())
.def(self_ns::str(self)) .def(py::init<>())
.def(self_ns::repr(self)) .def(py::init<const string&>())
.add_property("name", sg_get_name, sg_set_name, "名称") .def("__str__", to_py_str<SignalBase>)
.add_property("to", &SignalBase::getTO, &SignalBase::setTO, "设置或获取交易对象") .def("__repr__", to_py_str<SignalBase>)
.def_property("name", py::overload_cast<void>(&SignalBase::name, py::const_),
py::overload_cast<const string&>(&SignalBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &SignalBase::getTO, &SignalBase::setTO, "设置或获取交易对象")
.def("get_param", &SignalBase::getParam<boost::any>, R"(get_param(self, name) .def("get_param", &SignalBase::getParam<boost::any>, R"(get_param(self, name)
@ -72,7 +59,7 @@ void export_Signal() {
:return: :return:
:raises out_of_range: )") :raises out_of_range: )")
.def("set_param", &SignalBase::setParam<object>, R"(set_param(self, name, value) .def("set_param", &SignalBase::setParam<boost::any>, R"(set_param(self, name, value)
@ -131,20 +118,13 @@ void export_Signal() {
.def("reset", &SignalBase::reset, "复位操作") .def("reset", &SignalBase::reset, "复位操作")
.def("clone", &SignalBase::clone, "克隆操作") .def("clone", &SignalBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&SignalBase::_calculate), "【重载接口】子类计算接口") .def("_calculate", &SignalBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &SignalBase::_reset, &SignalWrap::default_reset, .def("_reset", &SignalBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&SignalBase::_clone), "【重载接口】子类克隆接口")
#if HKU_PYTHON_SUPPORT_PICKLE DEF_PICKLE(SGPtr);
.def_pickle(name_init_pickle_suite<SignalBase>())
#endif
;
register_ptr_to_python<SignalPtr>(); m.def("SG_Bool", SG_Bool, py::arg("buy"), py::arg("sell"),
R"(SG_Bool(buy, sell)
def("SG_Bool", SG_Bool, (arg("buy"), arg("sell")),
R"(SG_Bool(buy, sell)
使bool数组的Indicator分别作为买入 使bool数组的Indicator分别作为买入
@ -152,8 +132,9 @@ void export_Signal() {
:param Indicator sell: Indicator中相应位置>0 :param Indicator sell: Indicator中相应位置>0
:return: )"); :return: )");
def("SG_Single", SG_Single, (arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1), m.def("SG_Single", SG_Single, py::arg("ind"), py::arg("filter_n") = 10,
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1]) py::arg("filter_p") = 0.1,
R"(SG_Single(ind[, filter_n = 10, filter_p = 0.1])
线使 [BOOK1]_ 线线:: 线使 [BOOK1]_ 线线::
@ -168,8 +149,9 @@ void export_Signal() {
:param float filter_p: :param float filter_p:
:return: )"); :return: )");
def("SG_Single2", SG_Single2, (arg("ind"), arg("filter_n") = 10, arg("filter_p") = 0.1), m.def("SG_Single2", SG_Single2, py::arg("ind"), py::arg("filter_n") = 10,
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1]) py::arg("filter_p") = 0.1,
R"(SG_Single2(ind[, filter_n = 10, filter_p = 0.1])
线2 [BOOK1]_:: 线2 [BOOK1]_::
@ -183,8 +165,8 @@ void export_Signal() {
:param float filter_p: :param float filter_p:
:return: )"); :return: )");
def("SG_Cross", SG_Cross, (arg("fast"), arg("slow")), m.def("SG_Cross", SG_Cross, py::arg("fast"), py::arg("slow"),
R"(SG_Cross(fast, slow) R"(SG_Cross(fast, slow)
线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出:: 线线穿线线穿线5MA上穿10日MA时买入5MA线下穿MA10日线时卖出::
@ -194,8 +176,8 @@ void export_Signal() {
:param Indicator slow: 线 :param Indicator slow: 线
:return: )"); :return: )");
def("SG_CrossGold", SG_CrossGold, (arg("fast"), arg("slow")), m.def("SG_CrossGold", SG_CrossGold, py::arg("fast"), py::arg("slow"),
R"(SG_CrossGold(fast, slow) R"(SG_CrossGold(fast, slow)
线穿线线线 线穿线线线
线穿线线线:: 线穿线线线::
@ -206,8 +188,8 @@ void export_Signal() {
:param Indicator slow: 线 :param Indicator slow: 线
:return: )"); :return: )");
def("SG_Flex", SG_Flex, (arg("op"), arg("slow_n")), m.def("SG_Flex", SG_Flex, py::arg("op"), py::arg("slow_n"),
R"(SG_Flex(ind, slow_n) R"(SG_Flex(ind, slow_n)
使EMA(slow_n)线线线穿线线穿线 使EMA(slow_n)线线线穿线线穿线
@ -215,8 +197,8 @@ void export_Signal() {
:param int slow_n: 线EMA周期 :param int slow_n: 线EMA周期
:return: )"); :return: )");
def("SG_Band", SG_Band, (arg("ind"), arg("lower"), arg("upper")), m.def("SG_Band", SG_Band, py::arg("ind"), py::arg("lower"), py::arg("upper"),
R"(SG_Band(ind, lower, upper) R"(SG_Band(ind, lower, upper)
, ,
:: ::

View File

@ -5,55 +5,40 @@
* Author: fasiondog * Author: fasiondog
*/ */
#include <boost/python.hpp>
#include <hikyuu/trade_sys/slippage/SlippageBase.h> #include <hikyuu/trade_sys/slippage/SlippageBase.h>
#include <hikyuu/trade_sys/slippage/build_in.h> #include <hikyuu/trade_sys/slippage/build_in.h>
#include "../_Parameter.h" #include "../pybind_utils.h"
#include "../pickle_support.h"
using namespace boost::python; namespace py = pybind11;
using namespace hku; using namespace hku;
class SlippageWrap : public SlippageBase, public wrapper<SlippageBase> { class PySlippageBase : public SlippageBase {
PY_CLONE(PySlippageBase, SlippageBase)
public: public:
SlippageWrap() : SlippageBase() {} using SlippageBase::SlippageBase;
SlippageWrap(const string& name) : SlippageBase(name) {}
virtual ~SlippageWrap() {}
void _reset() { void _calculate() override {
if (override func = get_override("_reset")) { PYBIND11_OVERLOAD_PURE(void, SlippageBase, _calculate, );
func();
} else {
SlippageBase::_reset();
}
} }
void default_reset() { void _reset() override {
this->SlippageBase::_reset(); PYBIND11_OVERLOAD(void, SlippageBase, _reset, );
} }
SlippagePtr _clone() { price_t getRealBuyPrice(const Datetime& datetime, price_t planPrice) override {
return this->get_override("_clone")(); PYBIND11_OVERLOAD_PURE_NAME(price_t, SlippageBase, "get_real_buy_price", getRealBuyPrice,
datetime, planPrice);
} }
void _calculate() { price_t getRealSellPrice(const Datetime& datetime, price_t planPrice) override {
this->get_override("_calculate"); PYBIND11_OVERLOAD_PURE_NAME(price_t, SlippageBase, "get_real_sell_price", getRealSellPrice,
} datetime, planPrice);
price_t getRealBuyPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_real_buy_price")(datetime, price);
}
price_t getRealSellPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_real_sell_price")(datetime, price);
} }
}; };
string (SlippageBase::*sp_get_name)() const = &SlippageBase::name; void export_Slippage(py::module& m) {
void (SlippageBase::*sp_set_name)(const string&) = &SlippageBase::name; py::class_<SlippageBase, SPPtr, PySlippageBase>(m, "SlippageBase", R"(移滑价差算法基类
void export_Slippage() {
class_<SlippageWrap, boost::noncopyable>("SlippageBase", R"(移滑价差算法基类
@ -61,14 +46,20 @@ void export_Slippage() {
- getRealSellPrice : - getRealSellPrice :
- _calculate : - _calculate :
- _clone : - _clone :
- _reset : )", - _reset : )")
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", sp_get_name, sp_set_name, "名称") .def(py::init<>())
.add_property("to", &SlippageBase::getTO, &SlippageBase::setTO, "设置或获取交易对象") .def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<SlippageBase>)
.def("__repr__", to_py_str<SlippageBase>)
.def_property("name", py::overload_cast<void>(&SlippageBase::name, py::const_),
py::overload_cast<const string&>(&SlippageBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &SlippageBase::getTO, &SlippageBase::setTO, "关联交易对象")
.def("get_param", &SlippageBase::getParam<boost::any>, R"(get_param(self, name) .def("get_param", &SlippageBase::getParam<boost::any>, R"(get_param(self, name)
@ -78,7 +69,7 @@ void export_Slippage() {
:return: :return:
:raises out_of_range: )") :raises out_of_range: )")
.def("set_param", &SlippageBase::setParam<object>, R"(set_param(self, name, value) .def("set_param", &SlippageBase::setParam<boost::any>, R"(set_param(self, name, value)
@ -88,7 +79,7 @@ void export_Slippage() {
.def("have_param", &SlippageBase::haveParam, "是否存在指定参数") .def("have_param", &SlippageBase::haveParam, "是否存在指定参数")
.def("get_real_buy_price", pure_virtual(&SlippageBase::getRealBuyPrice), .def("get_real_buy_price", &SlippageBase::getRealBuyPrice,
R"(get_real_buy_price(self, datetime, price) R"(get_real_buy_price(self, datetime, price)
@ -98,7 +89,7 @@ void export_Slippage() {
:return: :return:
:rtype: float)") :rtype: float)")
.def("get_real_sell_price", pure_virtual(&SlippageBase::getRealSellPrice), .def("get_real_sell_price", &SlippageBase::getRealSellPrice,
R"(get_real_sell_price(self, datetime, price) R"(get_real_sell_price(self, datetime, price)
@ -110,21 +101,20 @@ void export_Slippage() {
.def("reset", &SlippageBase::reset, "复位操作") .def("reset", &SlippageBase::reset, "复位操作")
.def("clone", &SlippageBase::clone, "克隆操作") .def("clone", &SlippageBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&SlippageBase::_calculate), "【重载接口】子类计算接口") .def("_calculate", &SlippageBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &SlippageBase::_reset, &SlippageWrap::default_reset, .def("_reset", &SlippageBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&SlippageBase::_clone), "【重载接口】子类克隆接口");
register_ptr_to_python<SlippagePtr>(); DEF_PICKLE(SPPtr);
def("SP_FixedPercent", SP_FixedPercent, (arg("p") = 0.001), R"(SP_FixedPercent([p=0.001]) m.def("SP_FixedPercent", SP_FixedPercent, py::arg("p") = 0.001,
R"(SP_FixedPercent([p=0.001])
= * (1 + p) = * (1 - p) = * (1 + p) = * (1 - p)
:param float p: :param float p:
:return: )"); :return: )");
def("SP_FixedValue", SP_FixedValue, (arg("value") = 0.01), R"(SP_FixedValuet([p=0.001]) m.def("SP_FixedValue", SP_FixedValue, py::arg("value") = 0.01, R"(SP_FixedValuet([p=0.001])
= + = - = + = -

View File

@ -5,74 +5,57 @@
* Author: fasiondog * Author: fasiondog
*/ */
#include <boost/python.hpp>
#include <hikyuu/trade_sys/stoploss/build_in.h> #include <hikyuu/trade_sys/stoploss/build_in.h>
#include "../_Parameter.h" #include "../pybind_utils.h"
#include "../pickle_support.h"
using namespace boost::python; namespace py = pybind11;
using namespace hku; using namespace hku;
class StoplossWrap : public StoplossBase, public wrapper<StoplossBase> { class PyStoplossBase : public StoplossBase {
PY_CLONE(PyStoplossBase, StoplossBase)
public: public:
StoplossWrap() : StoplossBase() {} using StoplossBase::StoplossBase;
StoplossWrap(const string& name) : StoplossBase(name) {}
virtual ~StoplossWrap() {}
void _reset() { void _calculate() override {
if (override func = this->get_override("_reset")) { PYBIND11_OVERLOAD_PURE(void, StoplossBase, _calculate, );
func();
} else {
StoplossBase::_reset();
}
} }
void default_reset() { void _reset() override {
this->StoplossBase::_reset(); PYBIND11_OVERLOAD(void, StoplossBase, _reset, );
} }
StoplossPtr _clone() { price_t getPrice(const Datetime& datetime, price_t price) override {
return this->get_override("_clone")(); PYBIND11_OVERLOAD_PURE_NAME(price_t, StoplossBase, "get_price", getPrice, datetime, price);
} }
void _calculate() { price_t getShortPrice(const Datetime& datetime, price_t price) override {
this->get_override("_calculate")(); PYBIND11_OVERLOAD_NAME(price_t, StoplossBase, "get_short_price", getShortPrice, datetime,
} price);
price_t getPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_price")(datetime, price);
}
price_t getShortPrice(const Datetime& datetime, price_t price) {
if (override getShortPrice = get_override("get_short_price")) {
return getShortPrice(datetime, price);
}
return StoplossBase::getShortPrice(datetime, price);
}
price_t default_getShortPrice(const Datetime& datetime, price_t price) {
return this->StoplossBase::getShortPrice(datetime, price);
} }
}; };
string (StoplossBase::*st_get_name)() const = &StoplossBase::name; void export_Stoploss(py::module& m) {
void (StoplossBase::*st_set_name)(const string&) = &StoplossBase::name; py::class_<StoplossBase, StoplossPtr, PyStoplossBase>(m, "StoplossBase",
R"(止损/止赢算法基类
void export_Stoploss() {
class_<StoplossWrap, boost::noncopyable>("StoplossBase", R"(止损/止赢算法基类
/ /
- _calculate : - _calculate :
- _clone : - _clone :
- _reset : )", - _reset : )")
init<>()) .def(py::init<>())
.def(init<const string&>()) .def(py::init<const string&>(), R"(初始化构造函数
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", st_get_name, st_set_name, "名称") :param str name: )")
.add_property("to", &StoplossBase::getTO, &StoplossBase::setTO, "设置或获取交易对象")
.add_property("tm", &StoplossBase::getTM, &StoplossBase::setTM, "设置或获取交易管理实例") .def("__str__", to_py_str<StoplossBase>)
.def("__repr__", to_py_str<StoplossBase>)
.def_property("name", py::overload_cast<void>(&StoplossBase::name, py::const_),
py::overload_cast<const string&>(&StoplossBase::name),
py::return_value_policy::copy, "名称")
.def_property("tm", &StoplossBase::getTM, &StoplossBase::setTM, "关联交易管理实例")
.def_property("to", &StoplossBase::getTO, &StoplossBase::setTO, "关联交易对象")
.def("get_param", &StoplossBase::getParam<boost::any>, R"(get_param(self, name) .def("get_param", &StoplossBase::getParam<boost::any>, R"(get_param(self, name)
@ -82,7 +65,7 @@ void export_Stoploss() {
:return: :return:
:raises out_of_range: )") :raises out_of_range: )")
.def("set_param", &StoplossBase::setParam<object>, R"(set_param(self, name, value) .def("set_param", &StoplossBase::setParam<boost::any>, R"(set_param(self, name, value)
@ -92,7 +75,7 @@ void export_Stoploss() {
.def("have_param", &StoplossBase::haveParam, "是否存在指定参数") .def("have_param", &StoplossBase::haveParam, "是否存在指定参数")
.def("get_price", pure_virtual(&StoplossBase::getPrice), R"(get_price(self, datetime, price) .def("get_price", &StoplossBase::getPrice, R"(get_price(self, datetime, price)
0 0
@ -104,31 +87,24 @@ void export_Stoploss() {
:return: :return:
:rtype: float)") :rtype: float)")
//.def("getShortPrice", &StoplossBase::getShortPrice, &StoplossWrap::default_getShortPrice) .def("get_short_price", &StoplossBase::getShortPrice)
.def("reset", &StoplossBase::reset, "复位操作") .def("reset", &StoplossBase::reset, "复位操作")
.def("clone", &StoplossBase::clone, "克隆操作") .def("clone", &StoplossBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&StoplossBase::_calculate), "【重载接口】子类计算接口") .def("_calculate", &StoplossBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &StoplossBase::_reset, &StoplossWrap::default_reset, .def("_reset", &StoplossBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&StoplossBase::_clone), "【重载接口】子类克隆接口")
#if HKU_PYTHON_SUPPORT_PICKLE DEF_PICKLE(StoplossPtr);
.def_pickle(name_init_pickle_suite<StoplossBase>())
#endif
;
register_ptr_to_python<StoplossPtr>(); m.def("ST_FixedPercent", ST_FixedPercent, py::arg("p") = 0.03, R"(ST_FixedPercent([p=0.03])
def("ST_FixedPercent", ST_FixedPercent, (arg("p") = 0.03), R"(ST_FixedPercent([p=0.03])
:param float p: (0,1] :param float p: (0,1]
:return: /)"); :return: /)");
def("ST_Indicator", ST_Indicator, (arg("op"), arg("kpart") = "CLOSE"), m.def("ST_Indicator", ST_Indicator, py::arg("op"), py::arg("kpart") = "CLOSE",
R"(ST_Indicator(op[, kpart="CLOSE"]) R"(ST_Indicator(op[, kpart="CLOSE"])
使使10EMA作为止损:: 使使10EMA作为止损::
@ -138,8 +114,8 @@ void export_Stoploss() {
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL :param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: /)"); :return: /)");
def("ST_Saftyloss", ST_Saftyloss, (arg("n1") = 10, arg("n2") = 3, arg("p") = 2.0), m.def("ST_Saftyloss", ST_Saftyloss, py::arg("n1") = 10, py::arg("n2") = 3, py::arg("p") = 2.0,
R"(ST_Saftyloss([n1=10, n2=3, p=2.0]) R"(ST_Saftyloss([n1=10, n2=3, p=2.0])
2007 .(Alexander Elder) P202 2007 .(Alexander Elder) P202
1020穿穿 1020穿穿

View File

@ -5,36 +5,28 @@
* Author: fasiondog * Author: fasiondog
*/ */
#include <boost/python.hpp>
#include <hikyuu/trade_sys/system/build_in.h> #include <hikyuu/trade_sys/system/build_in.h>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp> #include "../pybind_utils.h"
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python; namespace py = pybind11;
using namespace hku; using namespace hku;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#pragma warning(disable : 4267) #pragma warning(disable : 4267)
#endif #endif
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(run_overload, run, 2, 3);
const string& (System::*sys_get_name)() const = &System::name;
void (System::*sys_set_name)(const string&) = &System::name;
void (System::*run_1)(const KQuery&, bool) = &System::run; void (System::*run_1)(const KQuery&, bool) = &System::run;
void (System::*run_2)(const KData&, bool) = &System::run; void (System::*run_2)(const KData&, bool) = &System::run;
void (System::*run_3)(const Stock&, const KQuery&, bool reset) = &System::run; void (System::*run_3)(const Stock&, const KQuery&, bool reset) = &System::run;
TradeRecord (System::*runMoment_1)(const Datetime&) = &System::runMoment; TradeRecord (System::*runMoment_1)(const Datetime&) = &System::runMoment;
void export_System() { void export_System(py::module& m) {
def( m.def(
"SYS_Simple", SYS_Simple, "SYS_Simple", SYS_Simple, py::arg("tm") = TradeManagerPtr(),
(arg("tm") = TradeManagerPtr(), arg("mm") = MoneyManagerPtr(), arg("ev") = EnvironmentPtr(), py::arg("mm") = MoneyManagerPtr(), py::arg("ev") = EnvironmentPtr(),
arg("cn") = ConditionPtr(), arg("sg") = SignalPtr(), arg("st") = StoplossPtr(), py::arg("cn") = ConditionPtr(), py::arg("sg") = SignalPtr(), py::arg("st") = StoplossPtr(),
arg("tp") = StoplossPtr(), arg("pg") = ProfitGoalPtr(), arg("sp") = SlippagePtr()), py::arg("tp") = StoplossPtr(), py::arg("pg") = ProfitGoalPtr(), py::arg("sp") = SlippagePtr(),
R"(SYS_Simple([tm=None, mm=None, ev=None, cn=None, sg=None, st=None, tp=None, pg=None, sp=None]) R"(SYS_Simple([tm=None, mm=None, ev=None, cn=None, sg=None, st=None, tp=None, pg=None, sp=None])
(run方法 (run方法
@ -65,7 +57,7 @@ void export_System() {
:param SlippageBase sp: :param SlippageBase sp:
:return: system实例)"); :return: system实例)");
def("get_system_part_name", getSystemPartName, R"(get_system_part_name(part) m.def("get_system_part_name", getSystemPartName, R"(get_system_part_name(part)
@ -82,21 +74,22 @@ void export_System() {
:param int part: System.Part :param int part: System.Part
:rtype: str)"); :rtype: str)");
def("get_system_part_enum", getSystemPartEnum, R"(get_system_part_enum(part_name) m.def("get_system_part_enum", getSystemPartEnum, R"(get_system_part_enum(part_name)
:param str part_name: :py:func:`getSystemPartName` :param str part_name: :py:func:`getSystemPartName`
:rtype: System.Part)"); :rtype: System.Part)");
class_<TradeRequest>( py::class_<TradeRequest>(
"TradeRequest", m, "TradeRequest",
R"(交易请求记录。系统内部在实现延迟操作时登记的交易请求信息。暴露该结构的主要目的是用于在“delay”模式延迟到下一个bar开盘时进行交易的情况下系统实际已知下一个Bar将要进行交易此时可通过 :py:meth:`System.getBuyTradeRequest` 、 :py:meth:`System.getSellTradeRequest` 来获知下一个BAR是否需要买入/卖出。主要用于提醒或打印下一个Bar需要进行操作。对于系统本身的运行没有影响。)", R"(交易请求记录。系统内部在实现延迟操作时登记的交易请求信息。暴露该结构的主要目的是用于
init<>()) delaybar开盘时进行交易Bar将要
System.getBuyTradeRequest() System.getSellTradeRequest()
//.def(self_ns::str(self)) BAR是否需要买入/Bar需要进行操作
//.def(self_ns::repr(self)) )")
.def(py::init<>())
.def_readwrite("valid", &TradeRequest::valid, "该交易请求记录是否有效True | False") .def_readwrite("valid", &TradeRequest::valid, "该交易请求记录是否有效True | False")
.def_readwrite("business", &TradeRequest::business, .def_readwrite("business", &TradeRequest::business,
"交易业务类型,参见::py:class:`hikyuu.trade_manage.BUSINESS`") "交易业务类型,参见::py:class:`hikyuu.trade_manage.BUSINESS`")
@ -105,17 +98,11 @@ void export_System() {
.def_readwrite("part", &TradeRequest::from, .def_readwrite("part", &TradeRequest::from,
"发出交易请求的来源,参见::py:class:`System.Part`") "发出交易请求的来源,参见::py:class:`System.Part`")
.def_readwrite("count", &TradeRequest::count, "因操作失败,连续延迟的次数") .def_readwrite("count", &TradeRequest::count, "因操作失败,连续延迟的次数")
#if HKU_PYTHON_SUPPORT_PICKLE DEF_PICKLE(TradeRequest);
.def_pickle(normal_pickle_suite<TradeRequest>())
#endif
;
class_<SystemList>("SystemList").def(vector_indexing_suite<SystemList>()); py::class_<System, SystemPtr>(
m, "System",
scope in_System = R"(系统基类。需要扩展或实现更复杂的系统交易行为,可从此类继承。
class_<System>(
"System",
R"(系统基类。需要扩展或实现更复杂的系统交易行为,可从此类继承。
@ -128,29 +115,30 @@ void export_System() {
- tp_delay_n=3 (int) : - tp_delay_n=3 (int) :
- ignore_sell_sg=False (bool) : 使/ - ignore_sell_sg=False (bool) : 使/
- ev_open_position=False (bool): 使 - ev_open_position=False (bool): 使
- cn_open_position=False (bool): 使)", - cn_open_position=False (bool): 使)")
init<const string&>())
.def(init<const TradeManagerPtr&, const MoneyManagerPtr&, const EnvironmentPtr&,
const ConditionPtr&, const SignalPtr&, const StoplossPtr&, const StoplossPtr&,
const ProfitGoalPtr&, const SlippagePtr&, const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", .def(py::init<const string&>())
make_function(sys_get_name, return_value_policy<copy_const_reference>()), .def(py::init<const TradeManagerPtr&, const MoneyManagerPtr&, const EnvironmentPtr&,
sys_set_name, "系统名称") const ConditionPtr&, const SignalPtr&, const StoplossPtr&, const StoplossPtr&,
.add_property("tm", &System::getTM, &System::setTM, "关联的交易管理实例") const ProfitGoalPtr&, const SlippagePtr&, const string&>())
.add_property("to", &System::getTO, &System::setTO, "交易对象 KData") .def("__str__", to_py_str<System>)
.add_property("mm", &System::getMM, &System::setMM, "资金管理策略") .def("__repr__", to_py_str<System>)
.add_property("ev", &System::getEV, &System::setEV, "市场环境判断策略")
.add_property("cn", &System::getCN, &System::setCN, "系统有效条件")
.add_property("sg", &System::getSG, &System::setSG, "信号指示器")
.add_property("st", &System::getST, &System::setST, "止损策略")
.add_property("tp", &System::getTP, &System::setTP, "止盈策略")
.add_property("pg", &System::getPG, &System::setPG, "盈利目标策略")
.add_property("sp", &System::getSP, &System::setSP, "移滑价差算法")
.def("get_param", &System::getParam<boost::any>, R"(get_param(self, name) .def_property("name", py::overload_cast<void>(&System::name, py::const_),
py::overload_cast<const string&>(&System::name), py::return_value_policy::copy,
"系统名称")
.def_property("tm", &System::getTM, &System::setTM, "关联的交易管理实例")
.def_property("to", &System::getTO, &System::setTO, "交易对象 KData")
.def_property("mm", &System::getMM, &System::setMM, "资金管理策略")
.def_property("ev", &System::getEV, &System::setEV, "市场环境判断策略")
.def_property("cn", &System::getCN, &System::setCN, "系统有效条件")
.def_property("sg", &System::getSG, &System::setSG, "信号指示器")
.def_property("st", &System::getST, &System::setST, "止损策略")
.def_property("tp", &System::getTP, &System::setTP, "止盈策略")
.def_property("pg", &System::getPG, &System::setPG, "盈利目标策略")
.def_property("sp", &System::getSP, &System::setSP, "移滑价差算法")
.def("get_param", &System::getParam<boost::any>, R"(get_param(self, name)
@ -158,7 +146,7 @@ void export_System() {
:return: :return:
:raises out_of_range: )") :raises out_of_range: )")
.def("set_param", &System::setParam<object>, R"(set_param(self, name, value) .def("set_param", &System::setParam<boost::any>, R"(set_param(self, name, value)
@ -166,56 +154,55 @@ void export_System() {
:param value: :param value:
:raises logic_error: Unsupported type! )") :raises logic_error: Unsupported type! )")
.def("have_param", &System::haveParam, "是否存在指定参数") .def("have_param", &System::haveParam, "是否存在指定参数")
.def("get_stock", &System::getStock, R"(get_stock(self) .def("get_stock", &System::getStock, R"(get_stock(self)
:rtype: Stock)") :rtype: Stock)")
.def("get_trade_record_list", &System::getTradeRecordList, .def("get_trade_record_list", &System::getTradeRecordList, py::return_value_policy::copy,
return_value_policy<copy_const_reference>(), R"(get_trade_record_list(self) R"(get_trade_record_list(self)
TM TM
:rtype: TradeRecordList)") :rtype: TradeRecordList)")
.def("get_buy_trade_request", &System::getBuyTradeRequest, .def("get_buy_trade_request", &System::getBuyTradeRequest, py::return_value_policy::copy,
return_value_policy<copy_const_reference>(), R"(get_buy_trade_request(self) R"(get_buy_trade_request(self)
delay delay
:rtype: TradeRequest)") :rtype: TradeRequest)")
.def("get_sell_trade_request", &System::getSellTradeRequest, .def("get_sell_trade_request", &System::getSellTradeRequest, py::return_value_policy::copy,
return_value_policy<copy_const_reference>(), R"(get_sell_trade_request(self) R"(get_sell_trade_request(self)
delay delay
:rtype: TradeRequest)") :rtype: TradeRequest)")
/*.def("getSellShortTradeRequest", &System::getSellShortTradeRequest, .def("get_sell_short_trade_request", &System::getSellShortTradeRequest,
return_value_policy<copy_const_reference>()) py::return_value_policy::copy)
.def("getBuyShortTradeRequest", &System::getBuyShortTradeRequest, .def("get_buy_short_trade_request", &System::getBuyShortTradeRequest,
return_value_policy<copy_const_reference>())*/ py::return_value_policy::copy)
.def("reset", &System::reset, R"(reset(self, with_tm, with_ev) .def("reset", &System::reset, R"(reset(self, with_tm, with_ev)
TMEV是和具体系统无关的策略组件TM时需要注意 TMEV是和具体系统无关的策略组件TM时需要注意
:param bool with_tm: TM组件 :param bool with_tm: TM组件
:param bool with_ev: EV组件)") :param bool with_ev: EV组件)")
.def("clone", &System::clone, R"(clone(self) .def("clone", &System::clone, R"(clone(self)
)") )")
//.def("run", &System::run, run_overload(args("stock", "query", "reset"))) .def("run", run_1, py::arg("query"), py::arg("reset") = true)
.def("run", run_1, (arg("query"), arg("reset") = true)) .def("run", run_2, py::arg("kdata"), py::arg("reset") = true)
.def("run", run_2, (arg("kdata"), arg("reset") = true)) .def("run", run_3, py::arg("stock"), py::arg("query"), py::arg("reset") = true,
.def("run", run_3, (arg("stock"), arg("query"), arg("reset") = true), R"(run(self, stock, query[, reset=True])
R"(run(self, stock, query[, reset=True])
@ -223,14 +210,11 @@ void export_System() {
:param Query query: K线数据查询条件 :param Query query: K线数据查询条件
:param bool reset: tm实例)") :param bool reset: tm实例)")
.def("ready", &System::readyForRun) .def("ready", &System::readyForRun)
#if HKU_PYTHON_SUPPORT_PICKLE DEF_PICKLE(System);
.def_pickle(name_init_pickle_suite<System>())
#endif
;
enum_<SystemPart>("Part") py::enum_<SystemPart>(m, "Part")
.value("ENVIRONMENT", PART_ENVIRONMENT) .value("ENVIRONMENT", PART_ENVIRONMENT)
.value("CONDITION", PART_CONDITION) .value("CONDITION", PART_CONDITION)
.value("SIGNAL", PART_SIGNAL) .value("SIGNAL", PART_SIGNAL)
@ -241,6 +225,4 @@ void export_System() {
.value("SLIPPAGE", PART_SLIPPAGE) .value("SLIPPAGE", PART_SLIPPAGE)
.value("ALLOCATEFUNDS", PART_ALLOCATEFUNDS) .value("ALLOCATEFUNDS", PART_ALLOCATEFUNDS)
.value("INVALID", PART_INVALID); .value("INVALID", PART_INVALID);
register_ptr_to_python<SystemPtr>();
} }

View File

@ -12,12 +12,12 @@ namespace py = pybind11;
void export_Environment(py::module& m); void export_Environment(py::module& m);
void export_Condition(py::module& m); void export_Condition(py::module& m);
void export_MoneyManager(py::module& m); void export_MoneyManager(py::module& m);
// void export_Signal(py::module& m); void export_Signal(py::module& m);
// void export_Stoploss(py::module& m); void export_Stoploss(py::module& m);
void export_ProfitGoal(py::module& m); void export_ProfitGoal(py::module& m);
// void export_Slippage(py::module& m); void export_Slippage(py::module& m);
// void export_System(py::module& m); void export_System(py::module& m);
// void export_Selector(py::module& m); void export_Selector(py::module& m);
void export_Portfolio(py::module& m); void export_Portfolio(py::module& m);
void export_AllocateFunds(py::module& m); void export_AllocateFunds(py::module& m);
@ -25,12 +25,12 @@ void export_trade_sys_main(py::module& m) {
export_Environment(m); export_Environment(m);
export_Condition(m); export_Condition(m);
export_MoneyManager(m); export_MoneyManager(m);
// export_Signal(m); export_Signal(m);
// export_Stoploss(m); export_Stoploss(m);
export_ProfitGoal(m); export_ProfitGoal(m);
// export_Slippage(m); export_Slippage(m);
// export_System(m); export_System(m);
// export_Selector(m); export_Selector(m);
export_AllocateFunds(m); export_AllocateFunds(m);
export_Portfolio(m); export_Portfolio(m);
} }

View File

@ -44,14 +44,8 @@ target("core")
add_files("./global/*.cpp") add_files("./global/*.cpp")
add_files("./trade_instance/*.cpp") add_files("./trade_instance/*.cpp")
add_files("./trade_manage/*.cpp") add_files("./trade_manage/*.cpp")
add_files("./trade_sys/trade_sys_main.cpp") add_files("./trade_sys/*.cpp")
add_files("./trade_sys/_AllocateFunds.cpp")
add_files("./trade_sys/_Condition.cpp")
add_files("./trade_sys/_Environment.cpp")
add_files("./trade_sys/_MoneyManager.cpp")
add_files("./trade_sys/_Portfolio.cpp")
add_files("./trade_sys/_ProfitGoal.cpp")
-- add_files("./trade_sys/_ProfitGoal.cpp")
add_rpathdirs("$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib") add_rpathdirs("$ORIGIN", "$ORIGIN/lib", "$ORIGIN/../lib")