diff --git a/hikyuu/__init__.py b/hikyuu/__init__.py index c2022bf3..56e7a746 100644 --- a/hikyuu/__init__.py +++ b/hikyuu/__init__.py @@ -76,8 +76,8 @@ if sys.platform == 'win32': # 读取配置信息,并初始化 # # ============================================================================== -#config_file = './test_data/hikyuu_win.ini' -config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini" +config_file = './test_data/hikyuu_win.ini' +#config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini" if not os.path.exists(config_file): # 检查老版本配置是否存在,如果存在可继续使用,否则异常终止 data_config_file = os.path.expanduser('~') + "/.hikyuu/data_dir.ini" diff --git a/hikyuu_cpp/hikyuu/utilities/util.cpp b/hikyuu_cpp/hikyuu/utilities/util.cpp index f2cca479..1f6983ad 100644 --- a/hikyuu_cpp/hikyuu/utilities/util.cpp +++ b/hikyuu_cpp/hikyuu/utilities/util.cpp @@ -18,34 +18,6 @@ namespace hku { double HKU_API roundEx(double number, int ndigits) { - /*double f; - int i; - f = 1.0; - i = abs(ndigits); - while (--i >= 0){ - f = f*10.0; - } - - if (ndigits < 0){ - number /= f; - }else{ - number *= f; - } - - if (number >= 0.0){ - number = std::floor(number + 0.5); - }else{ - number = std::ceil(number - 0.5); - } - - if (ndigits < 0){ - number *= f; - }else{ - number /= f; - } - - return number;*/ - //切换至:ROUND_HALF_EVEN 银行家舍入法 double pow1, pow2, y, z; double x = number; diff --git a/hikyuu_pywrap/_KData.cpp b/hikyuu_pywrap/_KData.cpp index 73466a9a..72fefc44 100644 --- a/hikyuu_pywrap/_KData.cpp +++ b/hikyuu_pywrap/_KData.cpp @@ -14,41 +14,38 @@ using namespace boost::python; using namespace hku; void export_KData() { - class_("KData", init<>()) - .def(init()) - .def(init()) - //.def(self_ns::str(self)) - .def("__str__", &KData::toString) - .add_property("startPos", &KData::startPos) - .add_property("endPos", &KData::endPos) - .add_property("lastPos", &KData::lastPos) - .add_property("open", &KData::open) - .add_property("close", &KData::close) - .add_property("high", &KData::high) - .add_property("low", &KData::low) - .add_property("amo", &KData::amo) - .add_property("vol", &KData::vol) + .def(init()) + .def(init()) + //.def(self_ns::str(self)) + .def("__str__", &KData::toString) + .def("__repr__", &KData::toString) + .add_property("startPos", &KData::startPos) + .add_property("endPos", &KData::endPos) + .add_property("lastPos", &KData::lastPos) + .add_property("open", &KData::open) + .add_property("close", &KData::close) + .add_property("high", &KData::high) + .add_property("low", &KData::low) + .add_property("amo", &KData::amo) + .add_property("vol", &KData::vol) - .def("getDatetimeList", &KData::getDatetimeList) - .def("getKRecord", &KData::getKRecord) - .def("get", &KData::getKRecord) - .def("getKRecordByDate", &KData::getKRecordByDate) - .def("getByDate", &KData::getKRecordByDate) - .def("_getPos", &KData::getPos) //python中需要将Null的情况改写为None + .def("getDatetimeList", &KData::getDatetimeList) + .def("getKRecord", &KData::getKRecord) + .def("get", &KData::getKRecord) + .def("getKRecordByDate", &KData::getKRecordByDate) + .def("getByDate", &KData::getKRecordByDate) + .def("_getPos", &KData::getPos) // python中需要将Null的情况改写为None - .def("size", &KData::size) - .def("empty", &KData::empty) - .def("getQuery", &KData::getQuery) - .def("getStock", &KData::getStock) - .def("tocsv", &KData::tocsv) + .def("size", &KData::size) + .def("empty", &KData::empty) + .def("getQuery", &KData::getQuery) + .def("getStock", &KData::getStock) + .def("tocsv", &KData::tocsv) - .def("__len__", &KData::size) + .def("__len__", &KData::size) #if HKU_PYTHON_SUPPORT_PICKLE - .def_pickle(normal_pickle_suite()) + .def_pickle(normal_pickle_suite()) #endif - ; - + ; } - - diff --git a/hikyuu_pywrap/_KRecord.cpp b/hikyuu_pywrap/_KRecord.cpp index 2a36e443..dda7fbde 100644 --- a/hikyuu_pywrap/_KRecord.cpp +++ b/hikyuu_pywrap/_KRecord.cpp @@ -16,32 +16,32 @@ bool (*krecord_eq)(const KRecord&, const KRecord&) = operator==; void export_KReord() { class_("KRecord", init<>()) - .def(init()) - .def(init()) - .def(self_ns::str(self)) - .def_readwrite("datetime", &KRecord::datetime) - .def_readwrite("openPrice", &KRecord::openPrice) - .def_readwrite("highPrice", &KRecord::highPrice) - .def_readwrite("lowPrice", &KRecord::lowPrice) - .def_readwrite("closePrice", &KRecord::closePrice) - .def_readwrite("transAmount", &KRecord::transAmount) - .def_readwrite("transCount", &KRecord::transCount) - .def("__eq__", krecord_eq) + .def(init()) + .def(init()) + .def(self_ns::str(self)) + .def(self_ns::repr(self)) + .def_readwrite("datetime", &KRecord::datetime, "时间") + .def_readwrite("openPrice", &KRecord::openPrice) + .def_readwrite("highPrice", &KRecord::highPrice) + .def_readwrite("lowPrice", &KRecord::lowPrice) + .def_readwrite("closePrice", &KRecord::closePrice) + .def_readwrite("transAmount", &KRecord::transAmount) + .def_readwrite("transCount", &KRecord::transCount) + .def("__eq__", krecord_eq) #if HKU_PYTHON_SUPPORT_PICKLE - .def_pickle(normal_pickle_suite()) + .def_pickle(normal_pickle_suite()) #endif - ; + ; - KRecordList::const_reference (KRecordList::*KRecordList_at)(KRecordList::size_type) const = &KRecordList::at; + KRecordList::const_reference (KRecordList::*KRecordList_at)(KRecordList::size_type) const = + &KRecordList::at; void (KRecordList::*append)(const KRecord&) = &KRecordList::push_back; class_("KRecordList") - .def("__iter__", iterator()) - .def("size", &KRecordList::size) - .def("__len__", &KRecordList::size) - .def("__getitem__", KRecordList_at, return_value_policy()) - .def("append", append) - ; + .def("__iter__", iterator()) + .def("size", &KRecordList::size) + .def("__len__", &KRecordList::size) + .def("__getitem__", KRecordList_at, return_value_policy()) + .def("append", append); register_ptr_to_python(); } - diff --git a/hikyuu_pywrap/_TransRecord.cpp b/hikyuu_pywrap/_TransRecord.cpp index 4b7a8f17..7743297d 100644 --- a/hikyuu_pywrap/_TransRecord.cpp +++ b/hikyuu_pywrap/_TransRecord.cpp @@ -39,6 +39,7 @@ void export_TransRecord() { void (TransList::*append)(const TransRecord&) = &TransList::push_back; class_("TransList") .def(self_ns::str(self)) + .def(self_ns::repr(self)) .def("__iter__", iterator()) .def("size", &TransList::size) .def("__len__", &TransList::size) diff --git a/hikyuu_pywrap/_util.cpp b/hikyuu_pywrap/_util.cpp index 250e9d4e..b4d42ee6 100644 --- a/hikyuu_pywrap/_util.cpp +++ b/hikyuu_pywrap/_util.cpp @@ -11,12 +11,30 @@ using namespace boost::python; using namespace hku; -BOOST_PYTHON_FUNCTION_OVERLOADS(roundEx_overload, roundEx, 1, 2); -BOOST_PYTHON_FUNCTION_OVERLOADS(roundUp_overload, roundUp, 1, 2); -BOOST_PYTHON_FUNCTION_OVERLOADS(roundDown_overload, roundDown, 1, 2); - void export_util() { - def("roundEx", roundEx, roundEx_overload()); - def("roundUp", roundUp, roundUp_overload()); - def("roundDown", roundDown, roundDown_overload()); + def("roundEx", roundEx, (arg("number"), arg("ndigits") = 0), + R"(roundEx(number[, ndigits=0]) + + 四舍五入,ROUND_HALF_EVEN 银行家舍入法 + + :param float number 待四舍五入的数据 + :param int ndigits 保留小数位数 + :rype: float)"); + + def("roundUp", roundUp, (arg("number"), arg("ndigits") = 0), R"(roundUp(number[, ndigits=0]) + + 向上截取,如10.1截取后为11 + + :param float number 待处理数据 + :param int ndigits 保留小数位数 + :rtype: float)"); + + def("roundDown", roundDown, (arg("number"), arg("ndigits") = 0), + R"(roundDown(number[, ndigits=0]) + + 向下截取,如10.1截取后为10 + + :param float number 待处理数据 + :param int ndigits 保留小数位数 + :rtype: float)"); }