alphasift 0.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. alphasift/__init__.py +52 -0
  2. alphasift/__main__.py +7 -0
  3. alphasift/audit.py +191 -0
  4. alphasift/candidate_context.py +738 -0
  5. alphasift/cli.py +2797 -0
  6. alphasift/config.py +705 -0
  7. alphasift/context.py +672 -0
  8. alphasift/daily.py +1256 -0
  9. alphasift/daily_brief.py +593 -0
  10. alphasift/daily_report.py +1115 -0
  11. alphasift/daily_report_html.py +1257 -0
  12. alphasift/doctor.py +1123 -0
  13. alphasift/dsa.py +302 -0
  14. alphasift/dsa_adapter.py +178 -0
  15. alphasift/dsa_provider.py +192 -0
  16. alphasift/evaluate.py +2418 -0
  17. alphasift/filter.py +517 -0
  18. alphasift/hotspot.py +1713 -0
  19. alphasift/industry.py +959 -0
  20. alphasift/llm_client.py +349 -0
  21. alphasift/market_digest.py +284 -0
  22. alphasift/market_news.py +446 -0
  23. alphasift/market_regime.py +578 -0
  24. alphasift/markets.py +160 -0
  25. alphasift/mcp.py +720 -0
  26. alphasift/models.py +315 -0
  27. alphasift/normalize.py +113 -0
  28. alphasift/notify.py +2608 -0
  29. alphasift/overview.py +225 -0
  30. alphasift/pack.py +1470 -0
  31. alphasift/pack_features.py +431 -0
  32. alphasift/pattern_replay.py +1449 -0
  33. alphasift/patterns/bottom_volume_yang.yaml +32 -0
  34. alphasift/patterns/box_breakout.yaml +36 -0
  35. alphasift/patterns/double_bottom_breakout.yaml +38 -0
  36. alphasift/patterns/ma20_shrink_pullback.yaml +37 -0
  37. alphasift/patterns/shooting_star_confirm.yaml +49 -0
  38. alphasift/patterns/single_yang_hold.yaml +44 -0
  39. alphasift/patterns/steady_trend_breakout.yaml +39 -0
  40. alphasift/patterns/three_white_soldiers.yaml +72 -0
  41. alphasift/patterns/three_white_soldiers_pullback.yaml +91 -0
  42. alphasift/patterns.py +1233 -0
  43. alphasift/performance_history.py +297 -0
  44. alphasift/pipeline.py +1010 -0
  45. alphasift/post_analysis.py +337 -0
  46. alphasift/ranker.py +990 -0
  47. alphasift/report.py +379 -0
  48. alphasift/result_schema.py +179 -0
  49. alphasift/risk.py +452 -0
  50. alphasift/run_history.py +164 -0
  51. alphasift/scorer.py +597 -0
  52. alphasift/server.py +680 -0
  53. alphasift/snapshot.py +1025 -0
  54. alphasift/snapshot_us.py +280 -0
  55. alphasift/snapshot_yahoo.py +358 -0
  56. alphasift/source_guard.py +70 -0
  57. alphasift/source_history.py +306 -0
  58. alphasift/store.py +294 -0
  59. alphasift/strategies/balanced_alpha.yaml +76 -0
  60. alphasift/strategies/blue_chip_income.yaml +87 -0
  61. alphasift/strategies/capital_heat.yaml +74 -0
  62. alphasift/strategies/dual_low.yaml +80 -0
  63. alphasift/strategies/global_value.yaml +65 -0
  64. alphasift/strategies/low_volatility_quality.yaml +95 -0
  65. alphasift/strategies/momentum_quality.yaml +81 -0
  66. alphasift/strategies/oversold_reversal.yaml +75 -0
  67. alphasift/strategies/quality_value.yaml +80 -0
  68. alphasift/strategies/shrink_pullback.yaml +77 -0
  69. alphasift/strategies/us_momentum_quality.yaml +74 -0
  70. alphasift/strategies/volume_breakout.yaml +78 -0
  71. alphasift/strategy.py +1090 -0
  72. alphasift/strategy_cards.py +424 -0
  73. alphasift/strategy_templates.py +291 -0
  74. alphasift/timeutil.py +38 -0
  75. alphasift/valuation_kr.py +149 -0
  76. alphasift/workbench_ui.py +1051 -0
  77. alphasift-0.3.1.data/data/.env.example +151 -0
  78. alphasift-0.3.1.data/data/LICENSE +184 -0
  79. alphasift-0.3.1.data/data/SKILL.md +190 -0
  80. alphasift-0.3.1.data/data/agents/openai.yaml +7 -0
  81. alphasift-0.3.1.dist-info/METADATA +312 -0
  82. alphasift-0.3.1.dist-info/RECORD +86 -0
  83. alphasift-0.3.1.dist-info/WHEEL +5 -0
  84. alphasift-0.3.1.dist-info/entry_points.txt +2 -0
  85. alphasift-0.3.1.dist-info/licenses/LICENSE +184 -0
  86. alphasift-0.3.1.dist-info/top_level.txt +1 -0
alphasift/markets.py ADDED
@@ -0,0 +1,160 @@
1
+ # -*- coding: utf-8 -*-
2
+ """Market registry: what AlphaSift needs to know about each supported market.
3
+
4
+ China A-shares keep their dedicated source chain (sina / efinance / akshare /
5
+ EastMoney / Tushare). Every other market is served by the Yahoo Finance
6
+ screener, which works from overseas servers and CI runners and returns price,
7
+ market cap, PE/PB and currency for a whole region in a few requests.
8
+
9
+ Codes for non-CN markets are Yahoo symbols (``AAPL``, ``0700.HK``,
10
+ ``7203.T``, ``005930.KS``). They are already unique across markets, so no
11
+ extra namespace prefix is needed.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from dataclasses import dataclass
17
+ from datetime import date, datetime, time, timedelta
18
+ from zoneinfo import ZoneInfo
19
+
20
+
21
+ @dataclass(frozen=True)
22
+ class MarketSpec:
23
+ id: str
24
+ name: str
25
+ currency: str
26
+ timezone: str
27
+ # Yahoo screener region code; None means the market has its own chain.
28
+ yahoo_region: str | None = None
29
+ # Yahoo symbol suffixes used by this market's listings.
30
+ yahoo_suffixes: tuple[str, ...] = ()
31
+ # Universe floor in local currency, roughly USD 1B. It keeps the screener
32
+ # pull small and liquid; strategies can filter further.
33
+ universe_min_market_cap: float = 0.0
34
+ # Yahoo exchange codes to keep; empty means every exchange in the region.
35
+ # The US region is half OTC pink sheets (unsponsored foreign ordinaries
36
+ # like BMWKY), which crowd out listed names under the row cap.
37
+ yahoo_exchanges: tuple[str, ...] = ()
38
+ # A-share conventions (ST names, limit-up boards, EastMoney industries).
39
+ cn_rules: bool = False
40
+ # Offline daily bar pack supported for full-market vectorized screening.
41
+ supports_daily_pack: bool = False
42
+ # Local regular-session open (HH:MM). A run created before the open was
43
+ # priced off the previous close, so that day's bar is entirely post-entry.
44
+ session_open: str = "09:30"
45
+ # Local regular-session close (HH:MM). Today's bar only counts as a
46
+ # completed T+N bar once the session has closed.
47
+ session_close: str = "15:00"
48
+ # Index used as the T+N evaluation benchmark. CN uses Tencent's index
49
+ # K-line (Yahoo's 000300.SS history is broken); others use Yahoo.
50
+ benchmark: str = ""
51
+ benchmark_name: str = ""
52
+ # Approximate local units per USD. Only used to express liquidity floors
53
+ # (avg_amount_usd_min) in one currency across markets; a rough rate is
54
+ # enough for a floor, so it is not fetched live.
55
+ usd_rate: float = 1.0
56
+
57
+
58
+ MARKETS: dict[str, MarketSpec] = {
59
+ spec.id: spec
60
+ for spec in (
61
+ MarketSpec(
62
+ "cn", "China A-shares", "CNY", "Asia/Shanghai", cn_rules=True, supports_daily_pack=True,
63
+ benchmark="sh000300", benchmark_name="CSI 300", usd_rate=7.2,
64
+ ),
65
+ MarketSpec(
66
+ "us", "United States", "USD", "America/New_York", "us", (),
67
+ # Nasdaq GS/GM/CM, NYSE, NYSE American, NYSE Arca, Cboe BZX.
68
+ yahoo_exchanges=("NMS", "NGM", "NCM", "NYQ", "ASE", "PCX", "BTS"),
69
+ universe_min_market_cap=1e9,
70
+ session_close="16:00", benchmark="SPY", benchmark_name="S&P 500 (SPY)",
71
+ ),
72
+ MarketSpec(
73
+ "hk", "Hong Kong", "HKD", "Asia/Hong_Kong", "hk", ("HK",), 8e9,
74
+ session_close="16:00", benchmark="^HSI", benchmark_name="Hang Seng", usd_rate=7.8,
75
+ ),
76
+ MarketSpec(
77
+ "jp", "Japan", "JPY", "Asia/Tokyo", "jp", ("T",), 1.5e11,
78
+ session_open="09:00", session_close="15:30", benchmark="^N225", benchmark_name="Nikkei 225", usd_rate=150.0,
79
+ ),
80
+ MarketSpec(
81
+ "kr", "South Korea", "KRW", "Asia/Seoul", "kr", ("KS", "KQ"), 1.4e12,
82
+ session_open="09:00", session_close="15:30", benchmark="^KS11", benchmark_name="KOSPI", usd_rate=1400.0,
83
+ ),
84
+ MarketSpec(
85
+ "tw", "Taiwan", "TWD", "Asia/Taipei", "tw", ("TW", "TWO"), 3e10,
86
+ session_open="09:00", session_close="13:30", benchmark="^TWII", benchmark_name="TAIEX", usd_rate=30.0,
87
+ ),
88
+ MarketSpec(
89
+ "in", "India", "INR", "Asia/Kolkata", "in", ("NS", "BO"), 8.5e10,
90
+ session_open="09:15", session_close="15:30", benchmark="^NSEI", benchmark_name="Nifty 50", usd_rate=85.0,
91
+ ),
92
+ )
93
+ }
94
+
95
+ # Suffixes that mark a non-CN Yahoo listing. A-share Yahoo/vendor suffixes
96
+ # (.SS/.SH/.SZ/.BJ) are deliberately absent so they still normalize to 6 digits.
97
+ FOREIGN_YAHOO_SUFFIXES: frozenset[str] = frozenset(
98
+ suffix for spec in MARKETS.values() for suffix in spec.yahoo_suffixes
99
+ )
100
+
101
+
102
+ def supported_markets() -> list[str]:
103
+ return list(MARKETS)
104
+
105
+
106
+ def get_market(market: str) -> MarketSpec:
107
+ key = (market or "").strip().lower()
108
+ try:
109
+ return MARKETS[key]
110
+ except KeyError:
111
+ raise ValueError(
112
+ f"Unsupported market: {market!r} (supported: {', '.join(MARKETS)})"
113
+ ) from None
114
+
115
+
116
+ def has_foreign_yahoo_suffix(code: str) -> bool:
117
+ """True for symbols like ``0700.HK`` or ``005930.KS`` that must keep their suffix."""
118
+ head, sep, suffix = (code or "").rpartition(".")
119
+ return bool(sep and head and suffix.upper() in FOREIGN_YAHOO_SUFFIXES)
120
+
121
+
122
+ # Daily bars are final some time after the close; vendors can lag a little.
123
+ _CLOSE_SETTLE_SECONDS = 30 * 60
124
+ # A screening batch takes minutes; stop reusing caches shortly before the open
125
+ # so candidates processed after it do not mix in pre-open data.
126
+ _PRE_OPEN_MARGIN_SECONDS = 15 * 60
127
+
128
+
129
+ def latest_settled_close(market: str, now: datetime | None = None) -> tuple[date, float] | None:
130
+ """Latest session whose close has settled, and seconds since it settled.
131
+
132
+ None during the session (and just before the open): today's bar is not
133
+ final, so screening must not reuse cached histories. Weekends step back
134
+ to Friday; exchange holidays are not known here, which only makes reuse
135
+ stricter (a cached history must still reach the computed session date).
136
+ """
137
+ spec = get_market(market)
138
+ tz = ZoneInfo(spec.timezone)
139
+ local = (now or datetime.now(tz)).astimezone(tz)
140
+ open_h, open_m = (int(part) for part in spec.session_open.split(":"))
141
+ close_h, close_m = (int(part) for part in spec.session_close.split(":"))
142
+ day = local.date()
143
+ open_at = datetime.combine(day, time(open_h, open_m), tzinfo=tz)
144
+ if local.weekday() < 5:
145
+ if open_at.timestamp() - _PRE_OPEN_MARGIN_SECONDS <= local.timestamp() < datetime.combine(
146
+ day, time(close_h, close_m), tzinfo=tz
147
+ ).timestamp():
148
+ return None
149
+ if local.timestamp() < open_at.timestamp():
150
+ day -= timedelta(days=1)
151
+ else:
152
+ day -= timedelta(days=1)
153
+ while day.weekday() >= 5:
154
+ day -= timedelta(days=1)
155
+ settled = datetime.combine(day, time(close_h, close_m), tzinfo=tz).timestamp() + _CLOSE_SETTLE_SECONDS
156
+ # Epoch seconds, not wall-clock differences, so DST changes do not skew it.
157
+ elapsed = local.timestamp() - settled
158
+ if elapsed <= 0:
159
+ return None
160
+ return day, elapsed