mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-04 21:07:57 +08:00
完善指标组合测试
This commit is contained in:
parent
1b2a569e93
commit
f763ea96c1
@ -140,8 +140,6 @@ vector<CombinateAnalysisOutput> HKU_API combinateIndicatorAnalysisWithBlock(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HKU_INFO("result size: {}", result.size());
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ Performance::Performance()
|
|||||||
{"累计投入本金", 0.},
|
{"累计投入本金", 0.},
|
||||||
{"累计投入资产", 0.},
|
{"累计投入资产", 0.},
|
||||||
{"累计借入现金", 0.},
|
{"累计借入现金", 0.},
|
||||||
|
{"累计借入资产", 0.},
|
||||||
{"累计红利", 0.},
|
{"累计红利", 0.},
|
||||||
{"现金余额", 0.},
|
{"现金余额", 0.},
|
||||||
{"未平仓头寸净值", 0.},
|
{"未平仓头寸净值", 0.},
|
||||||
|
@ -56,10 +56,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
void statistics(const TradeManagerPtr& tm, const Datetime& datetime = Datetime::now());
|
void statistics(const TradeManagerPtr& tm, const Datetime& datetime = Datetime::now());
|
||||||
|
|
||||||
|
/** 获取所有统计项名称,顺序与 values 相同 */
|
||||||
StringList names() const;
|
StringList names() const;
|
||||||
|
|
||||||
|
/** 获取所有统计项值,顺序与 names 相同*/
|
||||||
PriceList values() const;
|
PriceList values() const;
|
||||||
|
|
||||||
typedef map<string, double> map_type;
|
typedef std::map<string, double> map_type;
|
||||||
typedef map_type::iterator iterator;
|
typedef map_type::iterator iterator;
|
||||||
typedef map_type::const_iterator const_iterator;
|
typedef map_type::const_iterator const_iterator;
|
||||||
|
|
||||||
|
@ -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);
|
combinateIndicatorAnalysisWithBlock(blk, query, tm, sys, c_buy_inds, c_sell_inds, n);
|
||||||
|
|
||||||
std::vector<py::list> tmp;
|
std::vector<py::list> tmp;
|
||||||
|
|
||||||
|
StringList names{"组合名称", "证券代码", "证券名称"};
|
||||||
Performance per;
|
Performance per;
|
||||||
auto names = per.names();
|
auto keys = per.names();
|
||||||
names.emplace_back("组合名称");
|
for (const auto& key : keys) {
|
||||||
names.emplace_back("证券代码");
|
names.emplace_back(key);
|
||||||
names.emplace_back("证券名称");
|
}
|
||||||
|
|
||||||
for (const auto& name : names) {
|
for (const auto& name : names) {
|
||||||
tmp.emplace_back(py::list());
|
tmp.emplace_back(py::list());
|
||||||
// result[name] = py::list();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0, total = records.size(); i < total; i++) {
|
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[0].append(record.combinateName);
|
||||||
tmp[1].append(record.code);
|
tmp[1].append(record.code);
|
||||||
tmp[2].append(record.name);
|
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++) {
|
for (size_t j = 3, len = names.size(); j < len; j++) {
|
||||||
tmp[j].append(record.values[j]);
|
tmp[j].append(record.values[j - 3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@ void export_Performance() {
|
|||||||
:param TradeManager tm: 指定的交易管理实例
|
:param TradeManager tm: 指定的交易管理实例
|
||||||
:param Datetime datetime: 统计截止时刻)")
|
:param Datetime datetime: 统计截止时刻)")
|
||||||
|
|
||||||
|
.def("names", &Performance::names, R"(names(self)
|
||||||
|
|
||||||
|
获取所有统计项名称)")
|
||||||
|
|
||||||
|
.def("values", &Performance::values, R"(values(self)
|
||||||
|
|
||||||
|
获取所有统计项值,顺序与 names 相同)")
|
||||||
|
|
||||||
.def("__getitem__", &Performance::get,
|
.def("__getitem__", &Performance::get,
|
||||||
R"(按指标名称获取指标值,必须在运行 statistics 或 report 之后生效
|
R"(按指标名称获取指标值,必须在运行 statistics 或 report 之后生效
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user