完善指标组合测试

This commit is contained in:
fasiondog 2023-10-20 02:18:54 +08:00
parent 1b2a569e93
commit f763ea96c1
5 changed files with 23 additions and 9 deletions

View File

@ -140,8 +140,6 @@ vector<CombinateAnalysisOutput> HKU_API combinateIndicatorAnalysisWithBlock(
}
}
HKU_INFO("result size: {}", result.size());
return result;
}

View File

@ -16,6 +16,7 @@ Performance::Performance()
{"累计投入本金", 0.},
{"累计投入资产", 0.},
{"累计借入现金", 0.},
{"累计借入资产", 0.},
{"累计红利", 0.},
{"现金余额", 0.},
{"未平仓头寸净值", 0.},

View File

@ -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<string, double> map_type;
typedef std::map<string, double> map_type;
typedef map_type::iterator iterator;
typedef map_type::const_iterator const_iterator;

View File

@ -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<py::list> 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]);
}
}

View File

@ -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 之后生效