hikyuu2/hikyuu_pywrap/trade_sys/_ProfitGoal.cpp

145 lines
5.2 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _ProfitGoal.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
2016-05-07 02:21:07 +08:00
#include <hikyuu/trade_sys/profitgoal/build_in.h>
2023-12-27 17:02:11 +08:00
#include "../pybind_utils.h"
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
namespace py = pybind11;
2015-01-07 01:26:14 +08:00
using namespace hku;
2023-12-27 17:02:11 +08:00
class PyProfitGoalBase : public ProfitGoalBase {
PY_CLONE(PyProfitGoalBase, ProfitGoalBase)
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
public:
using ProfitGoalBase::ProfitGoalBase;
PyProfitGoalBase(const ProfitGoalBase& base) : ProfitGoalBase(base) {}
2018-01-21 14:00:40 +08:00
2023-12-27 17:02:11 +08:00
void buyNotify(const TradeRecord& tr) override {
PYBIND11_OVERLOAD_NAME(void, ProfitGoalBase, "buy_notify", buyNotify, tr);
2018-01-21 14:00:40 +08:00
}
2023-12-27 17:02:11 +08:00
void sellNotify(const TradeRecord& tr) override {
PYBIND11_OVERLOAD_NAME(void, ProfitGoalBase, "sell_notify", sellNotify, tr);
2015-01-07 01:26:14 +08:00
}
2023-12-27 17:02:11 +08:00
price_t getGoal(const Datetime& datetime, price_t price) override {
PYBIND11_OVERLOAD_PURE_NAME(price_t, ProfitGoalBase, "get_goal", getGoal, datetime, price);
2018-01-21 14:00:40 +08:00
}
2023-12-27 17:02:11 +08:00
price_t getShortGoal(const Datetime& date, price_t price) override {
PYBIND11_OVERLOAD_NAME(price_t, ProfitGoalBase, "get_short_goal", getShortGoal, date,
price);
2015-01-07 01:26:14 +08:00
}
2023-12-27 17:02:11 +08:00
void _reset() override {
PYBIND11_OVERLOAD(void, ProfitGoalBase, _reset, );
2015-01-07 01:26:14 +08:00
}
2023-12-27 17:02:11 +08:00
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, ProfitGoalBase, _calculate, );
};
2015-01-07 01:26:14 +08:00
};
2023-12-27 17:02:11 +08:00
void export_ProfitGoal(py::module& m) {
2024-05-13 05:23:37 +08:00
py::class_<ProfitGoalBase, PGPtr, PyProfitGoalBase>(m, "ProfitGoalBase", py::dynamic_attr(),
2023-12-27 17:02:11 +08:00
R"(盈利目标策略基类
2020-07-15 00:23:48 +08:00
- getGoal :
- _calculate :
- _clone :
- _reset :
- buyNotify :
2023-12-27 17:02:11 +08:00
- sellNotify : )")
.def(py::init<>())
.def(py::init<const ProfitGoalBase&>())
2023-12-27 17:02:11 +08:00
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
2020-07-15 00:23:48 +08:00
2023-12-27 17:02:11 +08:00
.def("__str__", to_py_str<ProfitGoalBase>)
.def("__repr__", to_py_str<ProfitGoalBase>)
2020-07-15 00:23:48 +08:00
.def_property("name", py::overload_cast<>(&ProfitGoalBase::name, py::const_),
2023-12-27 17:02:11 +08:00
py::overload_cast<const string&>(&ProfitGoalBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &ProfitGoalBase::getTO, &ProfitGoalBase::setTO, "设置或获取交易对象")
.def_property("tm", &ProfitGoalBase::getTM, &ProfitGoalBase::setTM, "设置或获取交易管理账户")
2020-07-15 00:23:48 +08:00
.def("get_param", &ProfitGoalBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
2023-12-27 17:02:11 +08:00
.def("set_param", &ProfitGoalBase::setParam<boost::any>, R"(set_param(self, name, value)
2020-07-15 00:23:48 +08:00
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &ProfitGoalBase::haveParam, "是否存在指定参数")
2023-12-27 17:02:11 +08:00
.def("buy_notify", &ProfitGoalBase::buyNotify,
2020-07-15 00:23:48 +08:00
R"(buy_notify(self, trade_record)
:param TradeRecord trade_record: )")
2023-12-27 17:02:11 +08:00
.def("sell_notify", &ProfitGoalBase::sellNotify,
2020-07-15 00:23:48 +08:00
R"(sell_notify(self, trade_record)
:param TradeRecord trade_record: )")
2023-12-27 17:02:11 +08:00
.def("get_goal", &ProfitGoalBase::getGoal, R"(get_goal(self, datetime, price)
2020-07-15 00:23:48 +08:00
constant.null_price时0
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
//.def("getShortGoal", &ProfitGoalBase::getShortGoal, &ProfitGoalWrap::default_getShortGoal)
.def("reset", &ProfitGoalBase::reset, "复位操作")
.def("clone", &ProfitGoalBase::clone, "克隆操作")
2023-12-27 17:02:11 +08:00
.def("_calculate", &ProfitGoalBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &ProfitGoalBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
2020-07-15 00:23:48 +08:00
2023-12-27 17:02:11 +08:00
DEF_PICKLE(PGPtr);
2016-05-07 02:21:07 +08:00
2023-12-27 17:02:11 +08:00
m.def("PG_NoGoal", PG_NoGoal, R"(PG_NoGoal()
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
:return: )");
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
m.def("PG_FixedPercent", PG_FixedPercent, py::arg("p") = 0.2, R"(PG_FixedPercent([p = 0.2])
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
= * (1 + p)
:param float p:
:return: )");
2015-01-07 01:26:14 +08:00
2023-12-27 17:02:11 +08:00
m.def("PG_FixedHoldDays", PG_FixedHoldDays, py::arg("days") = 5, R"(PG_FixedHoldDays([days=5])
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
:param int days: ,5
:return: )");
}