hikyuu2/hikyuu_pywrap/trade_manage/_TradeCost.cpp
2023-12-27 17:02:11 +08:00

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

/*
* _TradeCose.cpp
*
* Created on: 2013-2-14
* Author: fasiondog
*/
#include <hikyuu/trade_manage/TradeCostBase.h>
#include "../pybind_utils.h"
namespace py = pybind11;
using namespace hku;
class PyTradeCostBase : public TradeCostBase {
PY_CLONE(PyTradeCostBase, TradeCostBase)
public:
using TradeCostBase::TradeCostBase;
CostRecord getBuyCost(const Datetime& datetime, const Stock& stock, price_t price,
double num) const override {
PYBIND11_OVERLOAD_PURE(CostRecord, TradeCostBase, getBuyCost, datetime, stock, price, num);
}
CostRecord getSellCost(const Datetime& datetime, const Stock& stock, price_t price,
double num) const override {
PYBIND11_OVERLOAD_PURE(CostRecord, TradeCostBase, getSellCost, datetime, stock, price, num);
}
CostRecord getBorrowCashCost(const Datetime& datetime, price_t cash) const override {
PYBIND11_OVERLOAD(CostRecord, TradeCostBase, getBorrowCashCost, datetime, cash);
}
CostRecord getReturnCashCost(const Datetime& borrow_datetime, const Datetime& return_datetime,
price_t cash) const override {
PYBIND11_OVERLOAD(CostRecord, TradeCostBase, getReturnCashCost, borrow_datetime,
return_datetime, cash);
}
CostRecord getBorrowStockCost(const Datetime& datetime, const Stock& stock, price_t price,
double num) const override {
PYBIND11_OVERLOAD(CostRecord, TradeCostBase, getBorrowStockCost, datetime, stock, price,
num);
}
CostRecord getReturnStockCost(const Datetime& borrow_datetime, const Datetime& return_datetime,
const Stock& stock, price_t price, double num) const override {
PYBIND11_OVERLOAD(CostRecord, TradeCostBase, getReturnStockCost, borrow_datetime,
return_datetime, stock, price, num);
}
};
void export_TradeCost(py::module& m) {
py::class_<TradeCostBase, TradeCostPtr, PyTradeCostBase>(m, "TradeCostBase",
R"(交易成本算法基类
:py:meth:`TradeCostBase.getBuyCost` -
:py:meth:`TradeCostBase.getSellCost` -
:py:meth:`TradeCostBase._clone` - )")
.def(py::init<const string&>())
.def("__str__", to_py_str<TradeCostBase>)
.def("__repr__", to_py_str<TradeCostBase>)
.def_property_readonly("name", &TradeCostBase::name, py::return_value_policy::copy,
"成本算法名称")
.def("get_param", &TradeCostBase::getParam<boost::any>, R"(get_param(self, name)
:param str name:
:return:
:raises out_of_range: )")
.def("set_param", &TradeCostBase::setParam<boost::any>, R"(set_param(self, name, value)
:param str name:
:param value:
:raises logic_error: Unsupported type! )")
.def("clone", &TradeCostBase::clone, "克隆操作")
.def("get_buy_cost", &TradeCostBase::getBuyCost, py::arg("date"), py::arg("stock"),
py::arg("price"), py::arg("num"),
R"(get_buy_cost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param int num:
:return:
:rtype: CostRecord)")
.def("get_sell_cost", &TradeCostBase::getSellCost, py::arg("date"), py::arg("stock"),
py::arg("price"), py::arg("num"),
R"(get_sell_cost(self, datetime, stock, price, num)
:param Datetime datetime:
:param Stock stock:
:param float price:
:param int num:
:return:
:rtype: CostRecord)")
//.def("getBorrowCashCost", &TradeCostBase::getBorrowCashCost,
// &TradeCostWrap::default_getBorrowCashCost)
//.def("getReturnCashCost", &TradeCostBase::getReturnCashCost,
// &TradeCostWrap::default_getReturnCashCost)
//.def("getBorrowStockCost", &TradeCostBase::getBorrowStockCost,
//&TradeCostWrap::default_getBorrowStockCost) .def("getReturnStockCost",
//&TradeCostBase::getReturnStockCost, &TradeCostWrap::default_getReturnStockCost)
DEF_PICKLE(TradeCostPtr);
}