hikyuu2/hikyuu_pywrap/trade_sys/_Stoploss.cpp
2021-02-13 00:02:58 +08:00

155 lines
5.8 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.

/*
* _Stoploss.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/trade_sys/stoploss/build_in.h>
#include "../_Parameter.h"
#include "../pickle_support.h"
using namespace boost::python;
using namespace hku;
class StoplossWrap : public StoplossBase, public wrapper<StoplossBase> {
public:
StoplossWrap() : StoplossBase() {}
StoplossWrap(const string& name) : StoplossBase(name) {}
virtual ~StoplossWrap() {}
void _reset() {
if (override func = this->get_override("_reset")) {
func();
} else {
StoplossBase::_reset();
}
}
void default_reset() {
this->StoplossBase::_reset();
}
StoplossPtr _clone() {
return this->get_override("_clone")();
}
void _calculate() {
this->get_override("_calculate")();
}
price_t getPrice(const Datetime& datetime, price_t price) {
return this->get_override("get_price")(datetime, price);
}
price_t getShortPrice(const Datetime& datetime, price_t price) {
if (override getShortPrice = get_override("get_short_price")) {
return getShortPrice(datetime, price);
}
return StoplossBase::getShortPrice(datetime, price);
}
price_t default_getShortPrice(const Datetime& datetime, price_t price) {
return this->StoplossBase::getShortPrice(datetime, price);
}
};
string (StoplossBase::*st_get_name)() const = &StoplossBase::name;
void (StoplossBase::*st_set_name)(const string&) = &StoplossBase::name;
void export_Stoploss() {
class_<StoplossWrap, boost::noncopyable>("StoplossBase", R"(止损/止赢算法基类
/
- _calculate :
- _clone :
- _reset : )",
init<>())
.def(init<const string&>())
.def(self_ns::str(self))
.def(self_ns::repr(self))
.add_property("name", st_get_name, st_set_name, "名称")
.add_property("to", &StoplossBase::getTO, &StoplossBase::setTO, "设置或获取交易对象")
.add_property("tm", &StoplossBase::getTM, &StoplossBase::setTM, "设置或获取交易管理实例")
.def("get_param", &StoplossBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &StoplossBase::setParam<object>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &StoplossBase::haveParam, "是否存在指定参数")
.def("get_price", pure_virtual(&StoplossBase::getPrice), R"(get_price(self, datetime, price)
0
.. note::
/getPrice可以传入计划交易的价格30%price参数price为0.0使使price参数使30%price参数
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
//.def("getShortPrice", &StoplossBase::getShortPrice, &StoplossWrap::default_getShortPrice)
.def("reset", &StoplossBase::reset, "复位操作")
.def("clone", &StoplossBase::clone, "克隆操作")
.def("_calculate", pure_virtual(&StoplossBase::_calculate), "【重载接口】子类计算接口")
.def("_reset", &StoplossBase::_reset, &StoplossWrap::default_reset,
"【重载接口】子类复位接口,复位内部私有变量")
.def("_clone", pure_virtual(&StoplossBase::_clone), "【重载接口】子类克隆接口")
#if HKU_PYTHON_SUPPORT_PICKLE
.def_pickle(name_init_pickle_suite<StoplossBase>())
#endif
;
register_ptr_to_python<StoplossPtr>();
def("ST_FixedPercent", ST_FixedPercent, (arg("p") = 0.03), R"(ST_FixedPercent([p=0.03])
:param float p: (0,1]
:return: /)");
def("ST_Indicator", ST_Indicator, (arg("op"), arg("kpart") = "CLOSE"),
R"(ST_Indicator(op[, kpart="CLOSE"])
使使10EMA作为止损::
ST_Indicator(OP(EMA(n=10)))
:param Indicator op:
:param string kpart: KDATA|OPEN|HIGH|LOW|CLOSE|AMO|VOL
:return: /)");
def("ST_Saftyloss", ST_Saftyloss, (arg("n1") = 10, arg("n2") = 3, arg("p") = 2.0),
R"(ST_Saftyloss([n1=10, n2=3, p=2.0])
2007 .(Alexander Elder) P202
1020穿穿
线线
N日3
:param int n1: 10
:param int n2: 线n2日内的最高值3
:param double p: 2
:return: /)");
}