hikyuu2/hikyuu_pywrap/trade_sys/_AllocateFunds.cpp
2022-02-26 11:15:57 +08:00

135 lines
4.7 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.

/*
* _Selector.cpp
*
* Created on: 2016年3月28日
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/allocatefunds/build_in.h>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
#if defined(_MSC_VER)
#pragma warning(disable : 4267)
#endif
class AllocateFundsBaseWrap : public AllocateFundsBase, public wrapper<AllocateFundsBase> {
public:
AllocateFundsBaseWrap() : AllocateFundsBase() {}
AllocateFundsBaseWrap(const string& name) : AllocateFundsBase(name) {}
virtual ~AllocateFundsBaseWrap() {}
void _reset() {
if (override func = this->get_override("_reset")) {
func();
} else {
AllocateFundsBase::_reset();
}
}
void default_reset() {
this->AllocateFundsBase::_reset();
}
SystemWeightList _allocateWeight(const Datetime& date, const SystemList& se_list) {
return this->get_override("_allocate_weight")(date, se_list);
}
AFPtr _clone() {
return this->get_override("_clone")();
}
};
const string& (AllocateFundsBase::*af_get_name)() const = &AllocateFundsBase::name;
void (AllocateFundsBase::*af_set_name)(const string&) = &AllocateFundsBase::name;
void export_AllocateFunds() {
class_<SystemWeight>("SystemWeight",
"系统权重系数结构,在资产分配时,指定对应系统的资产占比系数", init<>())
.def(init<const SystemPtr&, price_t>())
.def(self_ns::str(self))
.add_property(
"sys", make_function(&SystemWeight::getSYS, return_value_policy<copy_const_reference>()),
&SystemWeight::setSYS, "对应的 System 实例")
.add_property("weight", &SystemWeight::getWeight, &SystemWeight::setWeight,
"对应的权重系数,有效范围为 [0, 1]")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(normal_pickle_suite<SystemWeight>())
#endif
;
class_<SystemWeightList>("SystemWeightList").def(vector_indexing_suite<SystemWeightList>());
class_<AllocateFundsBaseWrap, boost::noncopyable>("AllocateFundsBase",
R"(资产分配算法基类, 子类接口:
- _allocateWeight :
- _clone :
- _reset : )",
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", make_function(af_get_name, return_value_policy<copy_const_reference>()),
af_set_name, "算法组件名称")
.add_property(
"query",
make_function(&AllocateFundsBase::getQuery, return_value_policy<copy_const_reference>()),
&AllocateFundsBase::setQuery, "设置或获取查询条件")
.def("get_param", &AllocateFundsBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &AllocateFundsBase::setParam<object>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &AllocateFundsBase::haveParam, "是否存在指定参数")
.def("reset", &AllocateFundsBase::reset, "复位操作")
.def("clone", &AllocateFundsBase::clone, "克隆操作")
.def("_reset", &AllocateFundsBase::_reset, &AllocateFundsBaseWrap::default_reset,
"子类复位操作实现")
.def("_clone", pure_virtual(&AllocateFundsBase::_clone), "子类克隆操作实现接口")
.def("_allocate_weight", pure_virtual(&AllocateFundsBase::_allocateWeight),
(arg("date"), arg("se_list")), R"(_allocate_weight(self, date, se_list)
:param Datetime date:
:param SystemList se_list:
:return:
:rtype: SystemWeightList)")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<AllocateFundsBase>())
#endif
;
register_ptr_to_python<AFPtr>();
def("AF_EqualWeight", AF_EqualWeight, R"(AF_EqualWeight()
)");
def("AF_FixedWeight", AF_FixedWeight, (arg("weight") = 0.1), R"(AF_FixedWeight(weight)
:param float weight: [0, 1])");
}