-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_single_ticker.py
More file actions
89 lines (68 loc) · 2.98 KB
/
Copy path01_single_ticker.py
File metadata and controls
89 lines (68 loc) · 2.98 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
"""Every pattern currently firing on one ticker, next to its track record.
No API key needed.
python examples/01_single_ticker.py
python examples/01_single_ticker.py NVDA 1h
"""
from __future__ import annotations
import sys
from honest_signals import check_watchlist
from honest_signals.models import Report
from honest_signals.stats import Verdict
def main() -> int:
ticker = sys.argv[1] if len(sys.argv) > 1 else "AAPL"
timeframe = sys.argv[2] if len(sys.argv) > 2 else "1d"
report = check_watchlist([ticker], timeframe=timeframe, within_bars=10)
if report.errors:
for symbol, message in report.errors.items():
print(f"could not fetch {symbol}: {message}")
return 1
print(f"{ticker} on {timeframe}: {len(report.signals)} patterns in the last 10 bars\n")
for signal in report.ranked():
print(f" {signal.pattern} ({signal.direction}), {signal.bars_ago} bars ago")
if signal.verdict is Verdict.NO_DATA:
print(" no backtested record for this pattern -- treat it as decoration\n")
continue
print(
f" went its stated direction {signal.hit_rate:.1%} of the time "
f"over {signal.sample_size:,} historical occurrences"
)
if signal.verdict is Verdict.NO_BASELINE:
print(
" but the response carried no pattern-free baseline for this cell, "
"so there is nothing to compare that against."
)
print(
f" -> unmeasured. Reading {signal.hit_rate:.1%} as evidence for or "
"against this pattern would just be reading the market's drift.\n"
)
continue
lift = signal.lift
assert lift is not None
print(
f" with no pattern at all, price went that way {lift.baseline:.1%} "
f"of the time ({lift.baseline_n:,} windows)"
)
print(
f" so the pattern itself is worth {lift.lift_pp:+.1f}pp "
f"+/-{lift.ci95_pp:.1f}pp (horizon {signal.horizon} bars)"
)
if signal.verdict is Verdict.BEATS_BASELINE:
print(f" -> clears its baseline by {lift.lift_pp:+.1f} points\n")
elif signal.verdict is Verdict.TRAILS_BASELINE:
print(
f" -> falls {abs(lift.lift_pp):.1f} points SHORT of its baseline. "
"Doing nothing beat this pattern.\n"
)
else:
print(" -> the interval on that difference contains zero. No edge.\n")
print(summary(report))
return 0
def summary(report: Report) -> str:
beats = len(report.by_verdict(Verdict.BEATS_BASELINE))
unmeasured = int(round(report.unmeasured_share * len(report.signals)))
return (
f"{beats} of {len(report.signals)} signals clear their own baseline by more "
f"than the interval on the difference. {unmeasured} could not be measured."
)
if __name__ == "__main__":
raise SystemExit(main())