finance-ai-quality-benchmark 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pars1905
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,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: finance-ai-quality-benchmark
3
+ Version: 0.1.0
4
+ Summary: Reproducible benchmark for evaluating AI answers to financial-statement questions: numeric accuracy and exact source traceability.
5
+ Author: pars1905
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/pars1905/finance-ai-quality-benchmark
8
+ Project-URL: Issues, https://github.com/pars1905/finance-ai-quality-benchmark/issues
9
+ Keywords: llm,evaluation,benchmark,finance,financial-statements,ai-evaluation
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Topic :: Office/Business :: Financial
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # Finance AI Quality Benchmark
22
+
23
+ [![CI](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml/badge.svg)](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml)
24
+ [![PyPI](https://img.shields.io/pypi/v/finance-ai-quality-benchmark.svg)](https://pypi.org/project/finance-ai-quality-benchmark/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
26
+
27
+ An open-source, reproducible benchmark for evaluating AI answers to financial-statement questions. It checks two things separately: whether the number is correct, and whether the answer cites the exact source fields it used.
28
+
29
+ **Why it exists:** Most LLM benchmarks focus on general knowledge or code. Few open tools check whether a model's financial calculations (margins, growth, ratios) are numerically correct and traceable to the evidence. Models often sound confident while getting these numbers wrong. This project makes that measurable and repeatable.
30
+
31
+ **Status:** Working pilot with a synthetic control and three curated excerpts from public annual reports. Not a validated full-document finance benchmark. No confidential employer or client data. Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
32
+
33
+ ## Install
34
+
35
+ Python 3.10+ is required. There are no third-party dependencies.
36
+
37
+ ```bash
38
+ pip install finance-ai-quality-benchmark
39
+ finance-benchmark run --provider baseline
40
+ ```
41
+
42
+ `finance-benchmark` is equivalent to `python -m finance_benchmark`; every command below works with either form. To develop locally, clone the repository and run `pip install -e .`.
43
+
44
+ ## What it measures
45
+
46
+ - 30 questions: six fictional companies × five financial calculations (gross margin, revenue growth, operating margin, current ratio, debt-to-equity).
47
+ - Separately scores numeric answers (absolute tolerance 0.01) and exact source-field references; strict pass requires both. Percentage questions accept a numeric value or a numeric string ending in `%`; ratios reject `%`. API errors are reported as coverage failures, not incorrect model answers.
48
+ - Produces per-case failure codes and JSON/Markdown reports. Every nonempty explanation is flagged for expert review; the script **does not claim to verify the truth of prose**.
49
+ - Includes deliberately flawed sample answers to demonstrate failure detection.
50
+
51
+ All values in `finance_benchmark/data/statements.json` are fictional and in consistent arbitrary units. The benchmark tests arithmetic and traceability, not accounting interpretation, financial advice or investment performance.
52
+
53
+ ## Interactive public-equity valuation demo
54
+
55
+ [Open the public valuation interface](https://finance-ai-quality-demo-osman.affableeucalyptus1.chatgpt.site). The visitor starts with a fictional ready-to-use example. For a real company, choose **My company's data** and load a single [financial summary JSON template](web/sample-input.json), or open the advanced manual fields. Only the source choice, company and market price, and country condition are visible initially. Missing growth, discount and peer-multiple assumptions in an uploaded file use clearly labeled illustrative defaults that should be reviewed before interpreting results. The browser reads the file locally and does not upload it. The interface shows **five per-share methods** across bearish, base and bullish assumptions:
56
+
57
+ 1. FCFF DCF: five years of firm free cash flow and a terminal value, discounted at WACC; subtract net debt.
58
+ 2. FCFE DCF: five years of equity free cash flow and a terminal value, discounted at cost of equity.
59
+ 3. Comparable P/E applied to normalized net income.
60
+ 4. Comparable EV/EBITDA applied to EBITDA, then subtract net debt.
61
+ 5. Comparable P/B applied to book equity.
62
+
63
+ A country-conditions control offers illustrative **ordinary conditions, conflict, ceasefire and peace agreement** shifts to growth, discount rates and comparable multiples; every effect is visible and editable. These presets are hypothetical, not observations or forecasts about a real country. Bear/base/bull adjustments are separate. The page displays a median for navigation only; correlated models are not independent confirmations. Methods with nonpositive earnings, EBITDA, book equity, or invalid DCF discount spreads show unavailable rather than a fabricated value.
64
+
65
+ [Browser source](web/index.html) · [Calculation module](web/valuation.mjs) · [Model tests](web/tests/valuation.test.mjs). To run locally:
66
+
67
+ ```bash
68
+ python -m http.server 8000 --directory web
69
+ node --test web/tests/valuation.test.mjs
70
+ ```
71
+
72
+ Open http://localhost:8000. The sample company is fictional. The page does **not** fetch market data, validate uploaded filings, call an AI model, store form entries, or provide a verified price target. All inputs must come from consistently dated, denominated and reviewed company filings and peer data. The Python benchmark below remains the separate AI-answer evaluation product.
73
+
74
+ ## Three runnable customer conversation demos
75
+
76
+ The [Turkish demo walkthrough](docs/three-customer-demos-tr.md) covers three fictional client scenarios: management reporting (correct answer), credit analysis (wrong number), and research review (wrong source reference). Sample responses are hand-authored to demonstrate the scorer; they are **not actual model outputs or customer engagements**.
77
+
78
+ ```bash
79
+ python -m finance_benchmark evaluate examples/demo-fpna-predictions.json --dataset demo-fpna-v1 --output results/demo-fpna
80
+ python -m finance_benchmark evaluate examples/demo-credit-predictions.json --dataset demo-credit-v1 --output results/demo-credit
81
+ python -m finance_benchmark evaluate examples/demo-research-predictions.json --dataset demo-research-v1 --output results/demo-research
82
+ ```
83
+
84
+ Each demo has one case. The expected strict pass rates are 100%, 0%, and 0% respectively. The second case demonstrates a numeric failure with correct references; the third demonstrates a source failure despite a correct number. To test a live model on any of them, use the existing `run --provider gemini --dataset ...` command with a key set in your environment.
85
+
86
+ ## Three public-filing examples
87
+
88
+ `finance_benchmark/data/real_filings_v1.json` contains one independently checkable arithmetic question per company. Values are manually transcribed from fixed SEC annual filings; each case stores its accession number, filing URL, table location, reporting units, source IDs, and reference answer.
89
+
90
+ | Company | Annual report | Question | Reference answer |
91
+ | --- | --- | --- | ---: |
92
+ | [Microsoft](https://www.sec.gov/Archives/edgar/data/789019/000095017025100235/msft-20250630.htm) | FY2025 10-K | Revenue growth, FY2024 to FY2025 | 14.93% |
93
+ | [Apple](https://www.sec.gov/Archives/edgar/data/320193/000032019325000079/aapl-20250927.htm) | FY2025 10-K | Services share of total FY2025 net sales | 26.23% |
94
+ | [Turkcell](https://www.sec.gov/Archives/edgar/data/1071321/000110465926044740/tkc-20251231x20f.htm) | FY2025 20-F | Revenue growth using the FY2024 comparable amount from the **same FY2025 report** | 10.69% |
95
+
96
+ Turkcell applies IAS 29 inflation accounting; comparing the FY2025 figure with the previously published FY2024 report's unadjusted amount would be invalid. Both figures here come from the FY2025 filing and use TRY thousands. These are three curated **filing excerpts**, so the model is tested on cited financial reasoning, not retrieval from complete reports. The reference control copies answers and should not be presented as a model result.
97
+
98
+ To run the three-case Gemini pilot after setting the Codespaces secret `GEMINI_API_KEY`:
99
+
100
+ ```bash
101
+ python -m finance_benchmark run --provider gemini --dataset real-filings-v1 --delay-seconds 20 --output results/real-filings-gemini
102
+ ```
103
+
104
+ If quota errors occur, repeat with `--resume results/real-filings-gemini/predictions.json` and a different output directory after the quota resets. Review `predictions.json` explanations manually; the scorer checks numbers and reference IDs, not whether prose is fully supported by the filing.
105
+
106
+ A [manual review of the three Gemini explanations](reviews/real-filings-v1-gemini-review.md) records the filing evidence, independent calculations, and scope of the 3/3 pilot result. The automatic report still flags all explanations for expert review because it does not read this note.
107
+
108
+ Transient HTTP 500/503/504 responses are retried twice with short exponential waits. HTTP 429 quota errors are saved for a later `--resume` run; the result report shows the HTTP status separately from model quality.
109
+
110
+ For a prospective customer's first call, demo, model connection, tailored dataset and acceptance steps, see the [Turkish customer pilot guide](docs/customer-pilot-guide-tr.md).
111
+
112
+ ## Run without API keys
113
+
114
+ ```bash
115
+ python -m unittest discover -s tests -v
116
+ python -m finance_benchmark run --provider baseline
117
+ python -m finance_benchmark evaluate examples/sample_predictions.json --output results/sample
118
+ ```
119
+
120
+ The baseline copies gold arithmetic and citations as a **harness control**; its 100% result is not an AI performance claim. The sample yields errors and missing predictions by design. Accuracy is computed over evaluated responses; coverage shows how many requested cases received a usable response. Reports are written to `results/report.json`, `results/report.md`, and `results/predictions.json` (or the chosen output directory).
121
+
122
+ GitHub Actions runs these checks on every push and attaches an `evaluation-reports` artifact with both control and deliberately flawed sample outputs.
123
+
124
+ ## Evaluate your own predictions
125
+
126
+ Make a JSON list of objects with `case_id`, `value`, `source_refs`, `explanation`, and `abstained`; see `examples/sample_predictions.json`. Run:
127
+
128
+ ```bash
129
+ python -m finance_benchmark evaluate path/to/predictions.json --output results/my-model
130
+ ```
131
+
132
+ Source references must exactly match the fact IDs, e.g. `atlas:revenue_2025`. Wrong or duplicate IDs fail the source check. Missing predictions count as failures. For the full set, inspect `finance_benchmark.core.cases()`.
133
+
134
+ ## Try an OpenAI-compatible chat completions API
135
+
136
+ Set credentials locally; never commit keys. The model must support `response_format: {"type":"json_object"}`. Start with three calls to limit cost:
137
+
138
+ ```bash
139
+ export AI_API_KEY='your-key'
140
+ export AI_API_BASE_URL='https://api.openai.com/v1'
141
+ python -m finance_benchmark run --provider api --model YOUR_MODEL_ID --limit 3 --output results/api-trial
142
+ ```
143
+
144
+ Omit `AI_API_BASE_URL` to use the shown default. The CLI sends one request per case. API/parsing errors are counted as abstentions and printed to stderr; the report preserves all returned predictions. **Only run with a trusted endpoint** and do not put confidential customer data in this dataset.
145
+
146
+ ### Gemini free-tier trial
147
+
148
+ Store your Google AI Studio key as a GitHub Codespaces secret named `GEMINI_API_KEY` for this repository. Create a new Codespace (or restart an existing one to load a newly added secret), then run:
149
+
150
+ ```bash
151
+ python -m finance_benchmark run --provider gemini --limit 3 --output results/gemini-trial
152
+ cat results/gemini-trial/report.md
153
+ ```
154
+
155
+ The Gemini provider defaults to `gemini-2.5-flash` and Google's OpenAI-compatible Chat Completions endpoint. You can override the model with `--model`. The key is read from the environment and is never written to the report. `--limit 3` reports scores over three cases. Free-tier availability and quotas depend on your Google AI Studio project. Do not commit `results/` or the key.
156
+
157
+ If you see HTTP 429, inspect the rate limits for your project in Google AI Studio. A slower trial can help with per-minute limits:
158
+
159
+ ```bash
160
+ python -m finance_benchmark run --provider gemini --limit 10 --delay-seconds 20 --output results/gemini-slow
161
+ ```
162
+
163
+ If a daily quota is exhausted, wait for the quota reset. API failures remain in `predictions.json` but are shown separately from model accuracy. To re-score a previous run created with the older version of this project **without sending new API requests**, use:
164
+
165
+ ```bash
166
+ python -m finance_benchmark evaluate results/gemini-10/predictions.json --limit 10 --output results/gemini-10-rescored
167
+ ```
168
+
169
+ After the quota allows more requests, keep the six successful answers and retry only the four API errors:
170
+
171
+ ```bash
172
+ python -m finance_benchmark run --provider gemini --limit 10 --resume results/gemini-10/predictions.json --delay-seconds 20 --output results/gemini-10-complete
173
+ ```
174
+
175
+ `--resume` accepts previous predictions from the same first N cases, validates their IDs, and reuses genuine model responses (including genuine abstentions). It retries missing cases and both old and new API errors. The delay applies between actual API requests only.
176
+
177
+ ## Expert quality rubric (next pilot)
178
+
179
+ | Dimension | Automated here | Expert review |
180
+ | --- | --- | --- |
181
+ | Formula and rounding | Numeric value vs. reference answer | Whether the chosen financial metric fits the question |
182
+ | Evidence | Exact source-field IDs | Whether cited evidence supports the prose |
183
+ | Abstention | Unnecessary abstentions flagged | Whether a genuinely ambiguous question should be declined |
184
+ | Explanation | Marked for review | Unsupported claims, overconfidence, helpfulness |
185
+
186
+ The next dataset should use licensed public filings with exact page/table references, two independent expert annotations for ambiguous examples, a written adjudication log, and error rates by category. Keep it separate from the synthetic control so results are never confused.
187
+
188
+ ## Docker
189
+
190
+ ```bash
191
+ docker build -t finance-ai-quality-benchmark .
192
+ docker run --rm finance-ai-quality-benchmark
193
+ ```
194
+
195
+ The default container runs the arithmetic control and prints the Markdown summary. For persisted results, run the Python command locally or mount a results directory.
196
+
197
+ ## Scope and limitations
198
+
199
+ This is an evaluation harness, not a finance model. The reference data is invented; numeric accuracy on 30 templated questions does not predict performance on real filings. The scorer does not evaluate hallucinations in explanations, assess legal compliance, or judge whether a company is financially healthy. Human judgment and a separate public-data pilot are required before making those claims.
200
+
201
+ ## Contributing
202
+
203
+ New test cases (especially hard ones from public filings), providers, and documentation improvements are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
204
+
205
+ License: MIT.
@@ -0,0 +1,185 @@
1
+ # Finance AI Quality Benchmark
2
+
3
+ [![CI](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml/badge.svg)](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/finance-ai-quality-benchmark.svg)](https://pypi.org/project/finance-ai-quality-benchmark/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ An open-source, reproducible benchmark for evaluating AI answers to financial-statement questions. It checks two things separately: whether the number is correct, and whether the answer cites the exact source fields it used.
8
+
9
+ **Why it exists:** Most LLM benchmarks focus on general knowledge or code. Few open tools check whether a model's financial calculations (margins, growth, ratios) are numerically correct and traceable to the evidence. Models often sound confident while getting these numbers wrong. This project makes that measurable and repeatable.
10
+
11
+ **Status:** Working pilot with a synthetic control and three curated excerpts from public annual reports. Not a validated full-document finance benchmark. No confidential employer or client data. Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
12
+
13
+ ## Install
14
+
15
+ Python 3.10+ is required. There are no third-party dependencies.
16
+
17
+ ```bash
18
+ pip install finance-ai-quality-benchmark
19
+ finance-benchmark run --provider baseline
20
+ ```
21
+
22
+ `finance-benchmark` is equivalent to `python -m finance_benchmark`; every command below works with either form. To develop locally, clone the repository and run `pip install -e .`.
23
+
24
+ ## What it measures
25
+
26
+ - 30 questions: six fictional companies × five financial calculations (gross margin, revenue growth, operating margin, current ratio, debt-to-equity).
27
+ - Separately scores numeric answers (absolute tolerance 0.01) and exact source-field references; strict pass requires both. Percentage questions accept a numeric value or a numeric string ending in `%`; ratios reject `%`. API errors are reported as coverage failures, not incorrect model answers.
28
+ - Produces per-case failure codes and JSON/Markdown reports. Every nonempty explanation is flagged for expert review; the script **does not claim to verify the truth of prose**.
29
+ - Includes deliberately flawed sample answers to demonstrate failure detection.
30
+
31
+ All values in `finance_benchmark/data/statements.json` are fictional and in consistent arbitrary units. The benchmark tests arithmetic and traceability, not accounting interpretation, financial advice or investment performance.
32
+
33
+ ## Interactive public-equity valuation demo
34
+
35
+ [Open the public valuation interface](https://finance-ai-quality-demo-osman.affableeucalyptus1.chatgpt.site). The visitor starts with a fictional ready-to-use example. For a real company, choose **My company's data** and load a single [financial summary JSON template](web/sample-input.json), or open the advanced manual fields. Only the source choice, company and market price, and country condition are visible initially. Missing growth, discount and peer-multiple assumptions in an uploaded file use clearly labeled illustrative defaults that should be reviewed before interpreting results. The browser reads the file locally and does not upload it. The interface shows **five per-share methods** across bearish, base and bullish assumptions:
36
+
37
+ 1. FCFF DCF: five years of firm free cash flow and a terminal value, discounted at WACC; subtract net debt.
38
+ 2. FCFE DCF: five years of equity free cash flow and a terminal value, discounted at cost of equity.
39
+ 3. Comparable P/E applied to normalized net income.
40
+ 4. Comparable EV/EBITDA applied to EBITDA, then subtract net debt.
41
+ 5. Comparable P/B applied to book equity.
42
+
43
+ A country-conditions control offers illustrative **ordinary conditions, conflict, ceasefire and peace agreement** shifts to growth, discount rates and comparable multiples; every effect is visible and editable. These presets are hypothetical, not observations or forecasts about a real country. Bear/base/bull adjustments are separate. The page displays a median for navigation only; correlated models are not independent confirmations. Methods with nonpositive earnings, EBITDA, book equity, or invalid DCF discount spreads show unavailable rather than a fabricated value.
44
+
45
+ [Browser source](web/index.html) · [Calculation module](web/valuation.mjs) · [Model tests](web/tests/valuation.test.mjs). To run locally:
46
+
47
+ ```bash
48
+ python -m http.server 8000 --directory web
49
+ node --test web/tests/valuation.test.mjs
50
+ ```
51
+
52
+ Open http://localhost:8000. The sample company is fictional. The page does **not** fetch market data, validate uploaded filings, call an AI model, store form entries, or provide a verified price target. All inputs must come from consistently dated, denominated and reviewed company filings and peer data. The Python benchmark below remains the separate AI-answer evaluation product.
53
+
54
+ ## Three runnable customer conversation demos
55
+
56
+ The [Turkish demo walkthrough](docs/three-customer-demos-tr.md) covers three fictional client scenarios: management reporting (correct answer), credit analysis (wrong number), and research review (wrong source reference). Sample responses are hand-authored to demonstrate the scorer; they are **not actual model outputs or customer engagements**.
57
+
58
+ ```bash
59
+ python -m finance_benchmark evaluate examples/demo-fpna-predictions.json --dataset demo-fpna-v1 --output results/demo-fpna
60
+ python -m finance_benchmark evaluate examples/demo-credit-predictions.json --dataset demo-credit-v1 --output results/demo-credit
61
+ python -m finance_benchmark evaluate examples/demo-research-predictions.json --dataset demo-research-v1 --output results/demo-research
62
+ ```
63
+
64
+ Each demo has one case. The expected strict pass rates are 100%, 0%, and 0% respectively. The second case demonstrates a numeric failure with correct references; the third demonstrates a source failure despite a correct number. To test a live model on any of them, use the existing `run --provider gemini --dataset ...` command with a key set in your environment.
65
+
66
+ ## Three public-filing examples
67
+
68
+ `finance_benchmark/data/real_filings_v1.json` contains one independently checkable arithmetic question per company. Values are manually transcribed from fixed SEC annual filings; each case stores its accession number, filing URL, table location, reporting units, source IDs, and reference answer.
69
+
70
+ | Company | Annual report | Question | Reference answer |
71
+ | --- | --- | --- | ---: |
72
+ | [Microsoft](https://www.sec.gov/Archives/edgar/data/789019/000095017025100235/msft-20250630.htm) | FY2025 10-K | Revenue growth, FY2024 to FY2025 | 14.93% |
73
+ | [Apple](https://www.sec.gov/Archives/edgar/data/320193/000032019325000079/aapl-20250927.htm) | FY2025 10-K | Services share of total FY2025 net sales | 26.23% |
74
+ | [Turkcell](https://www.sec.gov/Archives/edgar/data/1071321/000110465926044740/tkc-20251231x20f.htm) | FY2025 20-F | Revenue growth using the FY2024 comparable amount from the **same FY2025 report** | 10.69% |
75
+
76
+ Turkcell applies IAS 29 inflation accounting; comparing the FY2025 figure with the previously published FY2024 report's unadjusted amount would be invalid. Both figures here come from the FY2025 filing and use TRY thousands. These are three curated **filing excerpts**, so the model is tested on cited financial reasoning, not retrieval from complete reports. The reference control copies answers and should not be presented as a model result.
77
+
78
+ To run the three-case Gemini pilot after setting the Codespaces secret `GEMINI_API_KEY`:
79
+
80
+ ```bash
81
+ python -m finance_benchmark run --provider gemini --dataset real-filings-v1 --delay-seconds 20 --output results/real-filings-gemini
82
+ ```
83
+
84
+ If quota errors occur, repeat with `--resume results/real-filings-gemini/predictions.json` and a different output directory after the quota resets. Review `predictions.json` explanations manually; the scorer checks numbers and reference IDs, not whether prose is fully supported by the filing.
85
+
86
+ A [manual review of the three Gemini explanations](reviews/real-filings-v1-gemini-review.md) records the filing evidence, independent calculations, and scope of the 3/3 pilot result. The automatic report still flags all explanations for expert review because it does not read this note.
87
+
88
+ Transient HTTP 500/503/504 responses are retried twice with short exponential waits. HTTP 429 quota errors are saved for a later `--resume` run; the result report shows the HTTP status separately from model quality.
89
+
90
+ For a prospective customer's first call, demo, model connection, tailored dataset and acceptance steps, see the [Turkish customer pilot guide](docs/customer-pilot-guide-tr.md).
91
+
92
+ ## Run without API keys
93
+
94
+ ```bash
95
+ python -m unittest discover -s tests -v
96
+ python -m finance_benchmark run --provider baseline
97
+ python -m finance_benchmark evaluate examples/sample_predictions.json --output results/sample
98
+ ```
99
+
100
+ The baseline copies gold arithmetic and citations as a **harness control**; its 100% result is not an AI performance claim. The sample yields errors and missing predictions by design. Accuracy is computed over evaluated responses; coverage shows how many requested cases received a usable response. Reports are written to `results/report.json`, `results/report.md`, and `results/predictions.json` (or the chosen output directory).
101
+
102
+ GitHub Actions runs these checks on every push and attaches an `evaluation-reports` artifact with both control and deliberately flawed sample outputs.
103
+
104
+ ## Evaluate your own predictions
105
+
106
+ Make a JSON list of objects with `case_id`, `value`, `source_refs`, `explanation`, and `abstained`; see `examples/sample_predictions.json`. Run:
107
+
108
+ ```bash
109
+ python -m finance_benchmark evaluate path/to/predictions.json --output results/my-model
110
+ ```
111
+
112
+ Source references must exactly match the fact IDs, e.g. `atlas:revenue_2025`. Wrong or duplicate IDs fail the source check. Missing predictions count as failures. For the full set, inspect `finance_benchmark.core.cases()`.
113
+
114
+ ## Try an OpenAI-compatible chat completions API
115
+
116
+ Set credentials locally; never commit keys. The model must support `response_format: {"type":"json_object"}`. Start with three calls to limit cost:
117
+
118
+ ```bash
119
+ export AI_API_KEY='your-key'
120
+ export AI_API_BASE_URL='https://api.openai.com/v1'
121
+ python -m finance_benchmark run --provider api --model YOUR_MODEL_ID --limit 3 --output results/api-trial
122
+ ```
123
+
124
+ Omit `AI_API_BASE_URL` to use the shown default. The CLI sends one request per case. API/parsing errors are counted as abstentions and printed to stderr; the report preserves all returned predictions. **Only run with a trusted endpoint** and do not put confidential customer data in this dataset.
125
+
126
+ ### Gemini free-tier trial
127
+
128
+ Store your Google AI Studio key as a GitHub Codespaces secret named `GEMINI_API_KEY` for this repository. Create a new Codespace (or restart an existing one to load a newly added secret), then run:
129
+
130
+ ```bash
131
+ python -m finance_benchmark run --provider gemini --limit 3 --output results/gemini-trial
132
+ cat results/gemini-trial/report.md
133
+ ```
134
+
135
+ The Gemini provider defaults to `gemini-2.5-flash` and Google's OpenAI-compatible Chat Completions endpoint. You can override the model with `--model`. The key is read from the environment and is never written to the report. `--limit 3` reports scores over three cases. Free-tier availability and quotas depend on your Google AI Studio project. Do not commit `results/` or the key.
136
+
137
+ If you see HTTP 429, inspect the rate limits for your project in Google AI Studio. A slower trial can help with per-minute limits:
138
+
139
+ ```bash
140
+ python -m finance_benchmark run --provider gemini --limit 10 --delay-seconds 20 --output results/gemini-slow
141
+ ```
142
+
143
+ If a daily quota is exhausted, wait for the quota reset. API failures remain in `predictions.json` but are shown separately from model accuracy. To re-score a previous run created with the older version of this project **without sending new API requests**, use:
144
+
145
+ ```bash
146
+ python -m finance_benchmark evaluate results/gemini-10/predictions.json --limit 10 --output results/gemini-10-rescored
147
+ ```
148
+
149
+ After the quota allows more requests, keep the six successful answers and retry only the four API errors:
150
+
151
+ ```bash
152
+ python -m finance_benchmark run --provider gemini --limit 10 --resume results/gemini-10/predictions.json --delay-seconds 20 --output results/gemini-10-complete
153
+ ```
154
+
155
+ `--resume` accepts previous predictions from the same first N cases, validates their IDs, and reuses genuine model responses (including genuine abstentions). It retries missing cases and both old and new API errors. The delay applies between actual API requests only.
156
+
157
+ ## Expert quality rubric (next pilot)
158
+
159
+ | Dimension | Automated here | Expert review |
160
+ | --- | --- | --- |
161
+ | Formula and rounding | Numeric value vs. reference answer | Whether the chosen financial metric fits the question |
162
+ | Evidence | Exact source-field IDs | Whether cited evidence supports the prose |
163
+ | Abstention | Unnecessary abstentions flagged | Whether a genuinely ambiguous question should be declined |
164
+ | Explanation | Marked for review | Unsupported claims, overconfidence, helpfulness |
165
+
166
+ The next dataset should use licensed public filings with exact page/table references, two independent expert annotations for ambiguous examples, a written adjudication log, and error rates by category. Keep it separate from the synthetic control so results are never confused.
167
+
168
+ ## Docker
169
+
170
+ ```bash
171
+ docker build -t finance-ai-quality-benchmark .
172
+ docker run --rm finance-ai-quality-benchmark
173
+ ```
174
+
175
+ The default container runs the arithmetic control and prints the Markdown summary. For persisted results, run the Python command locally or mount a results directory.
176
+
177
+ ## Scope and limitations
178
+
179
+ This is an evaluation harness, not a finance model. The reference data is invented; numeric accuracy on 30 templated questions does not predict performance on real filings. The scorer does not evaluate hallucinations in explanations, assess legal compliance, or judge whether a company is financially healthy. Human judgment and a separate public-data pilot are required before making those claims.
180
+
181
+ ## Contributing
182
+
183
+ New test cases (especially hard ones from public filings), providers, and documentation improvements are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
184
+
185
+ License: MIT.
@@ -0,0 +1,205 @@
1
+ Metadata-Version: 2.4
2
+ Name: finance-ai-quality-benchmark
3
+ Version: 0.1.0
4
+ Summary: Reproducible benchmark for evaluating AI answers to financial-statement questions: numeric accuracy and exact source traceability.
5
+ Author: pars1905
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/pars1905/finance-ai-quality-benchmark
8
+ Project-URL: Issues, https://github.com/pars1905/finance-ai-quality-benchmark/issues
9
+ Keywords: llm,evaluation,benchmark,finance,financial-statements,ai-evaluation
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Financial and Insurance Industry
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Topic :: Office/Business :: Financial
16
+ Requires-Python: >=3.10
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Dynamic: license-file
20
+
21
+ # Finance AI Quality Benchmark
22
+
23
+ [![CI](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml/badge.svg)](https://github.com/pars1905/finance-ai-quality-benchmark/actions/workflows/ci.yml)
24
+ [![PyPI](https://img.shields.io/pypi/v/finance-ai-quality-benchmark.svg)](https://pypi.org/project/finance-ai-quality-benchmark/)
25
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
26
+
27
+ An open-source, reproducible benchmark for evaluating AI answers to financial-statement questions. It checks two things separately: whether the number is correct, and whether the answer cites the exact source fields it used.
28
+
29
+ **Why it exists:** Most LLM benchmarks focus on general knowledge or code. Few open tools check whether a model's financial calculations (margins, growth, ratios) are numerically correct and traceable to the evidence. Models often sound confident while getting these numbers wrong. This project makes that measurable and repeatable.
30
+
31
+ **Status:** Working pilot with a synthetic control and three curated excerpts from public annual reports. Not a validated full-document finance benchmark. No confidential employer or client data. Contributions are welcome; see [CONTRIBUTING.md](CONTRIBUTING.md).
32
+
33
+ ## Install
34
+
35
+ Python 3.10+ is required. There are no third-party dependencies.
36
+
37
+ ```bash
38
+ pip install finance-ai-quality-benchmark
39
+ finance-benchmark run --provider baseline
40
+ ```
41
+
42
+ `finance-benchmark` is equivalent to `python -m finance_benchmark`; every command below works with either form. To develop locally, clone the repository and run `pip install -e .`.
43
+
44
+ ## What it measures
45
+
46
+ - 30 questions: six fictional companies × five financial calculations (gross margin, revenue growth, operating margin, current ratio, debt-to-equity).
47
+ - Separately scores numeric answers (absolute tolerance 0.01) and exact source-field references; strict pass requires both. Percentage questions accept a numeric value or a numeric string ending in `%`; ratios reject `%`. API errors are reported as coverage failures, not incorrect model answers.
48
+ - Produces per-case failure codes and JSON/Markdown reports. Every nonempty explanation is flagged for expert review; the script **does not claim to verify the truth of prose**.
49
+ - Includes deliberately flawed sample answers to demonstrate failure detection.
50
+
51
+ All values in `finance_benchmark/data/statements.json` are fictional and in consistent arbitrary units. The benchmark tests arithmetic and traceability, not accounting interpretation, financial advice or investment performance.
52
+
53
+ ## Interactive public-equity valuation demo
54
+
55
+ [Open the public valuation interface](https://finance-ai-quality-demo-osman.affableeucalyptus1.chatgpt.site). The visitor starts with a fictional ready-to-use example. For a real company, choose **My company's data** and load a single [financial summary JSON template](web/sample-input.json), or open the advanced manual fields. Only the source choice, company and market price, and country condition are visible initially. Missing growth, discount and peer-multiple assumptions in an uploaded file use clearly labeled illustrative defaults that should be reviewed before interpreting results. The browser reads the file locally and does not upload it. The interface shows **five per-share methods** across bearish, base and bullish assumptions:
56
+
57
+ 1. FCFF DCF: five years of firm free cash flow and a terminal value, discounted at WACC; subtract net debt.
58
+ 2. FCFE DCF: five years of equity free cash flow and a terminal value, discounted at cost of equity.
59
+ 3. Comparable P/E applied to normalized net income.
60
+ 4. Comparable EV/EBITDA applied to EBITDA, then subtract net debt.
61
+ 5. Comparable P/B applied to book equity.
62
+
63
+ A country-conditions control offers illustrative **ordinary conditions, conflict, ceasefire and peace agreement** shifts to growth, discount rates and comparable multiples; every effect is visible and editable. These presets are hypothetical, not observations or forecasts about a real country. Bear/base/bull adjustments are separate. The page displays a median for navigation only; correlated models are not independent confirmations. Methods with nonpositive earnings, EBITDA, book equity, or invalid DCF discount spreads show unavailable rather than a fabricated value.
64
+
65
+ [Browser source](web/index.html) · [Calculation module](web/valuation.mjs) · [Model tests](web/tests/valuation.test.mjs). To run locally:
66
+
67
+ ```bash
68
+ python -m http.server 8000 --directory web
69
+ node --test web/tests/valuation.test.mjs
70
+ ```
71
+
72
+ Open http://localhost:8000. The sample company is fictional. The page does **not** fetch market data, validate uploaded filings, call an AI model, store form entries, or provide a verified price target. All inputs must come from consistently dated, denominated and reviewed company filings and peer data. The Python benchmark below remains the separate AI-answer evaluation product.
73
+
74
+ ## Three runnable customer conversation demos
75
+
76
+ The [Turkish demo walkthrough](docs/three-customer-demos-tr.md) covers three fictional client scenarios: management reporting (correct answer), credit analysis (wrong number), and research review (wrong source reference). Sample responses are hand-authored to demonstrate the scorer; they are **not actual model outputs or customer engagements**.
77
+
78
+ ```bash
79
+ python -m finance_benchmark evaluate examples/demo-fpna-predictions.json --dataset demo-fpna-v1 --output results/demo-fpna
80
+ python -m finance_benchmark evaluate examples/demo-credit-predictions.json --dataset demo-credit-v1 --output results/demo-credit
81
+ python -m finance_benchmark evaluate examples/demo-research-predictions.json --dataset demo-research-v1 --output results/demo-research
82
+ ```
83
+
84
+ Each demo has one case. The expected strict pass rates are 100%, 0%, and 0% respectively. The second case demonstrates a numeric failure with correct references; the third demonstrates a source failure despite a correct number. To test a live model on any of them, use the existing `run --provider gemini --dataset ...` command with a key set in your environment.
85
+
86
+ ## Three public-filing examples
87
+
88
+ `finance_benchmark/data/real_filings_v1.json` contains one independently checkable arithmetic question per company. Values are manually transcribed from fixed SEC annual filings; each case stores its accession number, filing URL, table location, reporting units, source IDs, and reference answer.
89
+
90
+ | Company | Annual report | Question | Reference answer |
91
+ | --- | --- | --- | ---: |
92
+ | [Microsoft](https://www.sec.gov/Archives/edgar/data/789019/000095017025100235/msft-20250630.htm) | FY2025 10-K | Revenue growth, FY2024 to FY2025 | 14.93% |
93
+ | [Apple](https://www.sec.gov/Archives/edgar/data/320193/000032019325000079/aapl-20250927.htm) | FY2025 10-K | Services share of total FY2025 net sales | 26.23% |
94
+ | [Turkcell](https://www.sec.gov/Archives/edgar/data/1071321/000110465926044740/tkc-20251231x20f.htm) | FY2025 20-F | Revenue growth using the FY2024 comparable amount from the **same FY2025 report** | 10.69% |
95
+
96
+ Turkcell applies IAS 29 inflation accounting; comparing the FY2025 figure with the previously published FY2024 report's unadjusted amount would be invalid. Both figures here come from the FY2025 filing and use TRY thousands. These are three curated **filing excerpts**, so the model is tested on cited financial reasoning, not retrieval from complete reports. The reference control copies answers and should not be presented as a model result.
97
+
98
+ To run the three-case Gemini pilot after setting the Codespaces secret `GEMINI_API_KEY`:
99
+
100
+ ```bash
101
+ python -m finance_benchmark run --provider gemini --dataset real-filings-v1 --delay-seconds 20 --output results/real-filings-gemini
102
+ ```
103
+
104
+ If quota errors occur, repeat with `--resume results/real-filings-gemini/predictions.json` and a different output directory after the quota resets. Review `predictions.json` explanations manually; the scorer checks numbers and reference IDs, not whether prose is fully supported by the filing.
105
+
106
+ A [manual review of the three Gemini explanations](reviews/real-filings-v1-gemini-review.md) records the filing evidence, independent calculations, and scope of the 3/3 pilot result. The automatic report still flags all explanations for expert review because it does not read this note.
107
+
108
+ Transient HTTP 500/503/504 responses are retried twice with short exponential waits. HTTP 429 quota errors are saved for a later `--resume` run; the result report shows the HTTP status separately from model quality.
109
+
110
+ For a prospective customer's first call, demo, model connection, tailored dataset and acceptance steps, see the [Turkish customer pilot guide](docs/customer-pilot-guide-tr.md).
111
+
112
+ ## Run without API keys
113
+
114
+ ```bash
115
+ python -m unittest discover -s tests -v
116
+ python -m finance_benchmark run --provider baseline
117
+ python -m finance_benchmark evaluate examples/sample_predictions.json --output results/sample
118
+ ```
119
+
120
+ The baseline copies gold arithmetic and citations as a **harness control**; its 100% result is not an AI performance claim. The sample yields errors and missing predictions by design. Accuracy is computed over evaluated responses; coverage shows how many requested cases received a usable response. Reports are written to `results/report.json`, `results/report.md`, and `results/predictions.json` (or the chosen output directory).
121
+
122
+ GitHub Actions runs these checks on every push and attaches an `evaluation-reports` artifact with both control and deliberately flawed sample outputs.
123
+
124
+ ## Evaluate your own predictions
125
+
126
+ Make a JSON list of objects with `case_id`, `value`, `source_refs`, `explanation`, and `abstained`; see `examples/sample_predictions.json`. Run:
127
+
128
+ ```bash
129
+ python -m finance_benchmark evaluate path/to/predictions.json --output results/my-model
130
+ ```
131
+
132
+ Source references must exactly match the fact IDs, e.g. `atlas:revenue_2025`. Wrong or duplicate IDs fail the source check. Missing predictions count as failures. For the full set, inspect `finance_benchmark.core.cases()`.
133
+
134
+ ## Try an OpenAI-compatible chat completions API
135
+
136
+ Set credentials locally; never commit keys. The model must support `response_format: {"type":"json_object"}`. Start with three calls to limit cost:
137
+
138
+ ```bash
139
+ export AI_API_KEY='your-key'
140
+ export AI_API_BASE_URL='https://api.openai.com/v1'
141
+ python -m finance_benchmark run --provider api --model YOUR_MODEL_ID --limit 3 --output results/api-trial
142
+ ```
143
+
144
+ Omit `AI_API_BASE_URL` to use the shown default. The CLI sends one request per case. API/parsing errors are counted as abstentions and printed to stderr; the report preserves all returned predictions. **Only run with a trusted endpoint** and do not put confidential customer data in this dataset.
145
+
146
+ ### Gemini free-tier trial
147
+
148
+ Store your Google AI Studio key as a GitHub Codespaces secret named `GEMINI_API_KEY` for this repository. Create a new Codespace (or restart an existing one to load a newly added secret), then run:
149
+
150
+ ```bash
151
+ python -m finance_benchmark run --provider gemini --limit 3 --output results/gemini-trial
152
+ cat results/gemini-trial/report.md
153
+ ```
154
+
155
+ The Gemini provider defaults to `gemini-2.5-flash` and Google's OpenAI-compatible Chat Completions endpoint. You can override the model with `--model`. The key is read from the environment and is never written to the report. `--limit 3` reports scores over three cases. Free-tier availability and quotas depend on your Google AI Studio project. Do not commit `results/` or the key.
156
+
157
+ If you see HTTP 429, inspect the rate limits for your project in Google AI Studio. A slower trial can help with per-minute limits:
158
+
159
+ ```bash
160
+ python -m finance_benchmark run --provider gemini --limit 10 --delay-seconds 20 --output results/gemini-slow
161
+ ```
162
+
163
+ If a daily quota is exhausted, wait for the quota reset. API failures remain in `predictions.json` but are shown separately from model accuracy. To re-score a previous run created with the older version of this project **without sending new API requests**, use:
164
+
165
+ ```bash
166
+ python -m finance_benchmark evaluate results/gemini-10/predictions.json --limit 10 --output results/gemini-10-rescored
167
+ ```
168
+
169
+ After the quota allows more requests, keep the six successful answers and retry only the four API errors:
170
+
171
+ ```bash
172
+ python -m finance_benchmark run --provider gemini --limit 10 --resume results/gemini-10/predictions.json --delay-seconds 20 --output results/gemini-10-complete
173
+ ```
174
+
175
+ `--resume` accepts previous predictions from the same first N cases, validates their IDs, and reuses genuine model responses (including genuine abstentions). It retries missing cases and both old and new API errors. The delay applies between actual API requests only.
176
+
177
+ ## Expert quality rubric (next pilot)
178
+
179
+ | Dimension | Automated here | Expert review |
180
+ | --- | --- | --- |
181
+ | Formula and rounding | Numeric value vs. reference answer | Whether the chosen financial metric fits the question |
182
+ | Evidence | Exact source-field IDs | Whether cited evidence supports the prose |
183
+ | Abstention | Unnecessary abstentions flagged | Whether a genuinely ambiguous question should be declined |
184
+ | Explanation | Marked for review | Unsupported claims, overconfidence, helpfulness |
185
+
186
+ The next dataset should use licensed public filings with exact page/table references, two independent expert annotations for ambiguous examples, a written adjudication log, and error rates by category. Keep it separate from the synthetic control so results are never confused.
187
+
188
+ ## Docker
189
+
190
+ ```bash
191
+ docker build -t finance-ai-quality-benchmark .
192
+ docker run --rm finance-ai-quality-benchmark
193
+ ```
194
+
195
+ The default container runs the arithmetic control and prints the Markdown summary. For persisted results, run the Python command locally or mount a results directory.
196
+
197
+ ## Scope and limitations
198
+
199
+ This is an evaluation harness, not a finance model. The reference data is invented; numeric accuracy on 30 templated questions does not predict performance on real filings. The scorer does not evaluate hallucinations in explanations, assess legal compliance, or judge whether a company is financially healthy. Human judgment and a separate public-data pilot are required before making those claims.
200
+
201
+ ## Contributing
202
+
203
+ New test cases (especially hard ones from public filings), providers, and documentation improvements are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
204
+
205
+ License: MIT.
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ finance_ai_quality_benchmark.egg-info/PKG-INFO
5
+ finance_ai_quality_benchmark.egg-info/SOURCES.txt
6
+ finance_ai_quality_benchmark.egg-info/dependency_links.txt
7
+ finance_ai_quality_benchmark.egg-info/entry_points.txt
8
+ finance_ai_quality_benchmark.egg-info/top_level.txt
9
+ finance_benchmark/__init__.py
10
+ finance_benchmark/__main__.py
11
+ finance_benchmark/core.py
12
+ finance_benchmark/data/customer_demos_v1.json
13
+ finance_benchmark/data/real_filings_v1.json
14
+ finance_benchmark/data/statements.json
15
+ tests/test_core.py