hikyuu2/hikyuu_pywrap/_analysis.cpp
2023-10-10 04:49:49 +08:00

55 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (c) 2023 hikyuu.org
*
* Created on: 2023-10-10
* Author: fasiondog
*/
#include <boost/python.hpp>
#include <hikyuu/analysis/combinate.h>
#include "pybind_utils.h"
using namespace boost::python;
using namespace hku;
namespace py = boost::python;
static py::list combinate_index(object seq) {
size_t total = len(seq);
std::vector<size_t> index_list(total);
for (size_t i = 0; i < total; ++i) {
index_list[i] = i;
}
py::list result;
std::vector<std::vector<size_t>> comb = combinateIndex(index_list);
for (size_t i = 0, count = comb.size(); i < count; i++) {
py::list tmp = vector_to_py_list<std::vector<size_t>>(comb[i]);
result.append(tmp);
}
return result;
}
static py::list combinate_indicator(object seq, int n) {
size_t total = len(seq);
std::vector<Indicator> inds(total);
for (size_t i = 0; i < total; ++i) {
inds[i] = py::extract<Indicator>(seq[i])();
}
auto comb = combinateIndicator(inds, n);
return vector_to_py_list(comb);
}
void export_analysis() {
def("combinate_index", combinate_index, R"(combinate_index(seq)
, 15
:param seq: python
:rtype: list
)");
def("combinate_ind", combinate_indicator);
}