fa-quant 1.2.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.
- fa_quant-1.2.1.dist-info/METADATA +236 -0
- fa_quant-1.2.1.dist-info/RECORD +106 -0
- fa_quant-1.2.1.dist-info/WHEEL +4 -0
- fa_quant-1.2.1.dist-info/entry_points.txt +2 -0
- fa_quant-1.2.1.dist-info/licenses/LICENSE +21 -0
- financial_agent/__init__.py +1 -0
- financial_agent/agents/__init__.py +0 -0
- financial_agent/agents/claude/__init__.py +0 -0
- financial_agent/agents/gpt/__init__.py +0 -0
- financial_agent/agents/grok/__init__.py +0 -0
- financial_agent/dl/__init__.py +0 -0
- financial_agent/dl/models/__init__.py +0 -0
- financial_agent/dl/models/baseline_model.py +23 -0
- financial_agent/dl/preprocessing/__init__.py +0 -0
- financial_agent/dl/preprocessing/data_windowing.py +135 -0
- financial_agent/harness/__init__.py +73 -0
- financial_agent/harness/__main__.py +430 -0
- financial_agent/harness/_system/factor_scoring.py +175 -0
- financial_agent/harness/_system/settlement_ledger.py +1222 -0
- financial_agent/harness/audit.py +393 -0
- financial_agent/harness/equity_policy.toml +179 -0
- financial_agent/harness/fingerprint.py +55 -0
- financial_agent/harness/gates.py +522 -0
- financial_agent/harness/handlers.py +77 -0
- financial_agent/harness/helpers.py +47 -0
- financial_agent/harness/kernels.py +696 -0
- financial_agent/harness/ledger.py +325 -0
- financial_agent/harness/lifecycle.py +127 -0
- financial_agent/harness/manifest.py +113 -0
- financial_agent/harness/market_calendar.py +50 -0
- financial_agent/harness/mcp.py +505 -0
- financial_agent/harness/policy.py +248 -0
- financial_agent/harness/runner.py +275 -0
- financial_agent/harness/schema.py +451 -0
- financial_agent/harness/scoring.py +363 -0
- financial_agent/harness/skills.py +458 -0
- financial_agent/quant/__init__.py +1 -0
- financial_agent/quant/__main__.py +506 -0
- financial_agent/quant/backtest/__init__.py +16 -0
- financial_agent/quant/backtest/config.py +74 -0
- financial_agent/quant/backtest/costs.py +62 -0
- financial_agent/quant/backtest/engine.py +248 -0
- financial_agent/quant/backtest/metrics.py +102 -0
- financial_agent/quant/backtest/result.py +51 -0
- financial_agent/quant/data/__init__.py +21 -0
- financial_agent/quant/data/bars.py +103 -0
- financial_agent/quant/data/cache.py +168 -0
- financial_agent/quant/data/providers.py +138 -0
- financial_agent/quant/data/quality.py +104 -0
- financial_agent/quant/data/synthetic.py +67 -0
- financial_agent/quant/execution/__init__.py +24 -0
- financial_agent/quant/execution/alpaca.py +293 -0
- financial_agent/quant/execution/broker.py +98 -0
- financial_agent/quant/execution/ibkr.py +634 -0
- financial_agent/quant/execution/journal.py +139 -0
- financial_agent/quant/execution/paper.py +254 -0
- financial_agent/quant/execution/reconcile.py +35 -0
- financial_agent/quant/mcp.py +210 -0
- financial_agent/quant/portfolio.py +56 -0
- financial_agent/quant/quant_policy.toml +40 -0
- financial_agent/quant/risk/__init__.py +21 -0
- financial_agent/quant/risk/killswitch.py +61 -0
- financial_agent/quant/risk/limits.py +109 -0
- financial_agent/quant/risk/orders.py +91 -0
- financial_agent/quant/risk/pretrade.py +157 -0
- financial_agent/quant/risk/state.py +86 -0
- financial_agent/quant/runner/__init__.py +20 -0
- financial_agent/quant/runner/config.py +254 -0
- financial_agent/quant/runner/promotion.py +277 -0
- financial_agent/quant/runner/report.py +231 -0
- financial_agent/quant/runner/session.py +705 -0
- financial_agent/quant/strategies/__init__.py +19 -0
- financial_agent/quant/strategies/base.py +44 -0
- financial_agent/quant/strategies/benchmarks.py +54 -0
- financial_agent/quant/strategies/momentum.py +80 -0
- financial_agent/quant/strategies/registry.py +65 -0
- financial_agent/quant/strategies/research.py +226 -0
- financial_agent/quant/strategies/trend.py +91 -0
- financial_agent/quant/validation/__init__.py +41 -0
- financial_agent/quant/validation/bootstrap.py +39 -0
- financial_agent/quant/validation/certificate.py +189 -0
- financial_agent/quant/validation/gate.py +304 -0
- financial_agent/quant/validation/overfitting.py +148 -0
- financial_agent/quant/validation/stress.py +33 -0
- financial_agent/quant/validation/walkforward.py +157 -0
- financial_agent/rl/__init__.py +13 -0
- financial_agent/rl/agent.py +112 -0
- financial_agent/rl/environment.py +177 -0
- financial_agent/rl/trainer.py +142 -0
- financial_agent/trading/__init__.py +0 -0
- financial_agent/trading/autotrain/__init__.py +0 -0
- financial_agent/trading/autotrain/training.py +92 -0
- financial_agent/trading/backtest.py +118 -0
- financial_agent/trading/config/__init__.py +0 -0
- financial_agent/trading/config/config.py +1587 -0
- financial_agent/trading/marketdata/__init__.py +0 -0
- financial_agent/trading/marketdata/yahoodownloader.py +99 -0
- financial_agent/trading/model/__init__.py +0 -0
- financial_agent/trading/model/models.py +466 -0
- financial_agent/trading/preprocessing/__init__.py +0 -0
- financial_agent/trading/preprocessing/data.py +32 -0
- financial_agent/trading/preprocessing/preprocessors.py +162 -0
- financial_agent/trading/utils/__init__.py +0 -0
- financial_agent/trading/utils/gpu_config.py +213 -0
- financial_agent/trading/utils/main.py +52 -0
- financial_agent/trading/utils/setup_gpu_for_notebooks.py +130 -0
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: fa-quant
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Import-Name: financial_agent
|
|
5
|
+
Summary: Risk-managed systematic ETF trading, statistical validation, and financial research
|
|
6
|
+
Project-URL: Homepage, https://github.com/BichengWang/financial-agent
|
|
7
|
+
Project-URL: Repository, https://github.com/BichengWang/financial-agent
|
|
8
|
+
Project-URL: Documentation, https://github.com/BichengWang/financial-agent/tree/main/docs/quant
|
|
9
|
+
Project-URL: Issues, https://github.com/BichengWang/financial-agent/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/BichengWang/financial-agent/blob/main/CHANGELOG.md
|
|
11
|
+
Author-email: "Bicheng (Kenneth)" <31808103+BichengWang@users.noreply.github.com>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: backtesting,portfolio,reinforcement-learning,risk-management,systematic-trading
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: POSIX
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
21
|
+
Requires-Python: >=3.12
|
|
22
|
+
Requires-Dist: gymnasium
|
|
23
|
+
Requires-Dist: numpy<2.0,>=1.24.0
|
|
24
|
+
Requires-Dist: pandas<3,>=2.0
|
|
25
|
+
Requires-Dist: requests<3,>=2.32
|
|
26
|
+
Requires-Dist: yfinance
|
|
27
|
+
Provides-Extra: all
|
|
28
|
+
Requires-Dist: beautifulsoup4; extra == 'all'
|
|
29
|
+
Requires-Dist: ipython; extra == 'all'
|
|
30
|
+
Requires-Dist: keras-nightly; extra == 'all'
|
|
31
|
+
Requires-Dist: matplotlib; extra == 'all'
|
|
32
|
+
Requires-Dist: notebook; extra == 'all'
|
|
33
|
+
Requires-Dist: pyfolio-reloaded; extra == 'all'
|
|
34
|
+
Requires-Dist: scikit-learn; extra == 'all'
|
|
35
|
+
Requires-Dist: seaborn; extra == 'all'
|
|
36
|
+
Requires-Dist: stable-baselines3; extra == 'all'
|
|
37
|
+
Requires-Dist: stockstats; extra == 'all'
|
|
38
|
+
Requires-Dist: tensorflow; extra == 'all'
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: black>=22.0.0; extra == 'dev'
|
|
41
|
+
Requires-Dist: flake8>=6.0.0; extra == 'dev'
|
|
42
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
43
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
44
|
+
Requires-Dist: pytest-custom-exit-code; extra == 'dev'
|
|
45
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
46
|
+
Provides-Extra: dl
|
|
47
|
+
Requires-Dist: ipython; extra == 'dl'
|
|
48
|
+
Requires-Dist: keras-nightly; extra == 'dl'
|
|
49
|
+
Requires-Dist: matplotlib; extra == 'dl'
|
|
50
|
+
Requires-Dist: scikit-learn; extra == 'dl'
|
|
51
|
+
Requires-Dist: seaborn; extra == 'dl'
|
|
52
|
+
Requires-Dist: tensorflow; extra == 'dl'
|
|
53
|
+
Provides-Extra: notebooks
|
|
54
|
+
Requires-Dist: ipython; extra == 'notebooks'
|
|
55
|
+
Requires-Dist: matplotlib; extra == 'notebooks'
|
|
56
|
+
Requires-Dist: notebook; extra == 'notebooks'
|
|
57
|
+
Requires-Dist: seaborn; extra == 'notebooks'
|
|
58
|
+
Provides-Extra: research
|
|
59
|
+
Requires-Dist: openpyxl<4,>=3.1; extra == 'research'
|
|
60
|
+
Provides-Extra: rl
|
|
61
|
+
Requires-Dist: beautifulsoup4; extra == 'rl'
|
|
62
|
+
Requires-Dist: matplotlib; extra == 'rl'
|
|
63
|
+
Requires-Dist: pyfolio-reloaded; extra == 'rl'
|
|
64
|
+
Requires-Dist: scikit-learn; extra == 'rl'
|
|
65
|
+
Requires-Dist: stable-baselines3; extra == 'rl'
|
|
66
|
+
Requires-Dist: stockstats; extra == 'rl'
|
|
67
|
+
Requires-Dist: tensorflow; extra == 'rl'
|
|
68
|
+
Description-Content-Type: text/markdown
|
|
69
|
+
|
|
70
|
+
# financial-agent
|
|
71
|
+
|
|
72
|
+
A Python platform for systematic ETF research, cost-aware portfolio backtesting,
|
|
73
|
+
statistical certification, paper trading and explicitly gated Alpaca and IBKR execution.
|
|
74
|
+
It also retains an equity-research harness and separate RL/deep-learning research
|
|
75
|
+
stacks. The platform is **beta**: live performance is unproven, and neither a
|
|
76
|
+
historical gate pass nor paper results guarantee profit.
|
|
77
|
+
|
|
78
|
+
## Five-minute offline quickstart
|
|
79
|
+
|
|
80
|
+
Install [uv](https://docs.astral.sh/uv/getting-started/installation/); Python 3.12
|
|
81
|
+
is selected by `.python-version`. From the repository root:
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
uv sync --locked
|
|
85
|
+
uv run fa-quant demo
|
|
86
|
+
uv run fa-quant --help
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The demo uses seeded synthetic data with a planted trend. It runs backtest,
|
|
90
|
+
validation/certificate creation, 25 local paper sessions and status without
|
|
91
|
+
network access after dependencies are installed. Its printed numbers demonstrate
|
|
92
|
+
software behavior, not market performance. To keep the artifacts, use a fresh
|
|
93
|
+
state directory:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
uv run fa-quant demo --sessions 25 --state-dir /tmp/fa-quant-demo-release
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Core dependencies include NumPy `<2`, pandas `>=2,<3`, yfinance, Gymnasium and
|
|
100
|
+
requests. Default development tools are installed by `uv sync`; optional `rl`,
|
|
101
|
+
`dl`, `notebooks` and `research` extras add the heavier research stacks. Full
|
|
102
|
+
release verification uses `uv sync --locked --all-extras`.
|
|
103
|
+
|
|
104
|
+
Once a release is published to PyPI, `pip install fa-quant` installs the
|
|
105
|
+
`fa-quant` command and the `financial_agent` import package. The PyPI project
|
|
106
|
+
`financial-agent` is unrelated. Python 3.12 is the tested version; on 3.13+ the
|
|
107
|
+
NumPy `<2` pin builds NumPy from source. Examples, docs and evidence stay in this
|
|
108
|
+
repository; see [releasing](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/releasing.md).
|
|
109
|
+
|
|
110
|
+
## Real-data research
|
|
111
|
+
|
|
112
|
+
The example uses SPY, QQQ, IWM, EFA, EEM, TLT, IEF, LQD, GLD, DBC and VNQ,
|
|
113
|
+
weekly next-open fills, whole shares and a 2% cash buffer. Downloads are cached
|
|
114
|
+
under gitignored `var/`. Use the latest completed session as the inclusive end:
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
uv run fa-quant backtest --config examples/quant/paper.toml --end 2026-10-12 --json
|
|
118
|
+
uv run fa-quant validate --config examples/quant/paper.toml --end 2026-10-12 --json
|
|
119
|
+
uv run fa-quant certify --config examples/quant/paper.toml --end 2026-10-12 \
|
|
120
|
+
--output var/quant-paper/certificate.json
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
`validate`/`certify` return 2 when any gate fails; failed certificates can be saved
|
|
124
|
+
but cannot authorize live trading. With `--config`, settings come from the TOML;
|
|
125
|
+
standalone strategy/provider/start flags do not override it. See
|
|
126
|
+
[strategy research](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/strategy-research.md) for grids and interpretation.
|
|
127
|
+
|
|
128
|
+
The [committed real-data evidence](https://github.com/BichengWang/financial-agent/blob/v1.2.1/reports/quant/2026-10-default-strategy-evidence.md)
|
|
129
|
+
uses the earliest common ETF date, **2006-02-06 through 2026-10-12**, unchanged
|
|
130
|
+
default costs and the disclosed four-variant trend grid. All four full-period
|
|
131
|
+
default comparisons are shown here:
|
|
132
|
+
|
|
133
|
+
| Strategy | CAGR | Net Sharpe | Max drawdown | Turnover/year |
|
|
134
|
+
|---|---:|---:|---:|---:|
|
|
135
|
+
| Trend vol target | 5.625% | 0.740 | 16.533% | 14.375× |
|
|
136
|
+
| Dual momentum | 11.100% | 0.754 | 26.397% | 10.550× |
|
|
137
|
+
| SPY buy-and-hold | 11.122% | 0.652 | 54.299% | 0.048× |
|
|
138
|
+
| 60/40 SPY/IEF | 8.212% | 0.785 | 31.979% | 0.206× |
|
|
139
|
+
|
|
140
|
+
Trend passes all eight historical checks: OOS Sharpe 0.729, DSR 0.996, OOS
|
|
141
|
+
maximum drawdown 17.114%. PBO 0.650 warns that in-sample parameter selection adds
|
|
142
|
+
no reliable value. Single-default dual momentum and 60/40 also pass all eight
|
|
143
|
+
statistical checks; SPY fails the OOS drawdown limit. For a single pre-registered
|
|
144
|
+
variant, CSCV computes absolute OOS loss frequency; PBO and degradation slope
|
|
145
|
+
are not applicable. Warmup/OOS windows differ; read the report for dates, exact
|
|
146
|
+
checks, costs, bootstrap intervals, stress results and data caveats. No parameters
|
|
147
|
+
or thresholds were tuned to pass. Statistical passes do not override execution
|
|
148
|
+
limits: default dual momentum's three slots allocate 33.3% each versus the 30%
|
|
149
|
+
per-name cap, and concentrated SPY/60-40 benchmarks also exceed runtime caps.
|
|
150
|
+
|
|
151
|
+
The dated equity `research_forecast` strategy also [fails its real-ledger gate](https://github.com/BichengWang/financial-agent/blob/v1.2.1/reports/quant/research-forecast-validation.md):
|
|
152
|
+
there is too little history to support promotion. This is the retained result
|
|
153
|
+
for the LLM research signal, not an implied trading edge.
|
|
154
|
+
|
|
155
|
+
## Paper trading and live gate
|
|
156
|
+
|
|
157
|
+
Load Alpaca **paper** keys into the process environment as `APCA_API_KEY_ID` and
|
|
158
|
+
`APCA_API_SECRET_KEY`; keep them out of TOML, git and command history. With keys
|
|
159
|
+
loaded, preview and run before the opening auction (around 08:45 New York time):
|
|
160
|
+
|
|
161
|
+
```sh
|
|
162
|
+
uv run fa-quant run --config examples/quant/paper.toml --dry-run
|
|
163
|
+
uv run fa-quant run --config examples/quant/paper.toml
|
|
164
|
+
uv run fa-quant status --config examples/quant/paper.toml
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
IBKR uses the locally running **Client Portal Gateway**, with daily browser login.
|
|
168
|
+
Copy [ibkr-paper.toml](https://github.com/BichengWang/financial-agent/blob/v1.2.1/examples/quant/ibkr-paper.toml), set your USD paper account
|
|
169
|
+
ID (`DU…`/`DF…`) and gateway port, then use the same `fa-quant run` command.
|
|
170
|
+
TLS verification can be disabled only on loopback; remote gateways require a
|
|
171
|
+
trusted certificate or CA path. Order questions halt unless every message ID is
|
|
172
|
+
explicitly allowed. Follow the [gateway setup](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/operations.md#ibkr-client-portal-gateway).
|
|
173
|
+
|
|
174
|
+
The release verifies execution through local paper and fake Alpaca/IBKR transports;
|
|
175
|
+
a real credentialed paper run is still an owner step. A dry run suppresses new
|
|
176
|
+
orders but journals observations and can synchronize earlier fills.
|
|
177
|
+
|
|
178
|
+
Live needs `mode = "live"`, `FA_QUANT_ALLOW_LIVE=1`, a passing certificate no older
|
|
179
|
+
than 90 days matching the exact strategy/params, at least 20 distinct clean
|
|
180
|
+
paper sessions from the same broker (Alpaca or IBKR), no recent risk halts/reconciliation breaks, and observed
|
|
181
|
+
paper slippage within twice modeled allowance. Runtime risk limits cannot be
|
|
182
|
+
loosened by config. MCP exposes research and paper previews only. Read
|
|
183
|
+
[safety and go-live steps](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/safety.md) before changing mode, and
|
|
184
|
+
[operations](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/operations.md) for scheduling, kill/unkill and incidents.
|
|
185
|
+
Kill stops new submissions; it does not cancel orders or liquidate positions.
|
|
186
|
+
|
|
187
|
+
## Research harness, equity workflow and RL
|
|
188
|
+
|
|
189
|
+
The [native ticker workflow](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/research/README.md) combines sourced evidence,
|
|
190
|
+
Decimal arithmetic, optional earnings/DCF/comps models and structural audits;
|
|
191
|
+
[retained research](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/research/index.md) remains provisional. The
|
|
192
|
+
[daily equity workflow](https://github.com/BichengWang/financial-agent/blob/v1.2.1/agents/equity/daily_investment_system/main.md) produces
|
|
193
|
+
dated source/prediction packages. The harness provides deterministic report
|
|
194
|
+
checks and ledger audits, not autonomous completion of every prompt stage:
|
|
195
|
+
|
|
196
|
+
```sh
|
|
197
|
+
uv run python -m financial_agent.harness --help
|
|
198
|
+
uv run python -m financial_agent.harness audit --output-dir agents/equity/output
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Generic RL supplies tabular Q-learning, GridWorld, Gymnasium wrappers and bounded
|
|
202
|
+
training/evaluation loops. [Examples](https://github.com/BichengWang/financial-agent/blob/v1.2.1/example/rl/) demonstrate learning APIs;
|
|
203
|
+
[notebooks](https://github.com/BichengWang/financial-agent/blob/v1.2.1/notebooks/README.md) retain historical experiment outputs. Install
|
|
204
|
+
`--extra rl`, `--extra dl` or `--extra notebooks` as needed. The FinRL-derived
|
|
205
|
+
`trading/` and TensorFlow `dl/` stacks are experimental; they do not feed capital
|
|
206
|
+
unless adapted to `Strategy` and passed through the same gates. The historical
|
|
207
|
+
autotrain entrypoint has unresolved signature/name issues and is not turnkey.
|
|
208
|
+
|
|
209
|
+
## Repository map
|
|
210
|
+
|
|
211
|
+
| Path | Purpose |
|
|
212
|
+
|---|---|
|
|
213
|
+
| [src/financial_agent/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/src/financial_agent/quant/) | Data, strategies, backtest, validation, risk, execution, runner and CLI/MCP |
|
|
214
|
+
| [docs/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/) | [Architecture](https://github.com/BichengWang/financial-agent/blob/v1.2.1/docs/quant/architecture.md), safety, operations, strategy guide |
|
|
215
|
+
| [examples/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/examples/quant/) / [deploy/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/deploy/quant/) | Paper TOML and cron/launchd/systemd templates |
|
|
216
|
+
| [reports/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/reports/quant/) | Computed default and research-forecast evidence |
|
|
217
|
+
| [tests/quant](https://github.com/BichengWang/financial-agent/blob/v1.2.1/tests/quant/) | Deterministic offline regression coverage |
|
|
218
|
+
| [src/financial_agent/harness](https://github.com/BichengWang/financial-agent/blob/v1.2.1/src/financial_agent/harness/) | Equity schemas, gates, kernels and policy |
|
|
219
|
+
| [agents/equity](https://github.com/BichengWang/financial-agent/blob/v1.2.1/agents/equity/) / [skills](https://github.com/BichengWang/financial-agent/blob/v1.2.1/skills/) | Daily/native equity workflows and Turtle research |
|
|
220
|
+
| [src/financial_agent/rl](https://github.com/BichengWang/financial-agent/blob/v1.2.1/src/financial_agent/rl/) / [example/rl](https://github.com/BichengWang/financial-agent/blob/v1.2.1/example/rl/) | Generic RL APIs and examples |
|
|
221
|
+
| [src/financial_agent/trading](https://github.com/BichengWang/financial-agent/blob/v1.2.1/src/financial_agent/trading/) / [src/financial_agent/dl](https://github.com/BichengWang/financial-agent/blob/v1.2.1/src/financial_agent/dl/) | Financial RL and prediction research |
|
|
222
|
+
| [notebooks](https://github.com/BichengWang/financial-agent/blob/v1.2.1/notebooks/) / [archive](https://github.com/BichengWang/financial-agent/blob/v1.2.1/archive/) | Saved research outputs; avoid incidental reruns |
|
|
223
|
+
|
|
224
|
+
## Limitations
|
|
225
|
+
|
|
226
|
+
Yahoo's retrospectively adjusted OHLCV can change and is not raw auction
|
|
227
|
+
execution data. The fixed ETF universe retains selection bias. Simulations omit
|
|
228
|
+
taxes, cash interest, capacity/market impact and exact live corporate-action
|
|
229
|
+
accounting. Statistics measure this historical sample, not future profitability.
|
|
230
|
+
The scheduled runner does not continuously monitor intraday loss or guarantee
|
|
231
|
+
fills; reference-price limits do not eliminate gap risk. State/journal hashes
|
|
232
|
+
are integrity checks, not signatures. The POSIX runner targets macOS/Linux.
|
|
233
|
+
|
|
234
|
+
## License
|
|
235
|
+
|
|
236
|
+
[MIT](https://github.com/BichengWang/financial-agent/blob/v1.2.1/LICENSE). Software is provided as is, without warranty.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
financial_agent/__init__.py,sha256=rQfhy-OlgindBglnlG74MrRlxrb_N-auAjdNlZZ_cOw,58
|
|
2
|
+
financial_agent/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
financial_agent/agents/claude/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
financial_agent/agents/gpt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
financial_agent/agents/grok/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
financial_agent/dl/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
financial_agent/dl/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
financial_agent/dl/models/baseline_model.py,sha256=89tG5AydguIIYew2TFrP87LCJyVHG-QAvi3f3oI1OfQ,529
|
|
9
|
+
financial_agent/dl/preprocessing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
financial_agent/dl/preprocessing/data_windowing.py,sha256=mzO9w5Xm1wp8y88LQ4ndXkGSzxOgQi0Msei6C7Xf6k0,4619
|
|
11
|
+
financial_agent/harness/__init__.py,sha256=nopGB80wAt5XzJuH001NKgPyqLQXhLe6F3xqsZWS8YI,2157
|
|
12
|
+
financial_agent/harness/__main__.py,sha256=Bw52nCqcpxJsTbVKv9YdUf2MtID-vEGRvd48QuT1SOQ,16101
|
|
13
|
+
financial_agent/harness/audit.py,sha256=74rs6cWZPvMbU9a7Wa9kzz94SXpnJ5tuZOceZUFu20w,14904
|
|
14
|
+
financial_agent/harness/equity_policy.toml,sha256=QB-lgJePvZ2-Y4o0pMuja-KgGkV4XCorAQdfXck5Pzs,5503
|
|
15
|
+
financial_agent/harness/fingerprint.py,sha256=te5w1JbsM1JwWMQ4TDDcGpKnzrNBxt4bp8gDIHqehBo,2152
|
|
16
|
+
financial_agent/harness/gates.py,sha256=EuqMXXOOqYtlIFkUNKn9yX_m5B5QbDMLhX6SYAtTccw,19903
|
|
17
|
+
financial_agent/harness/handlers.py,sha256=OZCmoNsGXl15fVpU489Qh2mVeMRSNAA-W49Cp6a6ztQ,2945
|
|
18
|
+
financial_agent/harness/helpers.py,sha256=-AY9JAf_nPCYLe8sxAGYehf9cArPk4PapnTLFjZdV3k,1660
|
|
19
|
+
financial_agent/harness/kernels.py,sha256=CpyMe3FEpcX4Ln7HfF1NbIHhCpPTUk7q10bHCpyv-h0,26617
|
|
20
|
+
financial_agent/harness/ledger.py,sha256=V0CtY-Vylalr33WH8j9chLrvmltp2n_to2CPO7RJnrg,11315
|
|
21
|
+
financial_agent/harness/lifecycle.py,sha256=Zd9cHr8Se6N7TQX8x2JmbNlW_Eo2fD4szqsrCCbYtgU,4855
|
|
22
|
+
financial_agent/harness/manifest.py,sha256=YpM_ox1GBisXZ4Xq3oUw53gyxmlNRsk-woxdtRQC7Pg,4172
|
|
23
|
+
financial_agent/harness/market_calendar.py,sha256=SU6Z_XAmNvAVVPqkdV1fCecXW7ZH76oP4nCN8qviDX8,1664
|
|
24
|
+
financial_agent/harness/mcp.py,sha256=eXIlgSkwj4mNVdgXRDE3eHMvnaJksRJWWryuBztb0zE,19704
|
|
25
|
+
financial_agent/harness/policy.py,sha256=mx1u7nJ1D9cTPTAr23Mt7YaHh8NWhzDAW5SzoOuWiwI,9239
|
|
26
|
+
financial_agent/harness/runner.py,sha256=p80b1FGZ1WtKJHqMBLoC8nrEEQfbpQ8MIPFtDQ0Q_vY,9380
|
|
27
|
+
financial_agent/harness/schema.py,sha256=i_4sUZ0NnkLF8lIWXA1Uhs0LICuM_PKPIXwu3Pf45iM,17987
|
|
28
|
+
financial_agent/harness/scoring.py,sha256=vLYHIr9q0I1yfnA-TKY2OzSd1wLbqqxXVpAyUyLqkNY,13210
|
|
29
|
+
financial_agent/harness/skills.py,sha256=HlOfIrjLNuReCN73iX4nZYkQuaq5rjjQncv7fucopdg,17649
|
|
30
|
+
financial_agent/quant/__init__.py,sha256=9SJEFDg-03pL1QblDWaLO0MTvE_MFkhVdvc4v6hxxLo,50
|
|
31
|
+
financial_agent/quant/__main__.py,sha256=ST55e7Pmz5unB-2xjdC-aXIzIIEQaJVLGrJIFHbbujU,18894
|
|
32
|
+
financial_agent/quant/mcp.py,sha256=ujTYdf86AZkiuosCxuVk0UhcY0ZjobfEU0OGj1dltdE,8563
|
|
33
|
+
financial_agent/quant/portfolio.py,sha256=pNRzFCixLlTJmFHpasbkhdDhXZE_n01pE77vyabNtJk,2231
|
|
34
|
+
financial_agent/quant/quant_policy.toml,sha256=GFsdIe-H-O0lp_gbqfvWmArCcn6aLb3TDzF_yxQyva0,960
|
|
35
|
+
financial_agent/quant/backtest/__init__.py,sha256=xrtVSv7xakOSRUkzVAixmdYitDwOqorVBI5PwwSs5Bk,390
|
|
36
|
+
financial_agent/quant/backtest/config.py,sha256=czV3OZo1RiCbzlLm1jlXyF00z3kZbkoJ6SJIj6Jj--c,3068
|
|
37
|
+
financial_agent/quant/backtest/costs.py,sha256=SyJVclUucFPutktIBNBqkV4upLFu8nAPFTHW84tmBu8,2304
|
|
38
|
+
financial_agent/quant/backtest/engine.py,sha256=zRTvXI75SHXSGtZiuyhyrmt4IhXgU6icPtaB5AP7qu0,9792
|
|
39
|
+
financial_agent/quant/backtest/metrics.py,sha256=VxOLCILmcUr0YO1Ixb_ZyVAJXVv_QJ1r6XMK77b-uQ0,4096
|
|
40
|
+
financial_agent/quant/backtest/result.py,sha256=JSGcihiDQ9wfoUMW5ReTftodVVqQkWoxR2W_Gp8IjDk,1745
|
|
41
|
+
financial_agent/quant/data/__init__.py,sha256=Ly3KMtVNhQLzq-oPglwyFFZyUvR0q9Aem5kPPQpOYDQ,571
|
|
42
|
+
financial_agent/quant/data/bars.py,sha256=gbiNv6kaLwpVrteHQPmY_pgnGuxbepcOrgxSeENnV2s,4007
|
|
43
|
+
financial_agent/quant/data/cache.py,sha256=6h0Z5IA8OmUq0fwtk7yHRoln3CFqXuUwgynXLWwIDVc,7155
|
|
44
|
+
financial_agent/quant/data/providers.py,sha256=YMqsYkGvokDMhjU2SbrAa_DgfoEI95zuz1rKvfIk6zI,5780
|
|
45
|
+
financial_agent/quant/data/quality.py,sha256=3AxjaPusHaxdPg6adoPWXowQ9aRe0l6zn0B-K9bEgQg,3714
|
|
46
|
+
financial_agent/quant/data/synthetic.py,sha256=OzFhc2o88rwypT4YxWy3mn_kkwDUI9cYN5U73O4gsx0,2846
|
|
47
|
+
financial_agent/quant/execution/__init__.py,sha256=bvbtNwHtYRXt-p0pAjKJFx3AenHnU2noNvpgV_rrMGY,572
|
|
48
|
+
financial_agent/quant/execution/alpaca.py,sha256=cJZnyvtqNGwMdobZaK83h-SpO2bXWJekqGXyn-FJguI,11486
|
|
49
|
+
financial_agent/quant/execution/broker.py,sha256=ml7GU7iQsUrTGS0L2QVICw3mGFSPRAyPVLZibhvNyY8,2666
|
|
50
|
+
financial_agent/quant/execution/ibkr.py,sha256=JGM4wfzP8Uqy3huTsduqkjir4295eE7fnab-tmdsBmo,26234
|
|
51
|
+
financial_agent/quant/execution/journal.py,sha256=Odaej_J6aY7AZBa3ty_kTaOI__YESK9Ab6XO9MWDnR4,5207
|
|
52
|
+
financial_agent/quant/execution/paper.py,sha256=yNardzEZ3LE3s_4mjUK5tczuZ28lBrssSLZVA_Mddu8,10102
|
|
53
|
+
financial_agent/quant/execution/reconcile.py,sha256=gSPMUYvqHnq2QbgJ7qDC7Bfg3l5zOoeiZZWLDO8NNfA,1098
|
|
54
|
+
financial_agent/quant/risk/__init__.py,sha256=p58zRssmB2h6etoCmvRMHTImlu5okPHdYTESyrHuciU,557
|
|
55
|
+
financial_agent/quant/risk/killswitch.py,sha256=SYoji0AX956L2Vk7Z4jMaqQ4drOt6j-MT3kZ7RAQBSQ,2201
|
|
56
|
+
financial_agent/quant/risk/limits.py,sha256=SR93tEaG3uuWXPoAKobDleHGLyBv2Y1Z7Bn2OJMILuc,4341
|
|
57
|
+
financial_agent/quant/risk/orders.py,sha256=z8g9crlwTcqHr2CVzGnwiyHkfQ44CnQ3mYcu9ztMVjs,2831
|
|
58
|
+
financial_agent/quant/risk/pretrade.py,sha256=mVz9mcTxaKsbEF0e_c3tHlhTJbFVT5pnIMmmzx5-Wj8,6258
|
|
59
|
+
financial_agent/quant/risk/state.py,sha256=TZFiP7xiZJcnJ5HV4Az1PpfL3nm7qKFoR-nUFa-0bmA,2906
|
|
60
|
+
financial_agent/quant/runner/__init__.py,sha256=qfdYCrYu5hvU_apYLZ_5nh4or7jVpkWDJMy419pCLBo,556
|
|
61
|
+
financial_agent/quant/runner/config.py,sha256=8lN5ARyZlMfcb0Ga-rfaLUcX2CO0AiUXUZA-MEsUw5U,10760
|
|
62
|
+
financial_agent/quant/runner/promotion.py,sha256=lTom7o-rLPoVAiNYgtbZXLQQwCiUHNTWkX3THg5D3v0,10034
|
|
63
|
+
financial_agent/quant/runner/report.py,sha256=HVdL1y019tsaB4t0dYkFj2-7zuuJtMSPwqnygZC_JOo,8966
|
|
64
|
+
financial_agent/quant/runner/session.py,sha256=ikeNO6Dpmv1mKF2DKyx5deDAOHDcKQnUC-zcohupj04,26286
|
|
65
|
+
financial_agent/quant/strategies/__init__.py,sha256=BMMGBUTp80_WfytjcgCgG54aegZEyngWMQbTZpRGz7E,484
|
|
66
|
+
financial_agent/quant/strategies/base.py,sha256=_vZ4pLaYF8y2SiefMd0miz9hU8Of8-UY_x-X26TNM-o,1363
|
|
67
|
+
financial_agent/quant/strategies/benchmarks.py,sha256=lWajj7iwMiY09tGlxr-sj2pDMkWsB0NcgT9wYrqdMy0,2048
|
|
68
|
+
financial_agent/quant/strategies/momentum.py,sha256=XAMAA9gdOBqz-CUOT4Xp93TE1YTTFxS0_wsgM5llJJs,2333
|
|
69
|
+
financial_agent/quant/strategies/registry.py,sha256=9VA5SG7fwYTk1rvRh0Z00PBJ4K3AOSq7mPJ8imDOHIM,2418
|
|
70
|
+
financial_agent/quant/strategies/research.py,sha256=h0oC0lSWW_IfSXVRfnqJ3v653l4SXT-m_g0xZgRU8s0,8693
|
|
71
|
+
financial_agent/quant/strategies/trend.py,sha256=PYzPekZGdkQLqmjK0QKtJ4a_0eSiVT0sum7TsT6hX0E,3069
|
|
72
|
+
financial_agent/quant/validation/__init__.py,sha256=HP_ZBXhWON0LyfBW3wAOicTqS2V9oFCc7WkPDdGQm_M,1005
|
|
73
|
+
financial_agent/quant/validation/bootstrap.py,sha256=Oyy2cnhMv8Y6YcmhAYJARXK2dLoaQhm99qWHb5iMNdI,1509
|
|
74
|
+
financial_agent/quant/validation/certificate.py,sha256=XoZSKyflCMW8l15eVLZdCeXW0MCeJF59B2M2mRP1Zt4,7260
|
|
75
|
+
financial_agent/quant/validation/gate.py,sha256=nKN3V-fKMD2ATs_uS5ws493Tprj_4EixMmEQR6mgxNk,10018
|
|
76
|
+
financial_agent/quant/validation/overfitting.py,sha256=F-RdWwmwiQJJPMjTno6yI6J5s1ucASiL9nWwJcDNSHQ,6007
|
|
77
|
+
financial_agent/quant/validation/stress.py,sha256=fItx8WuMHflWGueKI6mnha1R-4Jdfa9B0563YCjSNRw,1017
|
|
78
|
+
financial_agent/quant/validation/walkforward.py,sha256=fKck7Re-HER51jknydhCml7bxZg6j29xufiDHHlqmqc,5832
|
|
79
|
+
financial_agent/rl/__init__.py,sha256=FXPKHXw8bwCLGAug8d02DmUG8IYIPqPd1YBO_rcdOWA,319
|
|
80
|
+
financial_agent/rl/agent.py,sha256=qxDjXyZoYls1CW5Z7dlWj6R5xMXXH2hg3aie1Lt5y30,3206
|
|
81
|
+
financial_agent/rl/environment.py,sha256=6kmDiUOlU5o3SKh1QhtLhrQYbapzM-yyzp-yt8dAufo,6259
|
|
82
|
+
financial_agent/rl/trainer.py,sha256=KtyztrXCfCe4cpt1exLc4RkiHvZF2zSwJJEc8PG9nfM,4871
|
|
83
|
+
financial_agent/trading/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
84
|
+
financial_agent/trading/backtest.py,sha256=ucBMu_IMGeLzbcnyhyeCV9RAVAQBm4E2FPnZleCbgxE,4431
|
|
85
|
+
financial_agent/trading/autotrain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
86
|
+
financial_agent/trading/autotrain/training.py,sha256=6E9ryktkC5D7nxEbX9YcbtmTd270f2BGzQ5x_9FrQKY,3049
|
|
87
|
+
financial_agent/trading/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
88
|
+
financial_agent/trading/config/config.py,sha256=fYWSCnvWgQ5sGzOQCZZFnTwo9gnz1LvdgQM7g_CevHk,25462
|
|
89
|
+
financial_agent/trading/marketdata/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
90
|
+
financial_agent/trading/marketdata/yahoodownloader.py,sha256=RBKasDSVbyt6pRbd_WNHOJPeEOPyWn8qpZ2ELViv3N0,3324
|
|
91
|
+
financial_agent/trading/model/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
92
|
+
financial_agent/trading/model/models.py,sha256=gYdHwkRx1w0-9C7ylOEWuVB1dL0hVvPVfGRP1h8lSlk,24159
|
|
93
|
+
financial_agent/trading/preprocessing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
94
|
+
financial_agent/trading/preprocessing/data.py,sha256=wF2H4BCQS-7SfDR9F82wngqA-TrrrlkdGD7wGJzpR2M,896
|
|
95
|
+
financial_agent/trading/preprocessing/preprocessors.py,sha256=142Ca9luA3uY6gug_nlE0MGiWzSEb3_pPAOLEkOJjIk,6101
|
|
96
|
+
financial_agent/trading/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
97
|
+
financial_agent/trading/utils/gpu_config.py,sha256=V59lpj8GUdGH70qSaQSP2ub8gGumdvkLjkBOfWuWaE0,6715
|
|
98
|
+
financial_agent/trading/utils/main.py,sha256=YQcN460Vnj-IxJFOM6N5HrmTyhbDmUaqVXkjxGrM6hA,1483
|
|
99
|
+
financial_agent/trading/utils/setup_gpu_for_notebooks.py,sha256=6STjRQ5XKMgEU64SMxiE-F9euZ2RhIe2fpkNRsuzX_A,3672
|
|
100
|
+
financial_agent/harness/_system/factor_scoring.py,sha256=4CO_7gJna8Pf0OhC2cAf5ypFuGkuEPJukJtyaDYTrYE,6685
|
|
101
|
+
financial_agent/harness/_system/settlement_ledger.py,sha256=ulyKRgHWy8RNu1j2OnunqfP3DdXInqIV7GOjgd1pQJw,46444
|
|
102
|
+
fa_quant-1.2.1.dist-info/METADATA,sha256=FVWdgbHs3Xr3SyACfYenIYj4zSyr5Ye1hntz39VoN-k,13860
|
|
103
|
+
fa_quant-1.2.1.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
104
|
+
fa_quant-1.2.1.dist-info/entry_points.txt,sha256=xsR4gziarTDnB0JTWZp4sagn2qrmB3P5LDbpr2_LcE4,65
|
|
105
|
+
fa_quant-1.2.1.dist-info/licenses/LICENSE,sha256=tvAxYuT26evE9ZZxZgNxHM7uXEHiuYyaWWYj3JGnWUs,1064
|
|
106
|
+
fa_quant-1.2.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Kenneth
|
|
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 @@
|
|
|
1
|
+
"""financial-agent: RL framework for financial agents."""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import datetime
|
|
3
|
+
|
|
4
|
+
import IPython
|
|
5
|
+
import IPython.display
|
|
6
|
+
import matplotlib as mpl
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import seaborn as sns
|
|
11
|
+
import tensorflow as tf
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Baseline(tf.keras.Model):
|
|
15
|
+
def __init__(self, label_index=None):
|
|
16
|
+
super().__init__()
|
|
17
|
+
self.label_index = label_index
|
|
18
|
+
|
|
19
|
+
def call(self, inputs):
|
|
20
|
+
if self.label_index is None:
|
|
21
|
+
return inputs
|
|
22
|
+
result = inputs[:, :, self.label_index]
|
|
23
|
+
return result[:, :, tf.newaxis]
|
|
File without changes
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import datetime
|
|
3
|
+
|
|
4
|
+
import IPython
|
|
5
|
+
import IPython.display
|
|
6
|
+
import matplotlib as mpl
|
|
7
|
+
import matplotlib.pyplot as plt
|
|
8
|
+
import numpy as np
|
|
9
|
+
import pandas as pd
|
|
10
|
+
import seaborn as sns
|
|
11
|
+
import tensorflow as tf
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WindowGenerator:
|
|
15
|
+
"""
|
|
16
|
+
train_df
|
|
17
|
+
input_width: the length of time series input
|
|
18
|
+
label_width: the
|
|
19
|
+
|
|
20
|
+
"""
|
|
21
|
+
def __init__(self, train_df, test_df,
|
|
22
|
+
input_width, label_width, shift,
|
|
23
|
+
label_columns=None):
|
|
24
|
+
# Store the raw data.
|
|
25
|
+
self.train_df = train_df
|
|
26
|
+
self.test_df = test_df
|
|
27
|
+
|
|
28
|
+
# Work out the label column indices.
|
|
29
|
+
self.label_columns = label_columns
|
|
30
|
+
if label_columns is not None:
|
|
31
|
+
self.label_columns_indices = {name: i for i, name in
|
|
32
|
+
enumerate(label_columns)}
|
|
33
|
+
self.column_indices = {name: i for i, name in
|
|
34
|
+
enumerate(train_df.columns)}
|
|
35
|
+
|
|
36
|
+
# Work out the window parameters.
|
|
37
|
+
self.input_width = input_width
|
|
38
|
+
self.label_width = label_width
|
|
39
|
+
self.shift = shift
|
|
40
|
+
|
|
41
|
+
self.total_window_size = input_width + shift
|
|
42
|
+
|
|
43
|
+
self.input_slice = slice(0, input_width)
|
|
44
|
+
self.input_indices = np.arange(self.total_window_size)[self.input_slice]
|
|
45
|
+
|
|
46
|
+
self.label_start = self.total_window_size - self.label_width
|
|
47
|
+
self.labels_slice = slice(self.label_start, None)
|
|
48
|
+
self.label_indices = np.arange(self.total_window_size)[self.labels_slice]
|
|
49
|
+
|
|
50
|
+
def __repr__(self):
|
|
51
|
+
return '\n'.join([
|
|
52
|
+
f'Total window size: {self.total_window_size}',
|
|
53
|
+
f'Input indices: {self.input_indices}',
|
|
54
|
+
f'Label indices: {self.label_indices}',
|
|
55
|
+
f'Label column name(s): {self.label_columns}'])
|
|
56
|
+
|
|
57
|
+
def split_window(self, features):
|
|
58
|
+
inputs = features[:, self.input_slice, :]
|
|
59
|
+
labels = features[:, self.labels_slice, :]
|
|
60
|
+
if self.label_columns is not None:
|
|
61
|
+
labels = tf.stack(
|
|
62
|
+
[labels[:, :, self.column_indices[name]] for name in self.label_columns],
|
|
63
|
+
axis=-1)
|
|
64
|
+
|
|
65
|
+
# Slicing doesn't preserve static shape information, so set the shapes
|
|
66
|
+
# manually. This way the `tf.data.Datasets` are easier to inspect.
|
|
67
|
+
inputs.set_shape([None, self.input_width, None])
|
|
68
|
+
labels.set_shape([None, self.label_width, None])
|
|
69
|
+
|
|
70
|
+
return inputs, labels
|
|
71
|
+
|
|
72
|
+
def plot(self, model=None, plot_col='T (degC)', max_subplots=3):
|
|
73
|
+
inputs, labels = self.example
|
|
74
|
+
plt.figure(figsize=(12, 8))
|
|
75
|
+
plot_col_index = self.column_indices[plot_col]
|
|
76
|
+
max_n = min(max_subplots, len(inputs))
|
|
77
|
+
for n in range(max_n):
|
|
78
|
+
plt.subplot(max_n, 1, n + 1)
|
|
79
|
+
plt.ylabel(f'{plot_col} [normed]')
|
|
80
|
+
plt.plot(self.input_indices, inputs[n, :, plot_col_index],
|
|
81
|
+
label='Inputs', marker='.', zorder=-10)
|
|
82
|
+
|
|
83
|
+
if self.label_columns:
|
|
84
|
+
label_col_index = self.label_columns_indices.get(plot_col, None)
|
|
85
|
+
else:
|
|
86
|
+
label_col_index = plot_col_index
|
|
87
|
+
|
|
88
|
+
if label_col_index is None:
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
plt.scatter(self.label_indices, labels[n, :, label_col_index],
|
|
92
|
+
edgecolors='k', label='Labels', c='#2ca02c', s=64)
|
|
93
|
+
if model is not None:
|
|
94
|
+
predictions = model(inputs)
|
|
95
|
+
plt.scatter(self.label_indices, predictions[n, :, label_col_index],
|
|
96
|
+
marker='X', edgecolors='k', label='Predictions',
|
|
97
|
+
c='#ff7f0e', s=64)
|
|
98
|
+
|
|
99
|
+
if n == 0:
|
|
100
|
+
plt.legend()
|
|
101
|
+
|
|
102
|
+
plt.xlabel('Time [h]')
|
|
103
|
+
|
|
104
|
+
def make_dataset(self, data):
|
|
105
|
+
data = np.array(data, dtype=np.float32)
|
|
106
|
+
ds = tf.keras.preprocessing.timeseries_dataset_from_array(
|
|
107
|
+
data=data,
|
|
108
|
+
targets=None,
|
|
109
|
+
sequence_length=self.total_window_size,
|
|
110
|
+
sequence_stride=1,
|
|
111
|
+
shuffle=True,
|
|
112
|
+
batch_size=32, )
|
|
113
|
+
|
|
114
|
+
ds = ds.map(self.split_window)
|
|
115
|
+
|
|
116
|
+
return ds
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def train(self):
|
|
120
|
+
return self.make_dataset(self.train_df)
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def test(self):
|
|
124
|
+
return self.make_dataset(self.test_df)
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def example(self):
|
|
128
|
+
"""Get and cache an example batch of `inputs, labels` for plotting."""
|
|
129
|
+
result = getattr(self, '_example', None)
|
|
130
|
+
if result is None:
|
|
131
|
+
# No example batch was found, so get one from the `.train` dataset
|
|
132
|
+
result = next(iter(self.train))
|
|
133
|
+
# And cache it for next time
|
|
134
|
+
self._example = result
|
|
135
|
+
return result
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Deterministic harness for LLM-driven financial research runs (spike, v0).
|
|
2
|
+
|
|
3
|
+
The harness owns everything that must be exact -- arithmetic, provenance,
|
|
4
|
+
schemas, gates, and run lifecycle -- so the model only contributes judgment.
|
|
5
|
+
Skills (open Agent Skills format, ``SKILL.md`` directories) tell a model
|
|
6
|
+
*when and why* to call harness tools; the harness decides *what is allowed*.
|
|
7
|
+
|
|
8
|
+
Design and spike findings: ``plan/2026-09-28-financial-harness-and-skills.md``.
|
|
9
|
+
Standard library only, like the helpers in
|
|
10
|
+
``agents/equity/daily_investment_system/``.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from financial_agent.harness.audit import AuditReport, audit_output_dir, audit_record
|
|
14
|
+
from financial_agent.harness.gates import (
|
|
15
|
+
Reachability,
|
|
16
|
+
StatusDecision,
|
|
17
|
+
decide_status,
|
|
18
|
+
go_reachability,
|
|
19
|
+
investability,
|
|
20
|
+
)
|
|
21
|
+
from financial_agent.harness.kernels import (
|
|
22
|
+
EquityInputs,
|
|
23
|
+
Holding,
|
|
24
|
+
KernelError,
|
|
25
|
+
MarketInputs,
|
|
26
|
+
PortfolioRisk,
|
|
27
|
+
equity_record,
|
|
28
|
+
market_forecast_records,
|
|
29
|
+
portfolio_feasibility,
|
|
30
|
+
price_risk,
|
|
31
|
+
)
|
|
32
|
+
from financial_agent.harness.ledger import LedgerRow, SourceLedger
|
|
33
|
+
from financial_agent.harness.lifecycle import RunLifecycle, RunState
|
|
34
|
+
from financial_agent.harness.market_calendar import Session, session
|
|
35
|
+
from financial_agent.harness.policy import Policy, load_policy
|
|
36
|
+
from financial_agent.harness.schema import validate_payload
|
|
37
|
+
from financial_agent.harness.scoring import NameInputs, Scoreboard, score_universe
|
|
38
|
+
from financial_agent.harness.skills import Skill, SkillRegistry, validate_skill_dir
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"AuditReport",
|
|
42
|
+
"EquityInputs",
|
|
43
|
+
"Holding",
|
|
44
|
+
"KernelError",
|
|
45
|
+
"LedgerRow",
|
|
46
|
+
"MarketInputs",
|
|
47
|
+
"NameInputs",
|
|
48
|
+
"Policy",
|
|
49
|
+
"PortfolioRisk",
|
|
50
|
+
"Reachability",
|
|
51
|
+
"RunLifecycle",
|
|
52
|
+
"RunState",
|
|
53
|
+
"Scoreboard",
|
|
54
|
+
"Session",
|
|
55
|
+
"Skill",
|
|
56
|
+
"SkillRegistry",
|
|
57
|
+
"SourceLedger",
|
|
58
|
+
"StatusDecision",
|
|
59
|
+
"audit_output_dir",
|
|
60
|
+
"audit_record",
|
|
61
|
+
"decide_status",
|
|
62
|
+
"equity_record",
|
|
63
|
+
"go_reachability",
|
|
64
|
+
"investability",
|
|
65
|
+
"load_policy",
|
|
66
|
+
"market_forecast_records",
|
|
67
|
+
"portfolio_feasibility",
|
|
68
|
+
"price_risk",
|
|
69
|
+
"score_universe",
|
|
70
|
+
"session",
|
|
71
|
+
"validate_payload",
|
|
72
|
+
"validate_skill_dir",
|
|
73
|
+
]
|