hikyuu2/hikyuu_pywrap/trade_sys/_MultiFactor.cpp
2024-03-15 03:16:55 +08:00

95 lines
3.3 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.

/*
* Copyright (c) 2024 hikyuu.org
*
* Created on: 2024-03-13
* Author: fasiondog
*/
#include <hikyuu/trade_sys/factor/build_in.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PyMultiFactor : public MultiFactorBase {
PY_CLONE(PyMultiFactor, MultiFactorBase)
public:
using MultiFactorBase::MultiFactorBase;
IndicatorList _calculate(const vector<IndicatorList>& all_stk_inds) {
PYBIND11_OVERLOAD_PURE_NAME(IndicatorList, MultiFactorBase, "_calculate", _calculate,
all_stk_inds);
}
};
void export_MultiFactor(py::module& m) {
py::class_<MultiFactorBase, MultiFactorPtr, PyMultiFactor>(m, "MultiFactor",
R"(市场环境判定策略基类
- _calculate :
- _clone :
- _reset : )")
.def(py::init<>())
// .def(py::init<const string&>())
// .def("__str__", to_py_str<EnvironmentBase>)
// .def("__repr__", to_py_str<EnvironmentBase>)
.def_property("name", py::overload_cast<>(&MultiFactorBase::name, py::const_),
py::overload_cast<const string&>(&MultiFactorBase::name),
py::return_value_policy::copy, "名称")
.def("get_query", &MultiFactorBase::getQuery, py::return_value_policy::copy)
.def("get_param", &MultiFactorBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &MultiFactorBase::setParam<boost::any>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("haveParam", &MultiFactorBase::haveParam, "是否存在指定参数")
// .def("is_valid", &EnvironmentBase::isValid, R"(is_valid(self, datetime)
// 指定时间系统是否有效
// :param Datetime datetime: 指定时间
// :return: True 有效 | False 无效)")
// .def("_add_valid", &EnvironmentBase::_addValid, R"(_add_valid(self, datetime)
// 加入有效时间在_calculate中调用
// :param Datetime datetime: 有效时间)")
// .def("reset", &EnvironmentBase::reset, "复位操作")
// .def("clone", &EnvironmentBase::clone, "克隆操作")
// .def("_reset", &EnvironmentBase::_reset,
// "【重载接口】子类复位接口,用于复位内部私有变量") .def("_calculate",
// &EnvironmentBase::_calculate, "【重载接口】子类计算接口")
DEF_PICKLE(MultiFactorPtr);
m.def(
"MF_EqualWeight",
[](const py::sequence& inds, const py::sequence& stks, const KQuery& query,
const Stock& ref_stk, int ic_n) {
// MF_EqualWeight
IndicatorList c_inds = python_list_to_vector<Indicator>(inds);
StockList c_stks = python_list_to_vector<Stock>(stks);
return MF_EqualWeight(c_inds, c_stks, query, ref_stk, ic_n);
},
py::arg("inds"), py::arg("stks"), py::arg("query"), py::arg("ref_stk"), py::arg("ic_n") = 5);
}