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

145 lines
5.2 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.

/*
* _ProfitGoal.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
#include <hikyuu/trade_sys/profitgoal/build_in.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PyProfitGoalBase : public ProfitGoalBase {
PY_CLONE(PyProfitGoalBase, ProfitGoalBase)
public:
using ProfitGoalBase::ProfitGoalBase;
PyProfitGoalBase(const ProfitGoalBase& base) : ProfitGoalBase(base) {}
void buyNotify(const TradeRecord& tr) override {
PYBIND11_OVERLOAD_NAME(void, ProfitGoalBase, "buy_notify", buyNotify, tr);
}
void sellNotify(const TradeRecord& tr) override {
PYBIND11_OVERLOAD_NAME(void, ProfitGoalBase, "sell_notify", sellNotify, tr);
}
price_t getGoal(const Datetime& datetime, price_t price) override {
PYBIND11_OVERLOAD_PURE_NAME(price_t, ProfitGoalBase, "get_goal", getGoal, datetime, price);
}
price_t getShortGoal(const Datetime& date, price_t price) override {
PYBIND11_OVERLOAD_NAME(price_t, ProfitGoalBase, "get_short_goal", getShortGoal, date,
price);
}
void _reset() override {
PYBIND11_OVERLOAD(void, ProfitGoalBase, _reset, );
}
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, ProfitGoalBase, _calculate, );
};
};
void export_ProfitGoal(py::module& m) {
py::class_<ProfitGoalBase, PGPtr, PyProfitGoalBase>(m, "ProfitGoalBase", py::dynamic_attr(),
R"(盈利目标策略基类
- getGoal :
- _calculate :
- _clone :
- _reset :
- buyNotify :
- sellNotify : )")
.def(py::init<>())
.def(py::init<const ProfitGoalBase&>())
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<ProfitGoalBase>)
.def("__repr__", to_py_str<ProfitGoalBase>)
.def_property("name", py::overload_cast<>(&ProfitGoalBase::name, py::const_),
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, "设置或获取交易管理账户")
.def("get_param", &ProfitGoalBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &ProfitGoalBase::setParam<boost::any>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &ProfitGoalBase::haveParam, "是否存在指定参数")
.def("buy_notify", &ProfitGoalBase::buyNotify,
R"(buy_notify(self, trade_record)
:param TradeRecord trade_record: )")
.def("sell_notify", &ProfitGoalBase::sellNotify,
R"(sell_notify(self, trade_record)
:param TradeRecord trade_record: )")
.def("get_goal", &ProfitGoalBase::getGoal, R"(get_goal(self, datetime, price)
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, "克隆操作")
.def("_calculate", &ProfitGoalBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &ProfitGoalBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
DEF_PICKLE(PGPtr);
m.def("PG_NoGoal", PG_NoGoal, R"(PG_NoGoal()
:return: )");
m.def("PG_FixedPercent", PG_FixedPercent, py::arg("p") = 0.2, R"(PG_FixedPercent([p = 0.2])
= * (1 + p)
:param float p:
:return: )");
m.def("PG_FixedHoldDays", PG_FixedHoldDays, py::arg("days") = 5, R"(PG_FixedHoldDays([days=5])
:param int days: ,5
:return: )");
}