指标组合测试(continue)

This commit is contained in:
fasiondog 2023-10-18 02:36:38 +08:00
parent cd303f919b
commit 5466427fa8
4 changed files with 36 additions and 11 deletions

View File

@ -28,10 +28,9 @@ std::vector<Indicator> HKU_API combinateIndicator(const std::vector<Indicator>&
return ret;
}
Performance HKU_API combinateIndicatorAnalysis(const Stock& stk, const KQuery& query,
TradeManagerPtr tm, SystemPtr sys,
const std::vector<Indicator>& buy_inds,
const std::vector<Indicator>& sell_inds, int n) {
std::map<std::string, Performance> HKU_API combinateIndicatorAnalysis(
const Stock& stk, const KQuery& query, TradeManagerPtr tm, SystemPtr sys,
const std::vector<Indicator>& buy_inds, const std::vector<Indicator>& sell_inds, int n) {
auto inds = combinateIndicator(buy_inds, n);
std::vector<SignalPtr> sgs;
for (const auto& buy_ind : inds) {
@ -42,15 +41,17 @@ Performance HKU_API combinateIndicatorAnalysis(const Stock& stk, const KQuery& q
}
}
Performance per;
std::map<std::string, Performance> result;
for (const auto& sg : sgs) {
sys->setSG(sg);
sys->setTM(tm);
sys->run(stk, query);
Performance per;
per.statistics(tm, Datetime::now());
result[sg->name()] = std::move(per);
}
return per;
return result;
}
} // namespace hku

View File

@ -45,9 +45,8 @@ std::vector<std::vector<size_t>> combinateIndex(const std::vector<T>& inputs) {
std::vector<Indicator> HKU_API combinateIndicator(const std::vector<Indicator>& inputs, int n);
Performance HKU_API combinateIndicatorAnalysis(const Stock& stk, const KQuery& query,
TradeManagerPtr tm, SystemPtr sys,
const std::vector<Indicator>& buy_inds,
const std::vector<Indicator>& sell_inds, int n);
std::map<std::string, Performance> HKU_API combinateIndicatorAnalysis(
const Stock& stk, const KQuery& query, TradeManagerPtr tm, SystemPtr sys,
const std::vector<Indicator>& buy_inds, const std::vector<Indicator>& sell_inds, int n);
} // namespace hku

View File

@ -56,8 +56,12 @@ public:
*/
void statistics(const TradeManagerPtr& tm, const Datetime& datetime = Datetime::now());
private:
typedef map<string, double> map_type;
typedef map_type::iterator iterator;
typedef map_type::const_iterator const_iterator;
private:
map_type m_result;
};

View File

@ -41,6 +41,26 @@ static py::list combinate_indicator(object seq, int n) {
return vector_to_py_list(comb);
}
static py::dict combinate_ind_analysis(const Stock& stk, const KQuery& query, TradeManagerPtr tm,
SystemPtr sys, object buy_inds, object sell_inds, int n) {
std::vector<Indicator> c_buy_inds;
for (size_t i = 0, total = len(buy_inds); i < total; i++) {
c_buy_inds.emplace_back(py::extract<Indicator>(buy_inds[i])());
}
std::vector<Indicator> c_sell_inds;
for (size_t i = 0, total = len(sell_inds); i < total; i++) {
c_sell_inds.emplace_back(py::extract<Indicator>(sell_inds[i])());
}
py::dict result;
auto pers = combinateIndicatorAnalysis(stk, query, tm, sys, c_buy_inds, c_sell_inds, n);
for (auto iter = pers.begin(); iter != pers.end(); ++iter) {
result[iter->first] = std::move(iter->second);
}
return result;
}
void export_analysis() {
def("combinate_index", combinate_index, R"(combinate_index(seq)
@ -52,4 +72,5 @@ void export_analysis() {
)");
def("combinate_ind", combinate_indicator);
def("combinate_ind_analysis", combinate_ind_analysis);
}