2018-02-09 01:05:05 +08:00
|
|
|
/*
|
|
|
|
* _Selector.cpp
|
|
|
|
*
|
|
|
|
* Created on: 2016年3月28日
|
|
|
|
* Author: fasiondog
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <hikyuu/trade_sys/allocatefunds/build_in.h>
|
|
|
|
#include "../_Parameter.h"
|
|
|
|
#include "../pickle_support.h"
|
|
|
|
|
|
|
|
using namespace boost::python;
|
|
|
|
using namespace hku;
|
|
|
|
|
|
|
|
class AllocateFundsBaseWrap : public AllocateFundsBase, public wrapper<AllocateFundsBase> {
|
|
|
|
public:
|
2020-08-26 00:25:45 +08:00
|
|
|
AllocateFundsBaseWrap() : AllocateFundsBase() {}
|
|
|
|
AllocateFundsBaseWrap(const string& name) : AllocateFundsBase(name) {}
|
2018-02-09 01:05:05 +08:00
|
|
|
virtual ~AllocateFundsBaseWrap() {}
|
|
|
|
|
|
|
|
void _reset() {
|
|
|
|
if (override func = this->get_override("_reset")) {
|
|
|
|
func();
|
|
|
|
} else {
|
|
|
|
AllocateFundsBase::_reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void default_reset() {
|
|
|
|
this->AllocateFundsBase::_reset();
|
|
|
|
}
|
|
|
|
|
2020-08-26 00:25:45 +08:00
|
|
|
SystemWeightList _allocateWeight(const Datetime& date, const SystemList& se_list) {
|
2021-02-13 00:02:58 +08:00
|
|
|
return this->get_override("_allocate_weight")(date, se_list);
|
2018-02-09 01:05:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AFPtr _clone() {
|
|
|
|
return this->get_override("_clone")();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
string (AllocateFundsBase::*af_get_name)() const = &AllocateFundsBase::name;
|
|
|
|
void (AllocateFundsBase::*af_set_name)(const string&) = &AllocateFundsBase::name;
|
|
|
|
|
|
|
|
void export_AllocateFunds() {
|
|
|
|
class_<SystemWeight>("SystemWeight", init<>())
|
2020-08-26 00:25:45 +08:00
|
|
|
.def(init<const SystemPtr&, price_t>())
|
|
|
|
.def(self_ns::str(self))
|
|
|
|
.def_readwrite("sys", &SystemWeight::m_sys)
|
|
|
|
.def_readwrite("weight", &SystemWeight::m_weight)
|
2018-02-09 01:05:05 +08:00
|
|
|
#if HKU_PYTHON_SUPPORT_PICKLE
|
2020-08-26 00:25:45 +08:00
|
|
|
.def_pickle(normal_pickle_suite<SystemWeight>())
|
2018-02-09 01:05:05 +08:00
|
|
|
#endif
|
2020-08-26 00:25:45 +08:00
|
|
|
;
|
2018-02-09 01:05:05 +08:00
|
|
|
|
2020-08-26 00:25:45 +08:00
|
|
|
SystemWeightList::const_reference (SystemWeightList::*SystemWeightList_at)(
|
|
|
|
SystemWeightList::size_type) const = &SystemWeightList::at;
|
2018-02-09 01:05:05 +08:00
|
|
|
void (SystemWeightList::*append)(const SystemWeight&) = &SystemWeightList::push_back;
|
|
|
|
class_<SystemWeightList>("SystemWeightList")
|
2020-08-26 00:25:45 +08:00
|
|
|
.def("__iter__", iterator<SystemWeightList>())
|
|
|
|
.def("size", &SystemWeightList::size)
|
|
|
|
.def("__len__", &SystemWeightList::size)
|
|
|
|
.def("get", SystemWeightList_at, return_value_policy<copy_const_reference>())
|
|
|
|
.def("append", append);
|
2018-02-09 01:05:05 +08:00
|
|
|
|
|
|
|
class_<AllocateFundsBaseWrap, boost::noncopyable>("AllocateFundsBase", init<>())
|
2020-08-26 00:25:45 +08:00
|
|
|
.def(init<const string&>())
|
|
|
|
.def(self_ns::str(self))
|
|
|
|
.def(self_ns::repr(self))
|
|
|
|
.add_property("name", af_get_name, af_set_name)
|
2021-02-13 00:02:58 +08:00
|
|
|
.def("get_param", &AllocateFundsBase::getParam<boost::any>)
|
|
|
|
.def("set_param", &AllocateFundsBase::setParam<object>)
|
|
|
|
.def("have_param", &AllocateFundsBase::haveParam)
|
2020-08-26 00:25:45 +08:00
|
|
|
|
|
|
|
.def("reset", &AllocateFundsBase::reset)
|
|
|
|
.def("clone", &AllocateFundsBase::clone)
|
|
|
|
.def("_reset", &AllocateFundsBase::_reset, &AllocateFundsBaseWrap::default_reset)
|
|
|
|
.def("_clone", pure_virtual(&AllocateFundsBase::_clone))
|
2021-02-13 00:02:58 +08:00
|
|
|
.def("_allocate_weight", pure_virtual(&AllocateFundsBase::_allocateWeight))
|
2018-02-09 01:05:05 +08:00
|
|
|
#if HKU_PYTHON_SUPPORT_PICKLE
|
2020-08-26 00:25:45 +08:00
|
|
|
.def_pickle(name_init_pickle_suite<AllocateFundsBase>())
|
2018-02-09 01:05:05 +08:00
|
|
|
#endif
|
2020-08-26 00:25:45 +08:00
|
|
|
;
|
2018-02-09 01:05:05 +08:00
|
|
|
|
|
|
|
register_ptr_to_python<AFPtr>();
|
|
|
|
|
|
|
|
def("AF_EqualWeight", AF_EqualWeight);
|
2020-08-31 23:52:25 +08:00
|
|
|
def("AF_FixedWeight", AF_FixedWeight);
|
2018-02-09 01:05:05 +08:00
|
|
|
}
|