From f763ea96c1235f96d02410ac6e77609e92e9aada Mon Sep 17 00:00:00 2001 From: fasiondog Date: Fri, 20 Oct 2023 02:18:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=8C=87=E6=A0=87=E7=BB=84?= =?UTF-8?q?=E5=90=88=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hikyuu_cpp/hikyuu/analysis/combinate.cpp | 2 -- hikyuu_cpp/hikyuu/trade_manage/Performance.cpp | 1 + hikyuu_cpp/hikyuu/trade_manage/Performance.h | 5 ++++- hikyuu_pywrap/_analysis.cpp | 16 ++++++++++------ hikyuu_pywrap/trade_manage/_Performance.cpp | 8 ++++++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/hikyuu_cpp/hikyuu/analysis/combinate.cpp b/hikyuu_cpp/hikyuu/analysis/combinate.cpp index 70923ae2..919fe855 100644 --- a/hikyuu_cpp/hikyuu/analysis/combinate.cpp +++ b/hikyuu_cpp/hikyuu/analysis/combinate.cpp @@ -140,8 +140,6 @@ vector HKU_API combinateIndicatorAnalysisWithBlock( } } - HKU_INFO("result size: {}", result.size()); - return result; } diff --git a/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp b/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp index fac8b13d..17636d0e 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp +++ b/hikyuu_cpp/hikyuu/trade_manage/Performance.cpp @@ -16,6 +16,7 @@ Performance::Performance() {"累计投入本金", 0.}, {"累计投入资产", 0.}, {"累计借入现金", 0.}, + {"累计借入资产", 0.}, {"累计红利", 0.}, {"现金余额", 0.}, {"未平仓头寸净值", 0.}, diff --git a/hikyuu_cpp/hikyuu/trade_manage/Performance.h b/hikyuu_cpp/hikyuu/trade_manage/Performance.h index 0fcc99e6..f7a59f0c 100644 --- a/hikyuu_cpp/hikyuu/trade_manage/Performance.h +++ b/hikyuu_cpp/hikyuu/trade_manage/Performance.h @@ -56,10 +56,13 @@ public: */ void statistics(const TradeManagerPtr& tm, const Datetime& datetime = Datetime::now()); + /** 获取所有统计项名称,顺序与 values 相同 */ StringList names() const; + + /** 获取所有统计项值,顺序与 names 相同*/ PriceList values() const; - typedef map map_type; + typedef std::map map_type; typedef map_type::iterator iterator; typedef map_type::const_iterator const_iterator; diff --git a/hikyuu_pywrap/_analysis.cpp b/hikyuu_pywrap/_analysis.cpp index 752c21b6..24e5f1b0 100644 --- a/hikyuu_pywrap/_analysis.cpp +++ b/hikyuu_pywrap/_analysis.cpp @@ -78,14 +78,16 @@ static py::dict combinate_ind_analysis_with_block(const Block& blk, const KQuery combinateIndicatorAnalysisWithBlock(blk, query, tm, sys, c_buy_inds, c_sell_inds, n); std::vector tmp; + + StringList names{"组合名称", "证券代码", "证券名称"}; Performance per; - auto names = per.names(); - names.emplace_back("组合名称"); - names.emplace_back("证券代码"); - names.emplace_back("证券名称"); + auto keys = per.names(); + for (const auto& key : keys) { + names.emplace_back(key); + } + for (const auto& name : names) { tmp.emplace_back(py::list()); - // result[name] = py::list(); } for (size_t i = 0, total = records.size(); i < total; i++) { @@ -93,8 +95,10 @@ static py::dict combinate_ind_analysis_with_block(const Block& blk, const KQuery tmp[0].append(record.combinateName); tmp[1].append(record.code); tmp[2].append(record.name); + HKU_INFO_IF(names.size() != record.values.size() + 3, "lenght invalid: {} {}", names.size(), + record.values.size()); for (size_t j = 3, len = names.size(); j < len; j++) { - tmp[j].append(record.values[j]); + tmp[j].append(record.values[j - 3]); } } diff --git a/hikyuu_pywrap/trade_manage/_Performance.cpp b/hikyuu_pywrap/trade_manage/_Performance.cpp index 8e9741fa..3edd1582 100644 --- a/hikyuu_pywrap/trade_manage/_Performance.cpp +++ b/hikyuu_pywrap/trade_manage/_Performance.cpp @@ -34,6 +34,14 @@ void export_Performance() { :param TradeManager tm: 指定的交易管理实例 :param Datetime datetime: 统计截止时刻)") + .def("names", &Performance::names, R"(names(self) + + 获取所有统计项名称)") + + .def("values", &Performance::values, R"(values(self) + + 获取所有统计项值,顺序与 names 相同)") + .def("__getitem__", &Performance::get, R"(按指标名称获取指标值,必须在运行 statistics 或 report 之后生效