-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_sample_chart.py
More file actions
50 lines (44 loc) · 2.19 KB
/
Copy path_sample_chart.py
File metadata and controls
50 lines (44 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""用新 below_axis 接口(箭头自K线底部low向下画)生成单张示例图供用户查看。"""
import os, sys, asyncio
os.environ['NO_PROXY'] = '*'
for _k in ('HTTP_PROXY','HTTPS_PROXY','http_proxy','https_proxy','ALL_PROXY','all_proxy'):
os.environ.pop(_k, None)
sys.stdout.reconfigure(encoding='utf-8')
from src.data.history_fetcher import DeepHistoryFetcher
from src.analysis.strategies.tiger_strategy.config import TigerConfig, ReturnConfig
from src.analysis.strategies.tiger_strategy.backtest import TigerBacktester
from src.analysis.strategies.tiger_strategy.recall import write_one_stock
# calibrated 预设(与 trades.csv 同配置)
cfg = TigerConfig(
first_change_pct=6.0, volume_avg_days=5, volume_mult=1.2,
max_interval_days=20, retest_volume_mult=1.0, breakout_above_avg=False,
washout_enabled=True, washout_mode='depth', washout_min_drawdown_pct=-3.0,
bottom_enabled=True, bottom_lookback=60, bottom_quantile=0.6,
)
ret = ReturnConfig(buy_mode='b1_open', sell_mode='close', forward_days=[1,2,3], cost_bps=5.0)
code = '300873'; name = '海晨股份'; want_signal = '2026-06-29'
print(f"拉取 {code} 深历史 …")
fetcher = DeepHistoryFetcher(max_concurrent=5, count=320)
hm = asyncio.run(fetcher.fetch_many([code]))
hist = hm.get(code)
if hist is None:
print("取历史失败"); sys.exit(1)
print(f"历史: {len(hist.closes)} 根")
bt = TigerBacktester(cfg, ret)
trades, stats = bt.run(hm, {code: name}, 320)
print(f"回测得 {len(trades)} 个信号")
t = next((x for x in trades if x.signal_date == want_signal), None)
if t is None and trades:
t = trades[0]; print(f"未命中 {want_signal},改用首信号 {t.signal_date}")
if t is None:
print("无信号"); sys.exit(1)
out_dir = 'src/analysis/strategies/tiger_strategy/recall_answer/_sample_below_axis'
os.makedirs(out_dir, exist_ok=True)
png, md = write_one_stock(t, hist, out_dir, cfg, ret)
print(f"[OK] 示例图: {png}")
print(f" A={t.a_date} B={t.signal_date} 买入={t.buy_date}@{t.buy_price:.2f} 量比={t.vol_ratio:.2f}x")
for f in (1,2,3):
i = t.forward.get(f)
if i: print(f" f{f}: 卖出{i['sell_date']}@{i['sell_price']:.2f} 收益{i['ret_pct']:+.2f}%")