mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
update for parallel
This commit is contained in:
parent
b7997e8f69
commit
0bbdf20d39
@ -21,8 +21,8 @@ os.environ['HKU_START_SPOT'] = '0' # 禁止启动行情接收代理
|
||||
from hikyuu.interactive import * # NOQA: E402
|
||||
|
||||
|
||||
fast_n = range(3, 200)
|
||||
slow_n = range(5, 300)
|
||||
fast_n = range(3, 20)
|
||||
slow_n = range(5, 100)
|
||||
params = [v for v in product(fast_n, slow_n)]
|
||||
# print(params)
|
||||
|
||||
@ -73,11 +73,11 @@ while not sm.data_ready:
|
||||
time.sleep(100)
|
||||
|
||||
# max_val, max_sys = find_optimal_param(sys_list, stk, query, key='当前总资产')
|
||||
max_val, max_sys = find_optimal_system_multi(sys_list, stk, query, '当前总资产', 0)
|
||||
# max_val, max_sys = find_optimal_system_multi(sys_list, stk, query, '当前总资产', 0)
|
||||
|
||||
# print(max_val)
|
||||
print(max_sys.name)
|
||||
print(len(sys_list))
|
||||
# print(max_sys.name)
|
||||
# print(len(sys_list))
|
||||
|
||||
# max_sys.run(stk, query)
|
||||
# max_sys.performance()
|
||||
@ -86,3 +86,9 @@ print(len(sys_list))
|
||||
|
||||
# x = find_optimal_system(sys_list, stk, query, '当前总资产', 0)
|
||||
# print(x)
|
||||
|
||||
my_sys = SYS_WalkForward(sys_list, crtTM())
|
||||
my_sys.set_param("parallel", True)
|
||||
my_sys.run(stk, query)
|
||||
my_sys.performance()
|
||||
plt.show()
|
||||
|
@ -124,6 +124,7 @@ void OptimalSelector::calculate(const SystemList& pf_realSysList, const KQuery&
|
||||
void OptimalSelector::_calculate_single(const vector<std::pair<size_t, size_t>>& train_ranges,
|
||||
const DatetimeList& dates, const string& key, int mode,
|
||||
size_t test_len, bool trace) {
|
||||
SPEND_TIME(OptimalSelector_calculate_single);
|
||||
size_t dates_len = dates.size();
|
||||
Performance per;
|
||||
for (size_t i = 0, total = train_ranges.size(); i < total; i++) {
|
||||
@ -190,6 +191,7 @@ void OptimalSelector::_calculate_single(const vector<std::pair<size_t, size_t>>&
|
||||
void OptimalSelector::_calculate_parallel(const vector<std::pair<size_t, size_t>>& train_ranges,
|
||||
const DatetimeList& dates, const string& key, int mode,
|
||||
size_t test_len, bool trace) {
|
||||
SPEND_TIME(OptimalSelector_calculate_parallel);
|
||||
auto sys_list = parallel_for_index(
|
||||
0, train_ranges.size(),
|
||||
[this, &train_ranges, &dates, query = m_query, trace, key, mode](size_t i) {
|
||||
@ -205,13 +207,14 @@ void OptimalSelector::_calculate_parallel(const vector<std::pair<size_t, size_t>
|
||||
} else if (0 == mode) {
|
||||
double max_value = std::numeric_limits<double>::lowest();
|
||||
for (const auto& sys : m_pro_sys_list) {
|
||||
sys->run(q, true);
|
||||
per.statistics(sys->getTM(), end_date);
|
||||
auto new_sys = sys->clone();
|
||||
new_sys->run(q, true);
|
||||
per.statistics(new_sys->getTM(), end_date);
|
||||
double value = per.get(key);
|
||||
CLS_TRACE_IF(trace, "value: {}, sys: {}", value, sys->name());
|
||||
CLS_TRACE_IF(trace, "value: {}, sys: {}", value, new_sys->name());
|
||||
if (value > max_value) {
|
||||
max_value = value;
|
||||
selected_sys = sys;
|
||||
selected_sys = new_sys;
|
||||
}
|
||||
}
|
||||
} else if (1 == mode) {
|
||||
|
@ -171,6 +171,7 @@ void WalkForwardSystem::readyForRun() {
|
||||
}
|
||||
|
||||
void WalkForwardSystem::run(const KData& kdata, bool reset, bool resetAll) {
|
||||
SPEND_TIME(WalkForwardSystem_run);
|
||||
HKU_IF_RETURN(kdata.empty(), void());
|
||||
if (resetAll) {
|
||||
this->forceResetAll();
|
||||
|
Loading…
Reference in New Issue
Block a user