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

127 lines
4.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.

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