tokio-ai 0.1.0__tar.gz

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 (37) hide show
  1. tokio_ai-0.1.0/.env.example +12 -0
  2. tokio_ai-0.1.0/.github/workflows/test.yml +21 -0
  3. tokio_ai-0.1.0/.gitignore +8 -0
  4. tokio_ai-0.1.0/CONTRIBUTING.md +47 -0
  5. tokio_ai-0.1.0/LICENSE +21 -0
  6. tokio_ai-0.1.0/PKG-INFO +161 -0
  7. tokio_ai-0.1.0/README.md +134 -0
  8. tokio_ai-0.1.0/SECURITY.md +29 -0
  9. tokio_ai-0.1.0/docs/index.html +119 -0
  10. tokio_ai-0.1.0/pyproject.toml +42 -0
  11. tokio_ai-0.1.0/scripts/__init__.py +0 -0
  12. tokio_ai-0.1.0/scripts/refresh_sp500.py +56 -0
  13. tokio_ai-0.1.0/src/tokio_ai/__init__.py +4 -0
  14. tokio_ai-0.1.0/src/tokio_ai/_env.py +18 -0
  15. tokio_ai-0.1.0/src/tokio_ai/agent/__init__.py +0 -0
  16. tokio_ai-0.1.0/src/tokio_ai/agent/loop.py +132 -0
  17. tokio_ai-0.1.0/src/tokio_ai/agent/system_prompt.py +29 -0
  18. tokio_ai-0.1.0/src/tokio_ai/agent/tool_schemas.py +163 -0
  19. tokio_ai-0.1.0/src/tokio_ai/cli.py +41 -0
  20. tokio_ai-0.1.0/src/tokio_ai/data/sp500.csv +504 -0
  21. tokio_ai-0.1.0/src/tokio_ai/rigor/__init__.py +0 -0
  22. tokio_ai-0.1.0/src/tokio_ai/rigor/ledger.py +63 -0
  23. tokio_ai-0.1.0/src/tokio_ai/rigor/provenance.py +21 -0
  24. tokio_ai-0.1.0/src/tokio_ai/rigor/stats.py +91 -0
  25. tokio_ai-0.1.0/src/tokio_ai/tools/__init__.py +0 -0
  26. tokio_ai-0.1.0/src/tokio_ai/tools/filings.py +85 -0
  27. tokio_ai-0.1.0/src/tokio_ai/tools/hypothesis.py +20 -0
  28. tokio_ai-0.1.0/src/tokio_ai/tools/patterns.py +91 -0
  29. tokio_ai-0.1.0/src/tokio_ai/tools/prices.py +99 -0
  30. tokio_ai-0.1.0/src/tokio_ai/tools/screener.py +106 -0
  31. tokio_ai-0.1.0/tests/__init__.py +0 -0
  32. tokio_ai-0.1.0/tests/test_filings.py +125 -0
  33. tokio_ai-0.1.0/tests/test_ledger.py +45 -0
  34. tokio_ai-0.1.0/tests/test_patterns.py +73 -0
  35. tokio_ai-0.1.0/tests/test_prices.py +107 -0
  36. tokio_ai-0.1.0/tests/test_screener.py +66 -0
  37. tokio_ai-0.1.0/tests/test_stats.py +48 -0
@@ -0,0 +1,12 @@
1
+ # Required: any OpenAI-compatible chat-completions endpoint works.
2
+ # Default target is NVIDIA's free NIM catalog: https://build.nvidia.com (free API key, no card)
3
+ OPENAI_API_KEY=
4
+ # OPENAI_BASE_URL=https://integrate.api.nvidia.com/v1
5
+
6
+ # Required for the SEC filings tool: SEC's fair-access policy requires a
7
+ # descriptive User-Agent identifying you. No signup needed, just fill this in.
8
+ # https://www.sec.gov/os/webmaster-faq#developers
9
+ TOKIO_AI_USER_AGENT=TokIO-AI you@example.com
10
+
11
+ # Optional: override the default model (see README for tool-calling-reliability notes)
12
+ # TOKIO_AI_MODEL=nvidia/llama-3.3-nemotron-super-49b-v1.5
@@ -0,0 +1,21 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: pip install -e ".[dev]"
21
+ - run: python -m pytest -q
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ .pytest_cache/
5
+ .env
6
+ build/
7
+ dist/
8
+ vault/
@@ -0,0 +1,47 @@
1
+ # Contributing
2
+
3
+ Thanks for looking at this. A few things that'll make a PR easy to merge:
4
+
5
+ ## Ground rules
6
+
7
+ - **No hallucinated data.** Tickers, sector membership, filing data, price
8
+ history -- all of it has to come from a real source (see `tools/`), never
9
+ invented or recalled from a model's memory. This is the one rule that
10
+ isn't negotiable; it's the entire reason this project exists.
11
+ - **New tools need tests.** If a function does pure logic (parsing, bucketing,
12
+ statistics), it should have a deterministic unit test with no network
13
+ call -- see `tests/test_patterns.py` or `tests/test_prices.py` for the
14
+ pattern (network-dependent fetch functions are the one thing that's fine
15
+ to leave untested in CI; verify those live instead).
16
+ - **Don't add a dependency to save a few lines of stdlib code.** This
17
+ project is deliberately light on dependencies (`openai` is the only
18
+ required one). If you're tempted to reach for a library, check whether
19
+ `urllib`/`statistics`/`concurrent.futures` already covers it.
20
+
21
+ ## Running things locally
22
+
23
+ ```bash
24
+ pip install -e ".[dev]"
25
+ python -m pytest # full suite, no network, no API key needed
26
+ ```
27
+
28
+ To exercise the live agent loop, copy `.env.example` to `.env` and fill in
29
+ a free key from https://build.nvidia.com (or any other OpenAI-compatible
30
+ endpoint).
31
+
32
+ ## Adding a new tool
33
+
34
+ 1. Pure logic goes in `tools/your_thing.py`, with the network call (if any)
35
+ as thin as possible so the logic underneath it is testable in isolation.
36
+ 2. Add a tool schema in `agent/tool_schemas.py` and wire the dispatch in
37
+ `agent/loop.py`.
38
+ 3. If the tool answers a class of question the model would otherwise
39
+ answer by guessing or hand-crunching raw data, say so explicitly in the
40
+ tool's description and in `agent/system_prompt.py` -- that's usually the
41
+ whole point of adding it.
42
+
43
+ ## Reporting a bug
44
+
45
+ If you hit a bad result (wrong number, hallucinated fact, tool that should
46
+ have fired but didn't), open an issue with the exact prompt you used. This
47
+ project cares more about honest failure reports than clean-looking demos.
tokio_ai-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 JordyDA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,161 @@
1
+ Metadata-Version: 2.4
2
+ Name: tokio-ai
3
+ Version: 0.1.0
4
+ Summary: An open-source financial research agent that runs every claim through honest statistical testing before trusting it.
5
+ Project-URL: Homepage, https://github.com/jordanahern2009-svg/Tokio-ai
6
+ Project-URL: Repository, https://github.com/jordanahern2009-svg/Tokio-ai
7
+ Project-URL: Issues, https://github.com/jordanahern2009-svg/Tokio-ai/issues
8
+ Author: Jordan Ahern
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: algorithmic-trading,finance,hypothesis-testing,llm-agent,statistics
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Topic :: Office/Business :: Financial :: Investment
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: openai>=1.50.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == 'dev'
26
+ Description-Content-Type: text/markdown
27
+
28
+ # TokIO AI
29
+
30
+ [![tests](https://github.com/jordanahern2009-svg/Tokio-ai/actions/workflows/test.yml/badge.svg)](https://github.com/jordanahern2009-svg/Tokio-ai/actions/workflows/test.yml)
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
32
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](pyproject.toml)
33
+
34
+ An open-source financial research agent that treats "the data supports this"
35
+ as a claim to be tested, not a vibe to be trusted.
36
+
37
+ Give it a ticker, a filing, or a plain-English trading hypothesis. It pulls
38
+ real data (price history, SEC filings) and, before it will tell you a
39
+ pattern is real, it runs the comparison through a permutation test, checks
40
+ the sample size against a hard floor, and corrects for every other
41
+ hypothesis you've asked it to test in the same conversation. Most AI
42
+ stock-chat tools will confidently describe a pattern in a handful of data
43
+ points. This one is built to tell you when it can't.
44
+
45
+ ## Why this exists
46
+
47
+ Generic LLM agents are commoditized -- anyone can wrap an LLM in a chat loop
48
+ and call it an agent. What isn't commoditized is discipline: most retail
49
+ (and plenty of professional) research fails because someone eyeballs a mean,
50
+ sees a gap, and calls it an edge without asking how likely that gap was to
51
+ appear by chance. The rigor layer here (`tokio_ai.rigor`) generalizes a
52
+ hypothesis-testing discipline actually used across real trading research
53
+ projects -- see `rigor/stats.py` and `rigor/ledger.py` for the permutation
54
+ test, minimum-sample gate, and Bonferroni/Benjamini-Hochberg multiple-testing
55
+ correction that every claim has to pass through.
56
+
57
+ ## What it can do today (v0)
58
+
59
+ - Pull daily OHLCV price history for any ticker (Yahoo Finance, no key)
60
+ - Pull recent SEC filings for any ticker (EDGAR, no key)
61
+ - Rank the real S&P 500 by trailing return, with optional GICS sector
62
+ filtering -- handles open-ended asks like "what are the best performing
63
+ stocks" without requiring you to already know a ticker or sector
64
+ - Test whether a simple technical condition (a big daily move, a gap at the
65
+ open, unusual volume) actually predicts what happens next -- fetches,
66
+ buckets, and runs the permutation test in one call, not via the model
67
+ eyeballing raw numbers
68
+ - Run a rigorous two-sided permutation test comparing any two groups of
69
+ numbers you already have, with automatic multiple-testing correction
70
+ across everything tested in the session
71
+ - Chat with it via a CLI; it decides when to call which tool
72
+
73
+ ## What it explicitly does not do
74
+
75
+ - Give investment advice or pick stocks
76
+ - Execute trades
77
+ - Pretend a small or cherry-picked sample proves anything
78
+
79
+ ## Quickstart
80
+
81
+ ```bash
82
+ pip install -e ".[dev]"
83
+ cp .env.example .env
84
+ # fill in OPENAI_API_KEY (a free key from https://build.nvidia.com works out of the box)
85
+ # and TOKIO_AI_USER_AGENT in .env
86
+ python -m tokio_ai.cli
87
+ ```
88
+
89
+ ```
90
+ > Pull AAPL's price history and tell me the most recent closing price.
91
+ > Get NVDA's recent 10-K and 10-Q filings.
92
+ ```
93
+
94
+ Run the test suite (no API key needed, no network calls):
95
+
96
+ ```bash
97
+ python -m pytest
98
+ ```
99
+
100
+ ## Architecture
101
+
102
+ - `tokio_ai/rigor/` -- pure-Python statistics engine (permutation testing,
103
+ multiple-testing correction, session-level test ledger). Fully unit
104
+ tested, zero dependencies beyond the standard library.
105
+ - `tokio_ai/tools/` -- data ingest (Yahoo price history, SEC EDGAR filings,
106
+ a bundled real S&P 500 + GICS sector snapshot) and the agent-facing
107
+ screening/pattern-testing/hypothesis-testing tools.
108
+ - `tokio_ai/agent/` -- the OpenAI-compatible tool-use loop (works against
109
+ any provider with that API shape; defaults to NVIDIA's free NIM catalog),
110
+ system prompt, and tool schemas.
111
+ - `tokio_ai/cli.py` -- interactive chat entry point.
112
+
113
+ **On language choice:** this is pure Python for now. The rigor engine (many
114
+ permutation-test iterations over numeric arrays) is the one part of this
115
+ codebase that's a plausible candidate for a Rust extension if it ever
116
+ becomes an actual measured bottleneck -- but the agent loop is I/O-bound on
117
+ LLM API calls, not local compute, so a polyglot rewrite ahead of a real
118
+ performance problem would just be added build complexity for no benefit.
119
+ Python first, optimize what's proven slow, not what looks slow.
120
+
121
+ ## Status
122
+
123
+ Early and under active development. The rigor engine and data-ingest tools
124
+ are tested against live sources. The agent loop has been verified
125
+ end-to-end against NVIDIA's free NIM catalog (`nvidia/llama-3.3-nemotron-super-49b-v1.5`
126
+ by default) -- real tool calls, real data, correct multi-turn answers.
127
+
128
+ **Known limitation:** the free tier has inconsistent latency (observed
129
+ anywhere from ~5s to 90s+ for the same model/prompt shape). That's the
130
+ tradeoff for "runs with zero-cost credentials out of the box." If you have
131
+ a paid OpenAI-compatible key with better SLAs, point `OPENAI_BASE_URL` /
132
+ `OPENAI_API_KEY` / `TOKIO_AI_MODEL` at it and nothing else changes.
133
+
134
+ Earlier versions asked the agent to manually crunch raw price history inline
135
+ for "does X predict Y"-style questions, which was unreliable on any LLM
136
+ backend (not specific to this one) -- that kind of bucketing belongs in a
137
+ Python tool, not the model's own token-by-token reasoning over a big JSON
138
+ blob. `test_return_pattern` and `top_performing_stocks` now do that
139
+ fetch+compute work in Python for the common cases (a technical condition
140
+ predicting forward returns; ranking stocks by trailing performance). If you
141
+ ask something shaped differently enough that neither tool fits, the model
142
+ may still fall back to reasoning over raw data by hand -- treat that path
143
+ as unreliable until there's a dedicated tool for it.
144
+
145
+ ### Example
146
+
147
+ ```
148
+ > Test whether AAPL days that gap up more than 2% at the open tend to keep
149
+ drifting up over the next 5 trading days, using 10 years of history.
150
+
151
+ The test found a statistically significant pattern (p=0.0050 after
152
+ correction), but in the opposite direction of the initial hypothesis. AAPL
153
+ days with gaps >2% at the open saw an average -1.31% return over the next 5
154
+ trading days, significantly underperforming the baseline. This suggests
155
+ large upward gaps historically preceded short-term weakness (gap-fade), not
156
+ momentum continuation. (data window: 2016-08-01 to 2026-07-31)
157
+ ```
158
+
159
+ ## License
160
+
161
+ MIT -- see [LICENSE](LICENSE).
@@ -0,0 +1,134 @@
1
+ # TokIO AI
2
+
3
+ [![tests](https://github.com/jordanahern2009-svg/Tokio-ai/actions/workflows/test.yml/badge.svg)](https://github.com/jordanahern2009-svg/Tokio-ai/actions/workflows/test.yml)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](pyproject.toml)
6
+
7
+ An open-source financial research agent that treats "the data supports this"
8
+ as a claim to be tested, not a vibe to be trusted.
9
+
10
+ Give it a ticker, a filing, or a plain-English trading hypothesis. It pulls
11
+ real data (price history, SEC filings) and, before it will tell you a
12
+ pattern is real, it runs the comparison through a permutation test, checks
13
+ the sample size against a hard floor, and corrects for every other
14
+ hypothesis you've asked it to test in the same conversation. Most AI
15
+ stock-chat tools will confidently describe a pattern in a handful of data
16
+ points. This one is built to tell you when it can't.
17
+
18
+ ## Why this exists
19
+
20
+ Generic LLM agents are commoditized -- anyone can wrap an LLM in a chat loop
21
+ and call it an agent. What isn't commoditized is discipline: most retail
22
+ (and plenty of professional) research fails because someone eyeballs a mean,
23
+ sees a gap, and calls it an edge without asking how likely that gap was to
24
+ appear by chance. The rigor layer here (`tokio_ai.rigor`) generalizes a
25
+ hypothesis-testing discipline actually used across real trading research
26
+ projects -- see `rigor/stats.py` and `rigor/ledger.py` for the permutation
27
+ test, minimum-sample gate, and Bonferroni/Benjamini-Hochberg multiple-testing
28
+ correction that every claim has to pass through.
29
+
30
+ ## What it can do today (v0)
31
+
32
+ - Pull daily OHLCV price history for any ticker (Yahoo Finance, no key)
33
+ - Pull recent SEC filings for any ticker (EDGAR, no key)
34
+ - Rank the real S&P 500 by trailing return, with optional GICS sector
35
+ filtering -- handles open-ended asks like "what are the best performing
36
+ stocks" without requiring you to already know a ticker or sector
37
+ - Test whether a simple technical condition (a big daily move, a gap at the
38
+ open, unusual volume) actually predicts what happens next -- fetches,
39
+ buckets, and runs the permutation test in one call, not via the model
40
+ eyeballing raw numbers
41
+ - Run a rigorous two-sided permutation test comparing any two groups of
42
+ numbers you already have, with automatic multiple-testing correction
43
+ across everything tested in the session
44
+ - Chat with it via a CLI; it decides when to call which tool
45
+
46
+ ## What it explicitly does not do
47
+
48
+ - Give investment advice or pick stocks
49
+ - Execute trades
50
+ - Pretend a small or cherry-picked sample proves anything
51
+
52
+ ## Quickstart
53
+
54
+ ```bash
55
+ pip install -e ".[dev]"
56
+ cp .env.example .env
57
+ # fill in OPENAI_API_KEY (a free key from https://build.nvidia.com works out of the box)
58
+ # and TOKIO_AI_USER_AGENT in .env
59
+ python -m tokio_ai.cli
60
+ ```
61
+
62
+ ```
63
+ > Pull AAPL's price history and tell me the most recent closing price.
64
+ > Get NVDA's recent 10-K and 10-Q filings.
65
+ ```
66
+
67
+ Run the test suite (no API key needed, no network calls):
68
+
69
+ ```bash
70
+ python -m pytest
71
+ ```
72
+
73
+ ## Architecture
74
+
75
+ - `tokio_ai/rigor/` -- pure-Python statistics engine (permutation testing,
76
+ multiple-testing correction, session-level test ledger). Fully unit
77
+ tested, zero dependencies beyond the standard library.
78
+ - `tokio_ai/tools/` -- data ingest (Yahoo price history, SEC EDGAR filings,
79
+ a bundled real S&P 500 + GICS sector snapshot) and the agent-facing
80
+ screening/pattern-testing/hypothesis-testing tools.
81
+ - `tokio_ai/agent/` -- the OpenAI-compatible tool-use loop (works against
82
+ any provider with that API shape; defaults to NVIDIA's free NIM catalog),
83
+ system prompt, and tool schemas.
84
+ - `tokio_ai/cli.py` -- interactive chat entry point.
85
+
86
+ **On language choice:** this is pure Python for now. The rigor engine (many
87
+ permutation-test iterations over numeric arrays) is the one part of this
88
+ codebase that's a plausible candidate for a Rust extension if it ever
89
+ becomes an actual measured bottleneck -- but the agent loop is I/O-bound on
90
+ LLM API calls, not local compute, so a polyglot rewrite ahead of a real
91
+ performance problem would just be added build complexity for no benefit.
92
+ Python first, optimize what's proven slow, not what looks slow.
93
+
94
+ ## Status
95
+
96
+ Early and under active development. The rigor engine and data-ingest tools
97
+ are tested against live sources. The agent loop has been verified
98
+ end-to-end against NVIDIA's free NIM catalog (`nvidia/llama-3.3-nemotron-super-49b-v1.5`
99
+ by default) -- real tool calls, real data, correct multi-turn answers.
100
+
101
+ **Known limitation:** the free tier has inconsistent latency (observed
102
+ anywhere from ~5s to 90s+ for the same model/prompt shape). That's the
103
+ tradeoff for "runs with zero-cost credentials out of the box." If you have
104
+ a paid OpenAI-compatible key with better SLAs, point `OPENAI_BASE_URL` /
105
+ `OPENAI_API_KEY` / `TOKIO_AI_MODEL` at it and nothing else changes.
106
+
107
+ Earlier versions asked the agent to manually crunch raw price history inline
108
+ for "does X predict Y"-style questions, which was unreliable on any LLM
109
+ backend (not specific to this one) -- that kind of bucketing belongs in a
110
+ Python tool, not the model's own token-by-token reasoning over a big JSON
111
+ blob. `test_return_pattern` and `top_performing_stocks` now do that
112
+ fetch+compute work in Python for the common cases (a technical condition
113
+ predicting forward returns; ranking stocks by trailing performance). If you
114
+ ask something shaped differently enough that neither tool fits, the model
115
+ may still fall back to reasoning over raw data by hand -- treat that path
116
+ as unreliable until there's a dedicated tool for it.
117
+
118
+ ### Example
119
+
120
+ ```
121
+ > Test whether AAPL days that gap up more than 2% at the open tend to keep
122
+ drifting up over the next 5 trading days, using 10 years of history.
123
+
124
+ The test found a statistically significant pattern (p=0.0050 after
125
+ correction), but in the opposite direction of the initial hypothesis. AAPL
126
+ days with gaps >2% at the open saw an average -1.31% return over the next 5
127
+ trading days, significantly underperforming the baseline. This suggests
128
+ large upward gaps historically preceded short-term weakness (gap-fade), not
129
+ momentum continuation. (data window: 2016-08-01 to 2026-07-31)
130
+ ```
131
+
132
+ ## License
133
+
134
+ MIT -- see [LICENSE](LICENSE).
@@ -0,0 +1,29 @@
1
+ # Security
2
+
3
+ ## Reporting a vulnerability
4
+
5
+ Open a GitHub issue, or if it's sensitive (credential exposure, a way to
6
+ make the agent execute arbitrary code), use GitHub's private vulnerability
7
+ reporting (Security tab -> "Report a vulnerability") instead of a public
8
+ issue.
9
+
10
+ ## What this project touches
11
+
12
+ - **Your LLM API key** (`OPENAI_API_KEY`), read from a local `.env` file
13
+ and never logged, printed, or sent anywhere except the configured
14
+ `OPENAI_BASE_URL`. Never commit `.env` -- it's gitignored by default.
15
+ - **Outbound network calls** to Yahoo Finance, SEC EDGAR, and your
16
+ configured LLM endpoint. No other network access, no telemetry, no
17
+ analytics.
18
+ - **No arbitrary code execution.** Tool inputs from the model are typed
19
+ JSON (strings, numbers, arrays) passed to fixed Python functions --
20
+ there is no `eval`, `exec`, or shell-out anywhere in the tool-calling
21
+ path. If you're extending this with a new tool, keep it that way.
22
+
23
+ ## Known limitations, not vulnerabilities
24
+
25
+ - The agent's data sources (Yahoo, SEC EDGAR) are unauthenticated public
26
+ endpoints; anyone running this tool is trusting those sources the same
27
+ way `curl` would.
28
+ - The bundled S&P 500 snapshot (`tokio_ai/data/sp500.csv`) is a point-in-time
29
+ dataset, not a live feed -- see `scripts/refresh_sp500.py`.
@@ -0,0 +1,119 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>TokIO AI</title>
7
+ <meta name="description" content="An open-source financial research agent that runs every claim through honest statistical testing before trusting it.">
8
+ <style>
9
+ :root {
10
+ color-scheme: light dark;
11
+ --bg: #ffffff;
12
+ --fg: #1a1a1a;
13
+ --muted: #5a5a5a;
14
+ --accent: #0a5c36;
15
+ --code-bg: #f4f4f4;
16
+ --border: #e2e2e2;
17
+ }
18
+ @media (prefers-color-scheme: dark) {
19
+ :root {
20
+ --bg: #0d1117;
21
+ --fg: #e6edf3;
22
+ --muted: #9198a1;
23
+ --accent: #3fb950;
24
+ --code-bg: #161b22;
25
+ --border: #30363d;
26
+ }
27
+ }
28
+ * { box-sizing: border-box; }
29
+ body {
30
+ margin: 0;
31
+ background: var(--bg);
32
+ color: var(--fg);
33
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
34
+ line-height: 1.6;
35
+ }
36
+ .wrap { max-width: 760px; margin: 0 auto; padding: 4rem 1.5rem 6rem; }
37
+ h1 { font-size: 2.1rem; margin: 0 0 0.5rem; }
38
+ .tagline { color: var(--muted); font-size: 1.15rem; margin: 0 0 2rem; }
39
+ .badges { margin-bottom: 2rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }
40
+ .badges img { height: 20px; }
41
+ p { margin: 1rem 0; }
42
+ code, pre {
43
+ font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
44
+ font-size: 0.9em;
45
+ }
46
+ pre {
47
+ background: var(--code-bg);
48
+ border: 1px solid var(--border);
49
+ border-radius: 8px;
50
+ padding: 1rem 1.25rem;
51
+ overflow-x: auto;
52
+ }
53
+ code { background: var(--code-bg); padding: 0.15em 0.4em; border-radius: 4px; }
54
+ pre code { background: none; padding: 0; }
55
+ ul { padding-left: 1.3rem; }
56
+ li { margin: 0.4rem 0; }
57
+ h2 { font-size: 1.3rem; margin-top: 2.5rem; }
58
+ .cta {
59
+ display: inline-block;
60
+ margin-top: 1rem;
61
+ padding: 0.65rem 1.3rem;
62
+ background: var(--accent);
63
+ color: #fff;
64
+ text-decoration: none;
65
+ border-radius: 8px;
66
+ font-weight: 600;
67
+ }
68
+ footer { margin-top: 4rem; color: var(--muted); font-size: 0.85rem; }
69
+ a { color: var(--accent); }
70
+ </style>
71
+ </head>
72
+ <body>
73
+ <div class="wrap">
74
+ <h1>TokIO AI</h1>
75
+ <p class="tagline">An open-source financial research agent that treats "the data supports this" as a claim to be tested, not a vibe to be trusted.</p>
76
+
77
+ <div class="badges">
78
+ <img src="https://github.com/jordanahern2009-svg/Tokio-ai/actions/workflows/test.yml/badge.svg" alt="tests">
79
+ <img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT License">
80
+ <img src="https://img.shields.io/badge/python-3.10+-blue.svg" alt="Python 3.10+">
81
+ </div>
82
+
83
+ <p>Give it a ticker, a filing, or a plain-English trading hypothesis. It pulls real data &mdash; price history, SEC filings, a real S&amp;P 500 snapshot &mdash; and before it will tell you a pattern is real, it runs the comparison through a permutation test, checks the sample size against a hard floor, and corrects for every other hypothesis you've asked it to test in the same conversation.</p>
84
+
85
+ <p>Most AI stock-chat tools will confidently describe a pattern in a handful of data points. This one is built to tell you when it can't.</p>
86
+
87
+ <a class="cta" href="https://github.com/jordanahern2009-svg/Tokio-ai">View on GitHub &rarr;</a>
88
+
89
+ <h2>What it can do</h2>
90
+ <ul>
91
+ <li>Pull daily price history and SEC filings for any ticker, no API key needed</li>
92
+ <li>Rank the real S&amp;P 500 by trailing return, optionally filtered by sector &mdash; handles open-ended asks like "what are the best performing stocks" without you having to already know a ticker</li>
93
+ <li>Test whether a technical condition actually predicts what happens next &mdash; fetch, bucket, and permutation-test in one call, not the model eyeballing raw numbers</li>
94
+ <li>Correct for multiple hypotheses tested in the same session, automatically</li>
95
+ </ul>
96
+
97
+ <h2>Quickstart</h2>
98
+ <pre><code>pip install -e ".[dev]"
99
+ cp .env.example .env
100
+ # fill in OPENAI_API_KEY (a free key from build.nvidia.com works out of the box)
101
+ python -m tokio_ai.cli</code></pre>
102
+
103
+ <h2>A real example</h2>
104
+ <pre><code>&gt; Test whether AAPL days that gap up more than 2% at the open tend to
105
+ keep drifting up over the next 5 trading days, using 10 years of history.
106
+
107
+ The test found a statistically significant pattern (p=0.0050 after
108
+ correction), but in the opposite direction of the initial hypothesis.
109
+ AAPL days with gaps &gt;2% at the open saw an average -1.31% return over
110
+ the next 5 trading days, significantly underperforming the baseline.
111
+ This suggests large upward gaps historically preceded short-term
112
+ weakness (gap-fade), not momentum continuation.</code></pre>
113
+
114
+ <footer>
115
+ MIT licensed. <a href="https://github.com/jordanahern2009-svg/Tokio-ai">Source, issues, and contributions welcome on GitHub</a>.
116
+ </footer>
117
+ </div>
118
+ </body>
119
+ </html>
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "tokio-ai"
7
+ version = "0.1.0"
8
+ description = "An open-source financial research agent that runs every claim through honest statistical testing before trusting it."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ authors = [{ name = "Jordan Ahern" }]
13
+ keywords = ["llm-agent", "finance", "statistics", "algorithmic-trading", "hypothesis-testing"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: Developers",
17
+ "Intended Audience :: Financial and Insurance Industry",
18
+ "License :: OSI Approved :: MIT License",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3.10",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Office/Business :: Financial :: Investment",
25
+ ]
26
+ dependencies = [
27
+ "openai>=1.50.0",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/jordanahern2009-svg/Tokio-ai"
32
+ Repository = "https://github.com/jordanahern2009-svg/Tokio-ai"
33
+ Issues = "https://github.com/jordanahern2009-svg/Tokio-ai/issues"
34
+
35
+ [project.scripts]
36
+ tokio-ai = "tokio_ai.cli:main"
37
+
38
+ [project.optional-dependencies]
39
+ dev = ["pytest>=8.0"]
40
+
41
+ [tool.hatch.build.targets.wheel]
42
+ packages = ["src/tokio_ai"]
File without changes
@@ -0,0 +1,56 @@
1
+ """Refresh the bundled S&P 500 snapshot (tokio_ai/data/sp500.csv).
2
+
3
+ Index membership changes every quarter (additions/removals), so the bundled
4
+ snapshot will drift stale over time -- run this periodically to update it.
5
+
6
+ Usage:
7
+ python -m scripts.refresh_sp500
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import csv
13
+ import json
14
+ import urllib.request
15
+ from datetime import date
16
+ from pathlib import Path
17
+
18
+ SOURCE_URL = "https://raw.githubusercontent.com/datasets/s-and-p-500-companies/main/data/constituents.csv"
19
+ DEST = Path(__file__).resolve().parent.parent / "src" / "tokio_ai" / "data" / "sp500.csv"
20
+ SCREENER_MODULE = Path(__file__).resolve().parent.parent / "src" / "tokio_ai" / "tools" / "screener.py"
21
+
22
+
23
+ def fetch_constituents() -> list[dict]:
24
+ req = urllib.request.Request(SOURCE_URL, headers={"User-Agent": "Mozilla/5.0"})
25
+ with urllib.request.urlopen(req, timeout=30) as r:
26
+ text = r.read().decode("utf-8")
27
+ return list(csv.DictReader(text.splitlines()))
28
+
29
+
30
+ def to_yahoo_symbol(symbol: str) -> str:
31
+ # Yahoo uses hyphens for class shares (BRK-B); this dataset uses dots (BRK.B).
32
+ return symbol.replace(".", "-")
33
+
34
+
35
+ def main() -> None:
36
+ rows = fetch_constituents()
37
+ if len(rows) < 400:
38
+ raise RuntimeError(f"got suspiciously few rows ({len(rows)}) -- source format may have changed, aborting")
39
+
40
+ with DEST.open("w", newline="", encoding="utf-8") as f:
41
+ w = csv.DictWriter(f, fieldnames=["symbol", "name", "sector"])
42
+ w.writeheader()
43
+ for r in rows:
44
+ w.writerow({
45
+ "symbol": to_yahoo_symbol(r["Symbol"]),
46
+ "name": r["Security"],
47
+ "sector": r["GICS Sector"],
48
+ })
49
+
50
+ today = date.today().isoformat()
51
+ print(f"Wrote {len(rows)} constituents to {DEST}")
52
+ print(f"Now update SNAPSHOT_DATE in {SCREENER_MODULE} to \"{today}\"")
53
+
54
+
55
+ if __name__ == "__main__":
56
+ main()
@@ -0,0 +1,4 @@
1
+ """TokIO AI: an open-source financial research agent that runs every claim
2
+ through honest statistical testing before trusting it."""
3
+
4
+ __version__ = "0.1.0"