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

133 lines
5.3 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 <hikyuu/trade_sys/stoploss/build_in.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PyStoplossBase : public StoplossBase {
PY_CLONE(PyStoplossBase, StoplossBase)
public:
using StoplossBase::StoplossBase;
PyStoplossBase(const StoplossBase& base) : StoplossBase(base) {}
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, StoplossBase, _calculate, );
}
void _reset() override {
PYBIND11_OVERLOAD(void, StoplossBase, _reset, );
}
price_t getPrice(const Datetime& datetime, price_t price) override {
PYBIND11_OVERLOAD_PURE_NAME(price_t, StoplossBase, "get_price", getPrice, datetime, price);
}
price_t getShortPrice(const Datetime& datetime, price_t price) override {
PYBIND11_OVERLOAD_NAME(price_t, StoplossBase, "get_short_price", getShortPrice, datetime,
price);
}
};
void export_Stoploss(py::module& m) {
py::class_<StoplossBase, StoplossPtr, PyStoplossBase>(m, "StoplossBase", py::dynamic_attr(),
R"(止损/止赢算法基类
/
- _calculate :
- _clone :
- _reset : )")
.def(py::init<>())
.def(py::init<const StoplossBase&>())
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<StoplossBase>)
.def("__repr__", to_py_str<StoplossBase>)
.def_property("name", py::overload_cast<>(&StoplossBase::name, py::const_),
py::overload_cast<const string&>(&StoplossBase::name),
py::return_value_policy::copy, "名称")
.def_property("tm", &StoplossBase::getTM, &StoplossBase::setTM, "关联交易管理实例")
.def_property("to", &StoplossBase::getTO, &StoplossBase::setTO, "关联交易对象")
.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<boost::any>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("have_param", &StoplossBase::haveParam, "是否存在指定参数")
.def("get_price", &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("get_short_price", &StoplossBase::getShortPrice)
.def("reset", &StoplossBase::reset, "复位操作")
.def("clone", &StoplossBase::clone, "克隆操作")
.def("_calculate", &StoplossBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &StoplossBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
DEF_PICKLE(StoplossPtr);
m.def("ST_FixedPercent", ST_FixedPercent, py::arg("p") = 0.03, R"(ST_FixedPercent([p=0.03])
:param float p: (0,1]
:return: /)");
m.def("ST_Indicator", ST_Indicator, py::arg("op"), py::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: /)");
m.def("ST_Saftyloss", ST_Saftyloss, py::arg("n1") = 10, py::arg("n2") = 3, py::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: /)");
}