hikyuu2/hikyuu_pywrap/trade_sys/_Portfolio.cpp

111 lines
4.1 KiB
C++
Raw Normal View History

2016-04-03 00:08:31 +08:00
/*
* _Portfolio.cpp
*
* Created on: 2016329
2016-04-14 01:36:53 +08:00
* Author: fasiondog
2016-04-03 00:08:31 +08:00
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/portfolio/build_in.h>
2020-07-15 22:50:22 +08:00
#include <hikyuu/trade_sys/selector/crt/SE_Fixed.h>
#include <hikyuu/trade_sys/allocatefunds/crt/AF_EqualWeight.h>
#include "../_Parameter.h"
2016-04-03 00:08:31 +08:00
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
2022-02-22 01:45:28 +08:00
namespace py = boost::python;
2016-04-03 00:08:31 +08:00
2017-06-17 16:59:15 +08:00
void (Portfolio::*pf_set_name)(const string&) = &Portfolio::name;
2020-06-26 21:39:53 +08:00
const string& (Portfolio::*pf_get_name)() const = &Portfolio::name;
2016-04-03 00:08:31 +08:00
2022-02-22 01:45:28 +08:00
py::list get_real_sys_list(const Portfolio& pf) {
return vector_to_py_list<SystemList>(pf.getRealSystemList());
}
py::list get_proto_sys_list(const Portfolio& pf) {
return vector_to_py_list<SystemList>(pf.getProtoSystemList());
}
2016-04-03 00:08:31 +08:00
void export_Portfolio() {
2020-07-15 22:50:22 +08:00
class_<Portfolio>("Portfolio", R"(实现多标的、多策略的投资组合)", init<>())
2020-06-26 21:39:53 +08:00
.def(init<const string&>())
.def(init<const TradeManagerPtr&, const SelectorPtr&, const AFPtr&>())
2020-07-15 22:50:22 +08:00
2020-06-26 21:39:53 +08:00
.def(self_ns::str(self))
2020-07-15 00:23:48 +08:00
.def(self_ns::repr(self))
.def("get_param", &Portfolio::getParam<boost::any>)
.def("set_param", &Portfolio::setParam<object>)
.def("have_param", &Portfolio::haveParam)
2020-06-26 21:39:53 +08:00
.add_property("name", make_function(pf_get_name, return_value_policy<copy_const_reference>()),
2020-07-15 22:50:22 +08:00
pf_set_name, "名称")
.add_property("tm", &Portfolio::getTM, &Portfolio::setTM, "设置或获取交易管理对象")
.add_property("se", &Portfolio::getSE, &Portfolio::setSE, "设置或获取交易对象选择算法")
2020-08-13 00:35:19 +08:00
.def("reset", &Portfolio::reset)
.def("clone", &Portfolio::clone)
//.def("readyForRun", &Portfolio::readyForRun)
//.def("runMoment", &Portfolio::runMoment)
2020-08-13 00:35:19 +08:00
2022-02-22 01:45:28 +08:00
.def("run", &Portfolio::run, (arg("query"), arg("force") = false), R"(run(self, query)
2020-07-15 22:50:22 +08:00
2022-02-22 01:45:28 +08:00
PF在第二次执行时
2020-07-15 22:50:22 +08:00
2022-02-22 01:45:28 +08:00
:param Query query:
:param bool force: )")
.def("get_real_sys_list", get_real_sys_list, "获取实际运行的子账户系统列表")
.def("get_proto_sys_list", get_proto_sys_list, "获取原型系统列表")
2020-07-15 22:50:22 +08:00
2022-02-23 01:32:11 +08:00
.def("get_funds", &Portfolio::getFunds, (arg("datetime"), arg("ktype") = KQuery::DAY),
R"(get_funds(self, [datetime, ktype = Query.DAY])
:param Datetime datetime:
:param Query.KType ktype: K线类型
:rtype: FundsRecord)")
2022-02-23 01:32:11 +08:00
.def("get_funds_curve", &Portfolio::getFundsCurve, (arg("dates"), arg("ktype") = KQuery::DAY),
R"(get_funds_curve(self, dates[, ktype = Query.DAY])
线
:param DatetimeList dates: 线
:param Query.KType ktype: K线类型
:return:
:rtype: PriceList)")
2022-02-23 01:32:11 +08:00
.def("get_profit_curve", &Portfolio::getProfitCurve,
(arg("dates"), arg("ktype") = KQuery::DAY),
R"(get_profit_curve(self, dates[, ktype = Query.DAY])
线线
:param DatetimeList dates: 线
:param Query.KType ktype: K线类型
:return: 线
:rtype: PriceList)")
2016-04-03 00:08:31 +08:00
#if HKU_PYTHON_SUPPORT_PICKLE
2020-06-26 21:39:53 +08:00
.def_pickle(name_init_pickle_suite<Portfolio>())
2016-04-03 00:08:31 +08:00
#endif
2020-06-26 21:39:53 +08:00
;
2016-04-03 00:08:31 +08:00
register_ptr_to_python<PortfolioPtr>();
2020-07-15 22:50:22 +08:00
def("PF_Simple", PF_Simple,
(arg("tm") = TradeManagerPtr(), arg("se") = SE_Fixed(), arg("af") = AF_EqualWeight()),
2022-02-15 22:13:47 +08:00
R"(PF_Simple([tm, se, af])
2020-07-15 22:50:22 +08:00
:param TradeManager tm:
2022-02-02 17:02:07 +08:00
:param SelectorBase se:
:param AllocateFundsBase af: )");
2016-04-03 00:08:31 +08:00
}