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/overview.py ADDED
@@ -0,0 +1,225 @@
1
+ # -*- coding: utf-8 -*-
2
+ """UI/agent overview payload for AlphaSift."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from dataclasses import asdict
7
+ from datetime import datetime, timezone
8
+ from typing import Any
9
+
10
+ from alphasift.config import Config
11
+ from alphasift.doctor import doctor_data_sources
12
+ from alphasift.performance_history import build_strategy_performance_summary
13
+ from alphasift.run_history import build_strategy_run_summary
14
+ from alphasift.source_history import build_data_source_history
15
+ from alphasift.store import list_saved_runs
16
+ from alphasift.strategy import list_strategies, match_strategies, strategy_facets_from_infos
17
+ from alphasift.strategy_cards import build_strategy_cards_from_parts
18
+
19
+
20
+ def build_overview(
21
+ config: Config,
22
+ *,
23
+ strategy_name: str | None = None,
24
+ runs_limit: int = 5,
25
+ live_data_check: bool = False,
26
+ strategy_match: dict[str, Any] | None = None,
27
+ match_limit: int = 5,
28
+ ) -> dict[str, Any]:
29
+ """Build one compact payload for dashboards, agents, and notification surfaces."""
30
+ strategies = list_strategies(config.strategies_dir)
31
+ doctor = doctor_data_sources(
32
+ config,
33
+ run_live=live_data_check,
34
+ strategy_name=strategy_name,
35
+ all_strategies=strategy_name is None,
36
+ ).to_dict()
37
+ recent_runs = list_saved_runs(
38
+ data_dir=config.data_dir,
39
+ limit=runs_limit,
40
+ strategy=strategy_name,
41
+ )
42
+ run_history = build_strategy_run_summary(
43
+ data_dir=config.data_dir,
44
+ limit=max(int(runs_limit), 20),
45
+ strategy=strategy_name,
46
+ )
47
+ source_history = build_data_source_history(
48
+ data_dir=config.data_dir,
49
+ limit=max(int(runs_limit), 20),
50
+ strategy=strategy_name,
51
+ )
52
+ performance = build_strategy_performance_summary(
53
+ data_dir=config.data_dir,
54
+ limit=max(int(runs_limit), 20),
55
+ strategy=strategy_name,
56
+ )
57
+ card_strategies = [
58
+ item
59
+ for item in strategies
60
+ if not strategy_name or item.name == strategy_name
61
+ ]
62
+ match_kwargs = dict(strategy_match or {})
63
+ strategy_matches = []
64
+ if _has_match_criteria(match_kwargs):
65
+ strategy_matches = match_strategies(
66
+ config.strategies_dir,
67
+ **match_kwargs,
68
+ limit=match_limit,
69
+ )
70
+
71
+ payload = {
72
+ "schema_version": 1,
73
+ "generated_at": datetime.now(timezone.utc).isoformat(),
74
+ "summary": {
75
+ "strategy_count": len(strategies),
76
+ "daily_strategy_count": sum(1 for item in strategies if item.requires_daily_features),
77
+ "data_source_status": doctor.get("status"),
78
+ "strategy_match_count": len(strategy_matches),
79
+ "recent_run_count": len(recent_runs),
80
+ "live_data_check": bool(live_data_check),
81
+ "strategy_filter": strategy_name or "",
82
+ },
83
+ "strategy_groups": _strategy_groups(strategies),
84
+ "strategy_facets": strategy_facets_from_infos(strategies),
85
+ "strategy_cards": build_strategy_cards_from_parts(
86
+ card_strategies,
87
+ strategy_coverage=doctor.get("strategy_coverage", []),
88
+ run_history_summary=run_history,
89
+ performance_summary=performance,
90
+ live_data_check=live_data_check,
91
+ strategy_filter=strategy_name or "",
92
+ ),
93
+ "strategy_matches": strategy_matches,
94
+ "data_sources": {
95
+ "status": doctor.get("status"),
96
+ "config": doctor.get("config", {}),
97
+ "health_summary": doctor.get("health_summary", {}),
98
+ "freshness_summary": doctor.get("freshness_summary", {}),
99
+ "snapshot_quality": (doctor.get("snapshot", {}) or {}).get("quality_summary", {}),
100
+ "strategy_requirements": doctor.get("strategy_requirements", {}),
101
+ "strategy_coverage": doctor.get("strategy_coverage", []),
102
+ "strategy_readiness_summary": doctor.get("strategy_readiness_summary", {}),
103
+ "recommendations": doctor.get("recommendations", []),
104
+ },
105
+ "run_history_summary": run_history,
106
+ "data_source_history": source_history,
107
+ "performance_summary": performance,
108
+ "recent_runs": recent_runs,
109
+ "next_actions": _next_actions(
110
+ doctor=doctor,
111
+ recent_runs=recent_runs,
112
+ source_history=source_history,
113
+ performance_summary=performance,
114
+ strategy_matches=strategy_matches,
115
+ strategy_name=strategy_name,
116
+ live_data_check=live_data_check,
117
+ ),
118
+ }
119
+ return payload
120
+
121
+
122
+ def _has_match_criteria(criteria: dict[str, Any]) -> bool:
123
+ return any(
124
+ bool(criteria.get(key))
125
+ for key in (
126
+ "risk_profile",
127
+ "holding_period",
128
+ "execution_style",
129
+ "market_regime",
130
+ "capital_profile",
131
+ "data_requirements",
132
+ "tags",
133
+ "category",
134
+ )
135
+ ) or criteria.get("daily_required") is not None or bool(criteria.get("strict"))
136
+
137
+
138
+ def _strategy_groups(strategies: list) -> dict[str, list[dict[str, object]]]:
139
+ return {
140
+ "by_category": _group_strategy_names(strategies, lambda item: item.category),
141
+ "by_risk_profile": _group_strategy_names(
142
+ strategies,
143
+ lambda item: str(item.style.get("risk_profile") or "unknown"),
144
+ ),
145
+ "by_holding_period": _group_strategy_names(
146
+ strategies,
147
+ lambda item: str(item.style.get("holding_period") or "unknown"),
148
+ ),
149
+ "by_data_requirement": _group_by_many(strategies, lambda item: item.data_requirements),
150
+ }
151
+
152
+
153
+ def _group_strategy_names(strategies: list, key_fn) -> list[dict[str, object]]:
154
+ groups: dict[str, list[str]] = {}
155
+ for item in strategies:
156
+ key = str(key_fn(item) or "unknown")
157
+ groups.setdefault(key, []).append(item.name)
158
+ return _group_payload(groups)
159
+
160
+
161
+ def _group_by_many(strategies: list, values_fn) -> list[dict[str, object]]:
162
+ groups: dict[str, list[str]] = {}
163
+ for item in strategies:
164
+ values = list(values_fn(item) or []) or ["unknown"]
165
+ for value in values:
166
+ groups.setdefault(str(value), []).append(item.name)
167
+ return _group_payload(groups)
168
+
169
+
170
+ def _group_payload(groups: dict[str, list[str]]) -> list[dict[str, object]]:
171
+ return [
172
+ {"name": name, "count": len(names), "strategies": sorted(names)}
173
+ for name, names in sorted(groups.items(), key=lambda item: (-len(item[1]), item[0]))
174
+ ]
175
+
176
+
177
+ def _next_actions(
178
+ *,
179
+ doctor: dict[str, Any],
180
+ recent_runs: list[dict[str, object]],
181
+ source_history: dict[str, object],
182
+ performance_summary: dict[str, object],
183
+ strategy_matches: list[dict[str, object]],
184
+ strategy_name: str | None,
185
+ live_data_check: bool,
186
+ ) -> list[str]:
187
+ actions: list[str] = []
188
+ if not live_data_check:
189
+ actions.append("Run `alphasift overview --live-data-check --explain` before relying on fresh data.")
190
+ actions.extend(str(item) for item in doctor.get("recommendations", []) or [])
191
+ actions.extend(_source_history_actions(source_history))
192
+ actions.extend(_performance_actions(performance_summary, has_recent_runs=bool(recent_runs)))
193
+ if strategy_matches:
194
+ top = strategy_matches[0]
195
+ actions.append(f"Try `alphasift screen {top.get('name')} --explain` for the top matched strategy.")
196
+ elif strategy_name:
197
+ actions.append(f"Try `alphasift screen {strategy_name} --explain` to validate the focused strategy.")
198
+ if not recent_runs:
199
+ actions.append("Run `alphasift screen <strategy> --save-run` to populate the recent-run panel.")
200
+ return list(dict.fromkeys(actions))
201
+
202
+
203
+ def _source_history_actions(source_history: dict[str, object]) -> list[str]:
204
+ watchlist = source_history.get("watchlist") or []
205
+ if not isinstance(watchlist, list):
206
+ return []
207
+ actions: list[str] = []
208
+ for item in watchlist[:2]:
209
+ if isinstance(item, dict):
210
+ actions.extend(str(action) for action in item.get("next_actions", []) or [])
211
+ return actions
212
+
213
+
214
+ def _performance_actions(performance_summary: dict[str, object], *, has_recent_runs: bool) -> list[str]:
215
+ if not has_recent_runs and not int(performance_summary.get("evaluation_count") or 0):
216
+ return []
217
+ summary = performance_summary.get("summary") or {}
218
+ if not isinstance(summary, dict):
219
+ return []
220
+ return [str(item) for item in summary.get("next_actions", []) or []]
221
+
222
+
223
+ def overview_to_jsonable(payload: dict[str, Any]) -> dict[str, Any]:
224
+ """Normalize dataclass-like values if callers extend this payload later."""
225
+ return asdict(payload) if hasattr(payload, "__dataclass_fields__") else payload