hikyuu2/hikyuu_pywrap/trade_sys/_AllocateFunds.cpp
2024-05-13 05:23:37 +08:00

107 lines
3.8 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 <hikyuu/trade_sys/allocatefunds/build_in.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
#if defined(_MSC_VER)
#pragma warning(disable : 4267)
#endif
class PyAllocateFundsBase : public AllocateFundsBase {
PY_CLONE(PyAllocateFundsBase, AllocateFundsBase)
public:
using AllocateFundsBase::AllocateFundsBase;
PyAllocateFundsBase(const AllocateFundsBase& base) : AllocateFundsBase(base) {}
void _reset() override {
PYBIND11_OVERLOAD(void, AllocateFundsBase, _reset, );
}
SystemWeightList _allocateWeight(const Datetime& date,
const SystemWeightList& se_list) override {
PYBIND11_OVERLOAD_PURE_NAME(SystemWeightList, AllocateFundsBase, "_allocate_weight",
_allocateWeight, date, se_list);
}
};
void export_AllocateFunds(py::module& m) {
py::class_<AllocateFundsBase, AFPtr, PyAllocateFundsBase>(
m, "AllocateFundsBase", py::dynamic_attr(),
R"(资产分配算法基类, 子类接口:
- _allocateWeight :
- _clone :
- _reset : )")
.def(py::init<>())
.def(py::init<const string&>())
.def(py::init<const AllocateFundsBase&>())
.def("__str__", to_py_str<AllocateFundsBase>)
.def("__repr__", to_py_str<AllocateFundsBase>)
.def_property("name", py::overload_cast<>(&AllocateFundsBase::name, py::const_),
py::overload_cast<const string&>(&AllocateFundsBase::name),
py::return_value_policy::copy, "算法组件名称")
.def_property("query", py::overload_cast<>(&AllocateFundsBase::getQuery, py::const_),
py::overload_cast<const KQuery&>(&AllocateFundsBase::setQuery),
py::return_value_policy::copy, "设置或获取查询条件")
.def_property_readonly("tm", py::overload_cast<>(&AllocateFundsBase::getTM, py::const_),
py::return_value_policy::copy)
.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<boost::any>, 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, "子类复位操作实现")
.def("_allocate_weight", &AllocateFundsBase::_allocateWeight, py::arg("date"),
py::arg("se_list"),
R"(_allocate_weight(self, date, se_list)
:param Datetime date:
:param SystemList se_list:
:return:
:rtype: SystemWeightList)")
DEF_PICKLE(AFPtr);
m.def("AF_EqualWeight", AF_EqualWeight, R"(AF_EqualWeight()
)");
m.def("AF_FixedWeight", AF_FixedWeight, py::arg("weight") = 0.1, R"(AF_FixedWeight(weight)
:param float weight: [0, 1])");
m.def("AF_MultiFactor", AF_MultiFactor, R"(AF_MultiFactor()
MultiFactor
)");
}