hikyuu2/hikyuu_pywrap/trade_sys/_ProfitGoal.cpp
2020-07-15 00:23:48 +08:00

180 lines
6.0 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 <boost/python.hpp>
#include <hikyuu/trade_sys/profitgoal/build_in.h>
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class ProfitGoalWrap : public ProfitGoalBase, public wrapper<ProfitGoalBase> {
public:
ProfitGoalWrap() : ProfitGoalBase() {}
ProfitGoalWrap(const string& name) : ProfitGoalBase(name) {}
virtual ~ProfitGoalWrap() {}
void _reset() {
if (override func = get_override("_reset")) {
func();
} else {
ProfitGoalBase::_reset();
}
}
void default_reset() {
this->ProfitGoalBase::_reset();
}
ProfitGoalPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate")();
}
void buyNotify(const TradeRecord& tr) {
if (override buy_notify = this->get_override("buyNotify")) {
buy_notify(tr);
return;
}
this->ProfitGoalBase::buyNotify(tr);
}
void default_buyNotify(const TradeRecord& tr) {
this->ProfitGoalBase::buyNotify(tr);
}
void sellNotify(const TradeRecord& tr) {
if (override sell_notify = this->get_override("sellNotify")) {
sell_notify(tr);
return;
}
this->ProfitGoalBase::sellNotify(tr);
}
void default_sellNotify(const TradeRecord& tr) {
this->ProfitGoalBase::sellNotify(tr);
}
price_t getGoal(const Datetime& datetime, price_t price) {
return this->get_override("getGoal")(datetime, price);
}
price_t getShortGoal(const Datetime& datetime, price_t price) {
if (override getShortGoal = get_override("getShortGoal")) {
return getShortGoal(datetime, price);
}
return ProfitGoalBase::getShortGoal(datetime, price);
}
price_t default_getShortGoal(const Datetime& datetime, price_t price) {
return this->ProfitGoalBase::getShortGoal(datetime, price);
}
};
string (ProfitGoalBase::*pg_get_name)() const = &ProfitGoalBase::name;
void (ProfitGoalBase::*pg_set_name)(const string&) = &ProfitGoalBase::name;
void export_ProfitGoal() {
class_<ProfitGoalWrap, boost::noncopyable>("ProfitGoalBase", R"(盈利目标策略基类
- getGoal :
- _calculate :
- _clone :
- _reset :
- buyNotify :
- sellNotify : )",
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", pg_get_name, pg_set_name, "名称")
.add_property("to", &ProfitGoalBase::getTO, &ProfitGoalBase::setTO, "设置或获取交易对象")
.add_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<object>, 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, &ProfitGoalWrap::default_buyNotify,
R"(buy_notify(self, trade_record)
:param TradeRecord trade_record: )")
.def("sell_notify", &ProfitGoalBase::sellNotify, &ProfitGoalWrap::default_sellNotify,
R"(sell_notify(self, trade_record)
:param TradeRecord trade_record: )")
.def("get_goal", pure_virtual(&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", pure_virtual(&ProfitGoalBase::_calculate), "【重载接口】子类计算接口")
.def("_reset", &ProfitGoalBase::_reset, &ProfitGoalWrap::default_reset,
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&ProfitGoalBase::_clone), "【重载接口】子类克隆接口");
register_ptr_to_python<ProfitGoalPtr>();
def("PG_NoGoal", PG_NoGoal, R"(PG_NoGoal()
:return: )");
def("PG_FixedPercent", PG_FixedPercent, (arg("p") = 0.2), R"(PG_FixedPercent([p = 0.2])
= * (1 + p)
:param float p:
:return: )");
def("PG_FixedHoldDays", PG_FixedHoldDays, (arg("days") = 5), R"(PG_FixedHoldDays([days=5])
:param int days: ,5
:return: )");
}