第一版策略
This commit is contained in:
@@ -18,9 +18,11 @@ from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
from collections import defaultdict
|
||||
@@ -261,14 +263,14 @@ def run_grid_search(
|
||||
print(f"✓ period={int(row['period']):4d}, std={float(row['std']):7.2f} | "
|
||||
f"收益: {row['ret_pct']:+7.2f}% | 回撤: {row['max_dd_pct']:6.2f}% | "
|
||||
f"夏普: {row['sharpe']:7.3f} | 交易: {int(row['n_trades']):6d} | "
|
||||
f"评分: {row['stable_score']:7.1f}")
|
||||
f"评分: {row['stable_score']:7.1f}", flush=True)
|
||||
rows.extend(res)
|
||||
done_periods += 1
|
||||
done_combos += len(task[1])
|
||||
maybe_save(done_periods)
|
||||
if done_periods % max(1, total_periods // 20) == 0 or done_periods == total_periods:
|
||||
elapsed = time.time() - start
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s")
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s", flush=True)
|
||||
else:
|
||||
done_periods = 0
|
||||
done_combos = 0
|
||||
@@ -287,14 +289,14 @@ def run_grid_search(
|
||||
print(f"✓ period={int(row['period']):4d}, std={float(row['std']):7.2f} | "
|
||||
f"收益: {row['ret_pct']:+7.2f}% | 回撤: {row['max_dd_pct']:6.2f}% | "
|
||||
f"夏普: {row['sharpe']:7.3f} | 交易: {int(row['n_trades']):6d} | "
|
||||
f"评分: {row['stable_score']:7.1f}")
|
||||
f"评分: {row['stable_score']:7.1f}", flush=True)
|
||||
rows.extend(res)
|
||||
done_periods += 1
|
||||
done_combos += len(stds)
|
||||
maybe_save(done_periods)
|
||||
if done_periods % max(1, total_periods // 20) == 0 or done_periods == total_periods:
|
||||
elapsed = time.time() - start
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s")
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s", flush=True)
|
||||
except (PermissionError, OSError) as e:
|
||||
print(f"多进程不可用 ({e}),改用单进程...")
|
||||
_init_worker(df_path, df_1m_path, use_1m, step_min)
|
||||
@@ -307,14 +309,14 @@ def run_grid_search(
|
||||
print(f"✓ period={int(row['period']):4d}, std={float(row['std']):7.2f} | "
|
||||
f"收益: {row['ret_pct']:+7.2f}% | 回撤: {row['max_dd_pct']:6.2f}% | "
|
||||
f"夏普: {row['sharpe']:7.3f} | 交易: {int(row['n_trades']):6d} | "
|
||||
f"评分: {row['stable_score']:7.1f}")
|
||||
f"评分: {row['stable_score']:7.1f}", flush=True)
|
||||
rows.extend(res)
|
||||
done_periods += 1
|
||||
done_combos += len(task[1])
|
||||
maybe_save(done_periods)
|
||||
if done_periods % max(1, total_periods // 20) == 0 or done_periods == total_periods:
|
||||
elapsed = time.time() - start
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s")
|
||||
print(f"进度 {done_combos}/{total_combos} ({done_periods}/{total_periods} periods), 用时 {elapsed:.0f}s", flush=True)
|
||||
|
||||
if ckpt_path and meta_path and meta and rows:
|
||||
save_checkpoint(ckpt_path, meta_path, meta, rows)
|
||||
@@ -325,6 +327,14 @@ def run_grid_search(
|
||||
|
||||
|
||||
def main():
|
||||
# Windows 兼容的无缓冲设置
|
||||
if os.name == 'nt': # Windows
|
||||
# Windows 上通过重定向来禁用缓冲
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', line_buffering=True)
|
||||
else: # Linux/macOS
|
||||
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 1, encoding='utf-8')
|
||||
|
||||
parser = argparse.ArgumentParser(description="布林带全参数网格搜索 (1-1000, 0.5-1000)")
|
||||
parser.add_argument("-p", "--period", default="5m", choices=["5m", "15m", "30m"])
|
||||
parser.add_argument("--start", default="2020-01-01")
|
||||
|
||||
Reference in New Issue
Block a user