hikyuu2/hikyuu_pywrap/trade_sys/_Slippage.cpp

127 lines
4.3 KiB
C++
Raw Normal View History

2015-01-07 01:26:14 +08:00
/*
* _Slippage.cpp
*
* Created on: 2013-3-21
* Author: fasiondog
*/
#include <hikyuu/trade_sys/slippage/SlippageBase.h>
2016-05-07 02:21:07 +08:00
#include <hikyuu/trade_sys/slippage/build_in.h>
2023-12-27 18:13:05 +08:00
#include "../pybind_utils.h"
2015-01-07 01:26:14 +08:00
2023-12-27 18:13:05 +08:00
namespace py = pybind11;
2015-01-07 01:26:14 +08:00
using namespace hku;
2023-12-27 18:13:05 +08:00
class PySlippageBase : public SlippageBase {
PY_CLONE(PySlippageBase, SlippageBase)
2016-05-07 02:21:07 +08:00
2023-12-27 18:13:05 +08:00
public:
using SlippageBase::SlippageBase;
PySlippageBase(const SlippageBase& base) : SlippageBase(base) {}
2015-01-07 01:26:14 +08:00
2023-12-27 18:13:05 +08:00
void _calculate() override {
PYBIND11_OVERLOAD_PURE(void, SlippageBase, _calculate, );
2015-01-07 01:26:14 +08:00
}
2023-12-27 18:13:05 +08:00
void _reset() override {
PYBIND11_OVERLOAD(void, SlippageBase, _reset, );
2015-01-07 01:26:14 +08:00
}
2023-12-27 18:13:05 +08:00
price_t getRealBuyPrice(const Datetime& datetime, price_t planPrice) override {
PYBIND11_OVERLOAD_PURE_NAME(price_t, SlippageBase, "get_real_buy_price", getRealBuyPrice,
datetime, planPrice);
2015-01-07 01:26:14 +08:00
}
2023-12-27 18:13:05 +08:00
price_t getRealSellPrice(const Datetime& datetime, price_t planPrice) override {
PYBIND11_OVERLOAD_PURE_NAME(price_t, SlippageBase, "get_real_sell_price", getRealSellPrice,
datetime, planPrice);
2015-01-07 01:26:14 +08:00
}
};
2023-12-27 18:13:05 +08:00
void export_Slippage(py::module& m) {
2024-05-13 05:23:37 +08:00
py::class_<SlippageBase, SPPtr, PySlippageBase>(m, "SlippageBase", py::dynamic_attr(),
R"(移滑价差算法基类
2020-07-15 00:23:48 +08:00
- getRealBuyPrice :
- getRealSellPrice :
- _calculate :
- _clone :
2023-12-27 18:13:05 +08:00
- _reset : )")
.def(py::init<>())
.def(py::init<const SlippageBase&>())
2023-12-27 18:13:05 +08:00
.def(py::init<const string&>(), R"(初始化构造函数
:param str name: )")
.def("__str__", to_py_str<SlippageBase>)
.def("__repr__", to_py_str<SlippageBase>)
2020-07-15 00:23:48 +08:00
.def_property("name", py::overload_cast<>(&SlippageBase::name, py::const_),
2023-12-27 18:13:05 +08:00
py::overload_cast<const string&>(&SlippageBase::name),
py::return_value_policy::copy, "名称")
.def_property("to", &SlippageBase::getTO, &SlippageBase::setTO, "关联交易对象")
2020-07-15 00:23:48 +08:00
.def("get_param", &SlippageBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
2023-12-27 18:13:05 +08:00
.def("set_param", &SlippageBase::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", &SlippageBase::haveParam, "是否存在指定参数")
2023-12-27 18:13:05 +08:00
.def("get_real_buy_price", &SlippageBase::getRealBuyPrice,
2020-07-15 00:23:48 +08:00
R"(get_real_buy_price(self, datetime, price)
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
2023-12-27 18:13:05 +08:00
.def("get_real_sell_price", &SlippageBase::getRealSellPrice,
2020-07-15 00:23:48 +08:00
R"(get_real_sell_price(self, datetime, price)
:param Datetime datetime:
:param float price:
:return:
:rtype: float)")
.def("reset", &SlippageBase::reset, "复位操作")
.def("clone", &SlippageBase::clone, "克隆操作")
2023-12-27 18:13:05 +08:00
.def("_calculate", &SlippageBase::_calculate, "【重载接口】子类计算接口")
.def("_reset", &SlippageBase::_reset, "【重载接口】子类复位接口,复位内部私有变量")
2020-07-15 00:23:48 +08:00
2023-12-27 18:13:05 +08:00
DEF_PICKLE(SPPtr);
2016-05-07 02:21:07 +08:00
2023-12-27 18:13:05 +08:00
m.def("SP_FixedPercent", SP_FixedPercent, py::arg("p") = 0.001,
R"(SP_FixedPercent([p=0.001])
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
= * (1 + p) = * (1 - p)
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
:param float p:
:return: )");
2015-01-07 01:26:14 +08:00
2023-12-27 18:13:05 +08:00
m.def("SP_FixedValue", SP_FixedValue, py::arg("value") = 0.01, R"(SP_FixedValuet([p=0.001])
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
= + = -
2015-01-07 01:26:14 +08:00
2020-07-15 00:23:48 +08:00
:param float p:
:return: )");
}