Skip to content
Projets

kbhujbal/AlphaAnalyst-open-source-autonomous-equity-research-agent

Voir sur GitHub

À propos

Enter a US stock ticker, get an analyst grade memo with DCF valuation, peer comparables, news sentiment, and earnings call tone analysis. Multi agent LLM pipeline (Claude + GPT-4o devil's advocate) with strict citation validation. FastAPI + Next.js + pgvector RAG. No hallucinated numbers

Développement web et applicatif

Comment ces chiffres sont mesurés

Progression mesurée des étoiles

in 24h
0
in 7 days
0
in 15 days
+3
in 1 month
Historique en cours

Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.

README.md

Original

AlphaAnalyst

AlphaAnalyst is an experimental US equity research assistant. It collects filings, market data, news, and earnings transcripts and drafts a research memo with source references and experimental valuation outputs. Analyst review is required.

Claim-level checks establish exact-source matching and consistency with retained financial observations. They do not certify source correctness, qualitative entailment, investment outperformance, or production readiness. The current DCF uses simplified inputs; Excel exports are snapshots with a few total formulas, not recalculating models. A different model providing skeptical review does not guarantee independent research.

Reproducible setup

Use Python 3.13 (see .python-version), uv 0.12.21, and Node.js 22 (see frontend/.nvmrc; Node 24 is also supported). Docker is needed for live analysis and database integration tests. Dependency installation initially requires network access. Commit both backend/uv.lock and frontend/package-lock.json when updating dependencies. Run commands from the repository root unless a cd is shown.

Offline interface demonstration

No provider accounts, backend, database, or Redis are needed:

cd frontend
npm ci
npm run dev

Open http://localhost:3000/demo. The homepage links to this fictional, fixed fixture. It demonstrates report layout, source references, coverage warnings, and unavailable exports. It does not demonstrate live research quality. After the initial install, frontend builds and this demo do not fetch fonts or company data.

Backend and live analysis

cd backend
uv sync --frozen
cp .env.example .env

Edit backend/.env before submitting live analyses. The default model configuration requires ANTHROPIC_API_KEY and OPENAI_API_KEY. Also configure FMP_API_KEY, SEC_API_KEY, VOYAGE_API_KEY, and EDGAR_USER_AGENT with a real contact email. Missing essential configuration returns HTTP 503 before creating a job.

Configure Polygon, Finnhub, MarketAux, and FRED keys for the corresponding coverage. Provider account plans must permit the endpoints used. Missing optional coverage, provider failures, low-confidence cross-checks, and unavailable sections produce partial reports with warnings. Requests incur provider charges. Model availability and provider entitlements need a live smoke test with your accounts.

Start PostgreSQL and Redis, apply migrations, then start the backend:

# From backend/
docker compose -f ../docker-compose.yml up -d --wait
uv run --frozen alembic upgrade head
uv run --frozen uvicorn src.api.main:app --reload --port 8000

In another terminal:

cd frontend
cp .env.local.example .env.local
npm ci
npm run dev

Open http://localhost:3000. API documentation is at http://localhost:8000/docs. Compose credentials and exposed service ports are for local development.

Report states

State Meaning
queued / running Processing has not finished. Progress indicates pipeline stages, not evidence quality or remaining time.
complete No known processing or coverage gaps were detected by the current checks. This is not independent factual verification.
partial A readable, cited memo exists, but warnings identify missing coverage, agent errors, insufficient sections, validation downgrades, or export failures.
failed Essential inputs were absent, no usable cited memo was produced, synthesis failed, the budget cap was exceeded, or execution failed. No memo is published.

Both complete and partial memos can be read and downloaded where exports exist. The API exposes warnings on job and memo responses. Unavailable export URLs are null; downloads require a finished job, an availability flag, and an existing file. The frontend stops polling all terminal states. Legacy error jobs remain readable as failures during the 24-hour cache transition.

Current full-report checks require a 10-K and a fundamentals snapshot with revenue. They also check for unavailable 10-Qs, prices, news, macro data, transcripts, estimates, peers, agent findings, valuations, and memo sections. Zero recent 8-Ks is a valid result. Some capabilities, including short-interest analysis, remain unimplemented, so live reports will commonly be partial. Warnings are conservative; there is not yet a configurable coverage policy for different research workflows.

Citation objects now carry their explicit tag when emitted by the synthesizer. The interface does not guess missing tag mappings. Actual filing-page extraction remains future work. The claim-verification stage below adds retained source passages and conservative claim-level publication checks.

Validation without provider credentials

cd backend
uv sync --frozen
uv run --frozen pytest -m 'not integration' -q

From the repository root, regenerate API types without starting services:

uv run --frozen --project backend python scripts/export_openapi.py
cd frontend
npm ci
npm run codegen
npm run test
npm run typecheck
npm run lint
npm run build

OpenAPI JSON and generated TypeScript are committed. Export and regenerate both when the backend contract changes. CI rejects stale generated contracts and runs the tests, type checking, linting, and production build. Tests and schema export use LiteLLM's bundled pricing map rather than fetching pricing metadata at import time. Costs remain estimates; provider billing is authoritative.

Database integration checks

These tests create/drop tables. Use a dedicated, disposable test database. They skip unless TEST_DATABASE_URL is explicitly set; never point it at your working research database.

# From repository root, with Docker running:
docker compose up -d --wait
docker compose exec -T postgres createdb -U analyst analyst_test
cd backend
TEST_DATABASE_URL=postgresql+asyncpg://analyst:analyst@localhost:5432/analyst_test uv run --frozen pytest -m integration -q

The database CI job checks migrations and PostgreSQL/pgvector integration against an isolated database. Unit and fixture tests do not validate provider availability or the financial accuracy of a live memo. The existing evaluation scripts check limited revenue matching and citation structure; they are not institutional-quality financial validation.

Architecture and remaining work

  • backend/src/clients and fetchers: provider access, caching, persistence.
  • backend/src/agents: specialist findings and memo synthesis through LiteLLM.
  • backend/src/modeler: deterministic, experimental valuation calculations.
  • backend/src/orchestrator: pipeline, report outcomes, PDF/Excel snapshots.
  • backend/src/api: FastAPI contracts and job/report endpoints.
  • frontend: Next.js, TanStack Query, Zod, and source-reference views.

Reports currently expire from Redis after 24 hours and exports use local temporary storage. Jobs use in-process background tasks. Authentication, durable workers, tenant isolation, canonical point-in-time financial data, corrected valuation, recalculating Excel models, and independent semantic/source-quality review remain pending. Charts that need structured series explicitly show unavailable states; this stage does not add chart data to the API. The financial-observation foundation is described below. A defensible valuation model and an analyst pilot remain subsequent milestones.

The report-status and nullable-export contract changes require consumers to update from the previous development checkout. Deploy the backend and frontend together; regenerate external clients from the committed OpenAPI schema.

Financial observation foundation

Run uv run --frozen alembic upgrade head from backend/ before using this update. Migration 0003_financial_observations adds an immutable observation store. Existing facts rows are preserved but are not used for financial cross-checking: their missing reporting context cannot safely be reconstructed. Run a new analysis to populate canonical observations. Versioned cache keys bypass the old snapshots.

Each accepted observation stores its metric, original provider tag, finite Decimal value, canonical unit, declared currency, start/end dates, instant/duration type, period basis, dimensions, source record locator, filing accession/date, retrieval time, and a canonical JSON payload hash. Parsed source records are retained in the database. Numeric decimal JSON values are decoded without a binary-float conversion. Repeated identical observations deduplicate; changed payloads and different filings retain separate identities. Hashes identify parsed provider records, not original HTTP bytes or whole filing documents. Missing dates and currencies remain null.

The SEC parser preserves annual, quarterly, YTD, instant, and segment contexts. Unit aliases normalize to forms such as USD, EUR/share, shares, and ratio. decimals records rounding precision; it does not multiply amounts. This follows sec-api's documented unscaled response and period/segment format.

FMP statement ingestion requests six annual records and keeps each accepted record with its own provenance. When consecutive fiscal year ends establish a full annual interval, the next start is derived from the preceding end plus one day. That normalization is labeled and records the prior row's locator and hash. It handles non-calendar and 52/53-week years; it does not invent January starts or missing currencies. EPS uses a diluted EPS field and currency-per-share units, without a fallback to basic EPS. Missing or incompatible balance-sheet/cash-flow contexts are withheld from the assembled snapshot. TTM ratios and undated market values do not inherit annual financial-statement dates.

The pipeline extracts both the fetched 10-K and 10-Q before refreshing fundamentals. Revenue/EPS cross-checks require complete matching intervals, currency, unit, consolidated dimensions, and a compatible filing version. Conflicting candidates are not arbitrarily selected. confidence describes the revenue/EPS cross-check; it does not certify every observation. Per-field source references remain attached when SEC values replace vendor values. Latest-filing pointers now revalidate on a five-minute cache interval; old-report amendments do not outrank newer report years.

MemoResponse.financial_facts exposes the selected observations and provenance, without raw provider payloads. The Financials tab shows these records. Reports retain warnings about missing context. Monetary observations without known currency are withheld from the synthesis fact bundle. Comparables require verified market-cap date/currency and exclude peers in other currencies; there is no automatic FX conversion. The traced DCF described below requires date-matched debt, cash and share observations plus explicit scenario assumptions.

Still pending: applying/testing migrations on a live PostgreSQL instance; provider account smoke tests; a larger independently reviewed company corpus; full XBRL context/taxonomy coverage; a security master; full historical memo APIs; raw HTTP archives; broader accounting/restatement reconciliation workflows; verified quote metadata; and a financially reviewed valuation methodology. The existing price, macro, and estimates pipelines have not been converted into this financial-statement model. The stored filing dates and timezone-aware acceptance timestamps do not by themselves make the application a point-in-time backtesting system. Naive provider acceptance timestamps remain in source payloads and are not assigned a timezone.

Claim-level evidence and publication checks

Apply migration 0004_evidence_documents with uv run --frozen alembic upgrade head from backend/ before running this version. Run a fresh analysis to re-index source material. Existing retrieval chunks without archive/version/offset metadata are excluded from verifiable retrieval; old reports remain visibly unverified.

The indexer now retains immutable versions of captured normalized filing text and transcripts. Retrieval chunks reference document hashes and real Unicode character offsets, never invented PDF page numbers. Filing searches are restricted to the requested accession numbers. News evidence captures provider headline/snippet excerpts and explicitly identifies them as excerpts, not full articles. Changed source text keeps a separate document identity. Identical captures retain their original retrieval timestamp. These are captured normalized text versions, not raw HTML/PDF byte archives; table layout preservation remains separate work.

Agents must supply a real chunk identifier and an exact contiguous quote. Unknown references, altered/noncontiguous quotes, and out-of-range evidence are rejected. Transcript guidance quotes are checked against cited paragraphs; missing paragraph references no longer receive a fabricated fallback citation. Skeptical review retains all original evidence instead of replacing it with generated analysis.

The synthesizer now produces structured atomic claims instead of free-form memo sections. A deterministic publication gate supports these claim kinds:

Kind Publication rule Meaning of the displayed result
quote Every cited tag must contain the exact quote in an independently reloaded source snapshot. The retained source said this; its real-world truth is not independently certified.
financial Copy a specific observation assertion. The value, metric, unit, currency, dates, period kind/basis, source payload hash, and source binding must match. The server renders a statement from the checked observation; arbitrary numerical prose is not accepted.
interpretation Evidence references must resolve; numerical/date prose is rejected. Labeled as requiring analyst review; semantic entailment is not automatically certified.

Financial source records are reloaded independently from the observation store. Derived annual start dates require the actual preceding fiscal boundary record and its matching hash. Original provider JSON fields are retained as source passages. Financial statements are rendered by Python; the LLM cannot turn an asset value into revenue by changing prose, add an unrelated citation, infer a currency, or substitute a different fiscal year. Rounded numerical prose and FX conversions remain unsupported. Registered source-linked recipes for growth, margins and valuation are described below; arbitrary LLM arithmetic is never accepted through a text-number match.

Legacy free-text LLM responses cannot bypass this gate. Rejected claims are withheld from section prose and recorded in Memo.claim_audit. Interpretations and rejected claims generate partial-report warnings. A separate report-integrity gate verifies that all published prose was rendered from accepted claims and explicit citation identifiers. Citation auditing now checks identities and coverage rather than comparing citation counts alone. If no usable cited research survives, no memo is published.

The interface exposes the claim audit, individual numerical checks, and a citation inspection dialog with exact passages, version hashes, offsets, and retrieval times. GET /api/v1/memos/{job_id}/evidence/{document_id} returns a retained source snapshot only when it is cited by that completed/partial claim-v1 report. The captured JSON link is included on returned passages. Offsets use Unicode code points, not bytes or JavaScript UTF-16 indices. PDFs include the source identifiers and claim audit.

The calculation stage below extends the numerical gate to registered growth, margin, DCF and comparable recipes. Macro snapshots, price returns, insider aggregations, sentiment statistics and FX conversions still lack registered traces and remain outside the verified memo evidence bundle. Excel files remain snapshots; new traced DCF exports also include exact-value trace and source sheets.

Still pending: live PostgreSQL/migration and provider-account validation, a larger independently labeled claim-support corpus, semantic entailment/contradiction review, full article retrieval, HTML/PDF table/page locators, additional derived calculations, and production access controls/retention policies. Deterministic quote and numerical checks do not replace a research analyst's judgment or prove investment merit.

Source-linked calculation recipes

Apply migration 0005_calculation_records from backend/ before running this version (uv run --frozen alembic upgrade head). No existing reports or untraced valuation values are upgraded to verified calculations. A fresh analysis uses archived financial observations, including historical periods, and stores verified calculation records immutably in PostgreSQL, independently of the 24-hour job cache. The fundamentals cache namespace is bumped so the new balance-sheet fields are fetched. Normalization now retains reported total debt, cash and cash equivalents, and point-in-time common shares outstanding; weighted-average EPS shares are not substituted.

Each Memo.calculations record includes a versioned recipe, input observation IDs, explicit assumptions, named formula steps, exact Decimal values, units, output node references, source metadata and retained source passages. A content hash identifies the full recipe and results. Replaying a recipe rebuilds the entire trace under 28-digit Decimal precision with half-even rounding, independent of the process-wide Decimal context. Changed steps, outputs, source bindings or assumptions fail verification. Changed legitimate inputs or scenarios produce a new identity. Before publication, observations and original payloads are independently reloaded, source records/passages are checked, and the registered recipe is rerun. Arbitrary formula text and LLM-supplied arithmetic are not executed.

Initial coverage is deliberately explicit:

Recipe Formula and conditions
growth-v1 Annual revenue / preceding annual revenue minus one. Requires positive values, consecutive complete annual intervals, comparable duration lengths, the same currency and no segment dimensions. This is annual growth, not a multi-year CAGR.
net-margin-v1 Net income / revenue, with a positive revenue denominator and matching fiscal interval, currency and filing version. Negative income produces a negative margin.
ocf-margin-v1 Operating cash flow / revenue under the same matching rules. It is labeled operating cash flow margin, never free cash flow margin.
dcf-fcff-v1 Projects revenue using the checked annual growth rate, multiplies by an explicitly assumed unlevered FCFF margin, discounts at the explicit WACC, and applies Gordon growth. Equity equals enterprise value minus reported debt plus reported cash, divided by reported fiscal-end shares. Every projection, discount factor, equity-bridge value and valid sensitivity cell is traced.
comps-v1 Per-peer P/S and eligible positive-income P/E, medians, and target implied market capitalization. Requires common market-cap dates, currency and exact annual fiscal intervals. Financial filing availability must be known and no later than the capitalization date; statements older than 550 days are excluded. Negative/missing income excludes P/E without suppressing valid P/S.

Ratios are stored as fractions: 0.10 means 10%, rather than ten percent being silently converted to a different scale. Source revisions are not averaged; ambiguous historical versions require explicit selection. Automatic peer fetches are limited to five and excluded peers receive reasons. Comparables select one common capitalization date: the largest eligible peer cohort, then the most recent date for that cohort. Different dates are never blended into one median. Market cap / operating cash flow is no longer described as EV/EBITDA, and no EV/EBITDA estimate is generated.

The DCF no longer derives shares from market cap divided by an unrelated price, uses liabilities as debt, invents missing cash, assumes a fallback historical margin, or adjusts valuation assumptions from generated news sentiment. It requires an explicit scenario. Enter one in the optional DCF scenario form, or submit:

{
  "ticker": "AAPL",
  "dcf_scenario": {
    "name": "Illustrative scenario",
    "rationale": "Illustrative assumptions supplied by the analyst; not a recommendation.",
    "wacc": "0.10",
    "terminal_growth": "0.025",
    "fcff_margin": "0.12",
    "projection_years": 5
  }
}

These example assumptions are not estimated or recommended by the application. FCFF margin is a forecast assumption, not a reported observation or a substitute for an operating cash flow margin. Terminal growth must be below WACC. Missing scenario/source inputs withhold the DCF with an actionable warning. Scenario, methodology and equity-bridge limitations remain visible in partial-report warnings. The model uses fiscal-end debt, cash and shares and is not a current-market or point-in-time backtesting valuation. Preferred equity, minority interests, lease policy, excess cash and other equity-bridge adjustments still require review.

A structured calculation claim must copy one exact output assertion (trace ID, output name, value, unit and currency) and reference its own calculation. The server renders its text; rounding or relabeling cannot turn a calculated scenario into an unqualified fact. The report-integrity gate replays calculations again and checks that numerical claim text, checks and references agree. The interface displays the trace, assumptions and source passages; source JSON is scoped to records included in that report. PDFs include calculation steps and source identities. Traced DCF Excel snapshots include exact Decimal strings and source IDs alongside the existing numeric presentation sheets; editing the workbook does not recalculate the model.

Download trace JSON from the report and replay it without provider credentials:

backend/.venv/bin/python scripts/replay_calculation.py downloaded-trace.json
backend/.venv/bin/python scripts/replay_calculation.py downloaded-trace.json --documents captured-sources/

The first command checks arithmetic against the included observation metadata. With full captured-source JSON files, the second also checks exact passages and original payload hashes/values. Neither proves source truth, accounting judgment, or investment merit. Job-scoped report URLs still expire with the job cache; durable records can be reloaded internally with calculation_store.load_record. An authenticated historical-record browsing API remains future work.

Pending for this stage: live PostgreSQL migration/integration tests and provider smoke tests; broader market-cap coverage beyond the recent-date path below; financial expert review and a broader golden-company corpus; multi-year CAGR and additional profitability/leverage/return ratios; broader TTM coverage and financial review; actual driver-based FCFF forecasts and reviewed WACC estimation; EV/EBITDA using real enterprise value and EBITDA inputs; FX/security-master support; scenario comparison, restatement selection, retention/access controls, and editable recalculating Excel.

Recent dated market capitalization for comparables

The live comparables pipeline now fetches FMP's historical market-cap records and a separately retained current listing profile. The dated endpoint supplies symbol, date and market cap; the profile supplies quote currency, exchange and issuer/listing metadata. Statement reporting currency and undated TTM market cap are never substitutes for quote-currency/date evidence.

The supported initial contract is intentionally narrow:

  • Dates must come from the original cap row, be strictly before the UTC capture date, and lie within the preceding seven calendar days. Same-day rows are withheld to avoid presenting an incomplete session as a completed-date snapshot. There is no exchange-calendar claim, and this is not an intraday valuation feed.
  • Quote profiles must identify the exact symbol, a supported major currency, exchange and issuer identifier, confirm active trading, and explicitly classify the listing as neither an ADR, ETF nor fund. Missing/ambiguous metadata is rejected.
  • When the cap row lacks currency, implicit mapping from the quote profile is supported only for USD listings on NASDAQ, NYSE or AMEX. Other exchange/currency combinations require an explicit, matching currency on the cap row. Minor units such as GBp/GBX and unrecognized currency codes are not relabeled as major units.
  • Profiles must be captured on the cap retrieval's UTC date. The immutable document ID includes the daily profile capture identity. Current profile currency is a disclosed recent-date mapping policy, not proof of historical currency validity or a full security master. Arbitrary historical backtests are unsupported.
  • Values must be finite and positive. Identical duplicate rows deduplicate; conflicting records for the same symbol/date are withheld. API errors and unsupported data produce peer-specific warnings, not invented values.

FinancialObservation.market_cap_context links the currency policy to the exact profile document ID, hash, source URL and capture timestamp. Its contents participate in the observation identity. Source verification independently reloads that document, replays normalization from the original cap row and profile, and requires a matching value, symbol, date, unit, currency and profile binding. Both source records contribute exact passages to the calculation trace. Missing or changed currency evidence fails publication. Trace downloads retain the context, and the UI explains the currency basis separately from the statement's reporting currency. Offline replay with --documents verifies the profile link as well as the primary cap payload.

Recent batches cache for one hour in UTC-date-scoped keys and must still pass date freshness checks on reads. Fresh supported batches replace historical/TTM cap candidates in the live peer path. A failed refresh does not revive old archived values. With multiple cap dates, the builder chooses the largest eligible cohort's latest common date and discloses peers excluded from that date. Matching statement currency, fiscal intervals and filing availability remain required by comps-v1. Neither currency conversion nor annual/TTM mixing happens implicitly.

No database migration is added for this stage: the context fits the existing observation JSON and profile text uses the existing source archive. Existing observation IDs, immutable record JSON and old calculation replay remain compatible when no market-cap context is present. Prior migrations through 0005 are still required. Start a fresh analysis after setting FMP_API_KEY and confirming account access to the two stable endpoints; live analysis also needs its existing providers, PostgreSQL and Redis.

Validation includes provider HTTP fixtures through dated-cap normalization, independent archive reload, peer date selection and published calculation claims; tampered/missing profile rejection; provider failures and stale caches; immutable legacy compatibility; offline replay; and a PostgreSQL persistence test. Real account smoke tests remain pending because no FMP credential is configured in this checkout. PostgreSQL integration tests remain pending without a running test database.

Remaining work: actual provider/account validation and independent numerical cross-checks; reviewed currency methodology beyond the supported USD listing path; historical effective-dated currencies, security/issuer identity and share-class handling; ADR ratios and FX; broader TTM/calendar coverage; exchange calendars, corporate actions and provider corrections. Current-profile provenance does not establish source truth or historical investability.

TTM financials and differing fiscal calendars

The live calculation pipeline now fetches discrete quarterly income statements from FMP's stable income-statement endpoint with period=quarter&limit=12. The existing annual snapshot remains separate. New recipes ttm-income-v1 and comps-ttm-v1 produce source-linked revenue, net income, net margin, P/S, P/E and implied market capitalization. TTM totals are calculated trace nodes, never fabricated provider-reported observations.

Quarterly normalization requires the exact symbol, reported currency, fiscal year, Q1–Q4 label and end date. A quarter start is the immediately preceding fiscal quarter's end plus one day, including Q4-to-Q1 fiscal-year rollover. The predecessor must be unambiguous and the interval 75–105 days. Its original payload hash is retained in period.start_evidence; start_method=prior_quarter_end identifies this derivation. Missing/conflicting predecessors leave the start unknown and exclude the observation from TTM assembly. Independent source verification replays the quarter normalization against the retained original row and predecessor, not just the displayed date. Quarterly revenue and net income are normalized; EPS, annual rows and cumulative/YTD cash flows are not summed.

Each TTM needs exactly four distinct, chronological, complete, contiguous quarters with one currency and no segment dimensions. Gaps, overlaps, duplicates, unknown starts, annual/YTD substitutions and ambiguous source versions are rejected. The full interval must span 350–380 days, accommodating calendar and 52/53-week years. Revenue and earnings must use matching quarter boundaries and filing versions. Each filing must have known availability on/before the explicit as-of date; future or unknown availability cannot supply a TTM denominator. A trace is replayed from all retained quarter observations and their source passages before publication.

comps-ttm-v1 keeps one market-cap date but allows companies' actual trailing windows to differ under a visible policy:

Check Initial bound
Age of each TTM end at the market-cap date At most 185 calendar days
Difference between target and peer TTM ends At most 100 calendar days
Difference between their window lengths At most 7 days
Currency Identical statement and market-cap currencies; no FX inference

This supports differing fiscal quarter/year ends without pretending all companies reported over the same dates. The policy is a comparison tolerance, not calendarized financials: there is no interpolation or proration, and different seasonal/economic windows remain a disclosed limitation. Every company's actual start/end is retained in CalculationTrace.periods, displayed in the interface and PDF, and included in trace downloads and offline replay. Server-rendered claims use the entire target TTM window, never the first component quarter's dates.

The selector uses the most recent available four-quarter set at each candidate market-cap date. It does not silently resolve conflicting versions or skip an incomplete latest quarter to find an older convenient window. Peer capitalization dates still use the largest eligible cohort, then its latest common date. A valid TTM cohort is preferred over annual comparables; annual and TTM multiples are never combined into a median. If TTM inputs are unavailable, the separate comps-v1 annual recipe can still run under its original exact-interval rules. Earnings unavailable, misaligned or nonpositive on a trailing basis suppress P/E while valid P/S survives.

The quarterly fetcher caches for one hour and persists original observations before caching. A failed refresh produces a warning and does not reactivate old archived quarterly candidates in the live path. Annual/Q4 observations that share an end date are selected separately so quarterly ingestion does not break annual margins or fallback P/E. The new recipes and period metadata preserve old calculation IDs, serialized records and replay behavior; no new database migration is required. Existing migrations through 0005 are still required. Run a fresh analysis to fetch quarterly inputs; provider account access must include quarterly stable statements.

Tests cover fiscal-year rollover, calendar versus 52/53-week windows, source-boundary replay, incomplete/duplicate/overlapping/YTD inputs, restatement conflicts, filing availability, peer skew/staleness, loss-making P/E exclusions, annual fallback, HTTP/cache behavior, published claims, offline replay and database persistence. Live provider tests remain pending without an FMP key; PostgreSQL integration tests require a disposable configured database.

Remaining work: financial expert calibration of these comparison tolerances and a larger independently reviewed company corpus; actual provider/account validation; broader historical SEC ingestion and statement restatement selection, issuer/share-class/corporate-action handling; true calendarization and seasonality adjustments; broader non-US/half-year reporting and currency/FX support. The existing annual DCF has not been silently switched to TTM inputs. Source availability checks do not turn this application into a fully point-in-time backtesting system.

Q4, annual-plus-YTD and cumulative cash-flow reconstruction

New registered recipes extend period coverage without inserting calculated amounts into reported-observation storage:

Recipe Formula and output
q4-v1 Fiscal annual amount minus discrete Q1, Q2 and Q3 amounts; returns the actual residual Q4 interval.
ttm-ytd-v1 Previous fiscal annual amount + current fiscal YTD − comparative prior fiscal YTD; retains the full trailing interval.
cashflow-difference-v1 Later cumulative operating cash flow − immediately preceding cumulative operating cash flow, sharing one fiscal start; returns one discrete quarter. Annual − nine-month YTD also reconstructs Q4 cash flow.
ttm-flex-v1 Composes source-linked TTM revenue, earnings and optional operating cash flow/margins using explicit per-role methods.
comps-flex-v1 Uses those complete TTM series for P/S, eligible P/E and implied capitalization, including peers whose missing Q4 or discrete-quarter history prevents the earlier four-quarter recipe.

Supported additive metrics are revenue, net income and operating cash flow. EPS, ratios, balance-sheet instants, unknown periods and segmented observations are not reconstructed. Every input must have complete actual dates, compatible entity, metric, units, currency and provider, and known filing availability on/before the explicit as-of date. A filing dated before its covered period ends is rejected. Quarter/year start months are not assumed to be January.

Q4 needs a complete 350–380-day fiscal year and three distinct chronological, contiguous 75–105-day quarters beginning at its fiscal start. Their versions must not postdate the annual anchor. The remaining interval must itself be a supported quarter. Annual/YTD mixtures, overlapping periods and missing Q1–Q3 do not produce a residual. The result stays a calculation trace, never a fabricated reported Q4.

Annual-plus-YTD requires the prior prefix to start at the annual's fiscal start, the current prefix to start the day after that fiscal year ends, and prefix lengths to differ by at most seven days. Prefixes may represent the first quarter, half-year or nine months; a quarterly first-prefix is accepted only through these fiscal-start checks. Current and comparative prior YTD must share an identified document, filing date and accession/version. The annual anchor cannot postdate that interim anchor. The resulting trailing interval must span 350–380 days.

Cash-flow differencing requires the same fiscal start for both original cumulative amounts and a 75–105-day residual interval. The later input must explicitly be YTD or annual; subtracting arbitrary standalone quarters is not accepted. Q1 already represents a discrete first prefix. A cumulative cash-flow year can therefore use Q1 directly, difference Q2−Q1, Q3−Q2 and annual−Q3, and retain all intermediate subtractions. Negative quarter cash flow is preserved, not clipped or annualized. Adjacent valid differences can be published even when no complete revenue TTM exists. The cash-flow metric here is operating cash flow, not free cash flow or FCFF.

CalculationTrace.period_methods records each chosen series strategy: quarters, q4-plus-quarters, annual-ytd, or cashflow-quarters. Complete TTM series retain the existing 185-day age, 100-day peer end-gap and seven-day length-gap limits. Revenue/earnings must use matching methods, actual component intervals and filing versions; cash-flow margins require a matching trailing interval/currency. Peer series can use different disclosed methods because each denominator still represents a complete trailing year. They are never blended with annual-only multiples. A supported reconstructed TTM cohort supersedes annual-only comparables; an existing four-quarter TTM cohort remains preferred unless reconstruction adds more eligible peers or a newer common capitalization date. Existing recipe versions and replay behavior remain unchanged.

Selection prefers the newest supported trailing end, then reported quarters, Q4 reconstruction, annual-plus-YTD, and cumulative cash-flow-year differencing. Equivalent-priority conflicting canonical source versions require explicit selection; values are not averaged. Missing or incompatible earnings withhold P/E while valid P/S survives. The report, PDF and JSON downloads expose chosen methods and actual periods, and source-linked claim rendering distinguishes standalone as-of dates from capitalization dates. Offline replay verifies the registered bridge arithmetic and, with captured documents, the original provider payloads.

Target SEC annual/interim contexts already extracted by the pipeline are reused. For up to five peers, the pipeline extracts a SEC annual anchor and the bounded quarterly history described below, as well as fetching the existing annual and discrete-quarter vendor data. Explicit SEC start/end durations provide genuine cumulative YTD contexts; the application does not relabel vendor discrete cash-flow or income rows as YTD. Original context versions and comparative entries are retained by the existing observation store. Older SEC contexts can be used from that archive subject to availability checks. Fresh vendor quarterly batches replace archived vendor quarterly candidates, and a failed market-cap refresh still cannot reactivate an old capitalization snapshot. Extraction errors and missing contexts are disclosed as coverage warnings.

No new database migration or dependency is added. Prior migrations through 0005 remain required. Run a fresh analysis to gather the additional interim contexts. New method metadata is omitted when empty so legacy observation IDs, trace IDs and immutable record JSON remain compatible. The existing DCF is unchanged.

Validation covers hand-computed Q4 and annual/YTD totals, cumulative differences (including negative quarters), reconstructed Q4 in a rolling TTM, provider/metric/unit and period incompatibilities, conflicting versions and filing chronology, peer multiples, source reload failures/tampering, publication gates, offline replay, peer ingestion, frontend contracts and a database persistence round-trip test.

Pending: live provider/account validation and current PostgreSQL integration tests; financial expert review and independently reconciled company examples; automated broader accounting-policy reconciliation across annual/interim filings and SEC history beyond the bounded ingestion window; richer 52/53-week and non-US fiscal-transition coverage; additional cash-flow metrics, FX and share-class handling. Source/period/chronology checks do not prove cross-filing accounting comparability. That limitation is explicitly shown in reconstruction warnings rather than implied to be fully verified.

Historical 10-K/10-Q ingestion and filing-version reconciliation

Both the target and up to five peers ingest bounded SEC annual and quarterly history, including 10-K/A and 10-Q/A amendments in one shared submissions walk. Discovery reads filings.recent and follows the historical pages listed in filings.files through the SEC submissions API. It does not assume the recent array contains every needed quarter.

Defaults are a 2,192-day (approximately six-year) filing-date lookback, at most 96 filings total (annual, quarterly, originals and amendments), and at most ten historical archive pages. fetch_period_bridge_inputs accepts as_of, lookback_days, max_filings, max_archive_files, and refresh. These parameters also reach fetch_historical_filings; dedicated fetch_historical_10ks and fetch_historical_10qs wrappers filter forms with default budgets of 32 and 64 filings respectively. Requests can expand to 14,610 days (approximately forty years), 400 filings and 100 archive pages. Requests beyond those bounds fail before network access. The filing-date interval is relative to the requested cutoff, so an older cutoff walks relevant archive pages rather than substituting today's latest annual filing. Annual and interim facts then use the same immutable extraction cache, availability filters, source verification and reconciliation.

Discovery batches expose requested_start, as_of, forms, archive_pages_available, archive_pages_loaded, filings_discovered, and coverage_complete. Completeness means all relevant pages advertised by the SEC index were read and valid discovered filings fit within the requested budget; it is scoped to that filing-date interval and form set, not proof of complete XBRL coverage or every historical accounting period. Empty discoveries remain flagged. A discovered amendment excluded by the filing budget is unresolved and blocks quantitative reuse. Only warning-free discoveries are cached. Duplicate identical archive-index entries do not consume extra retrieval slots. Limits, inaccessible pages, malformed arrays, conflicting accession metadata and excluded rows produce explicit partial-coverage warnings. Requested cutoffs exclude later filing/acceptance dates. A late amendment to an older report remains a distinct accession; it does not replace unrelated quarters. Safe archive filenames are restricted to the requested CIK and the fixed SEC submissions host. Aligned required arrays and primary-document names are checked before constructing filing URLs.

Normalized submissions snapshots are retained in the existing immutable source archive. Filing metadata and each original XBRL fact version remain stored under their existing identities. Extraction runs with concurrency two. A shared per-event-loop SEC request gate permits at most eight requests per second; it also paces retries. Distributed/multi-worker rate coordination is not implemented. Successful discoveries cache for five minutes; partial discoveries are retried.

An accession-level 24-hour extraction cache reuses retained original observations only when all listed IDs, ticker, accession, filing date, document URL, acceptance time, payload hashes and source values still match. Missing/corrupt records trigger source extraction again. Failures and empty/nonmatching results are not marked as successes; refresh=True bypasses reuse. This is a processing-success marker, not a claim that every possible financial context or custom taxonomy has been extracted.

An amended filing with failed extraction, or known malformed/conflicting amendment metadata, is unresolved. It cannot silently authorize the old quantitative inputs: target calculations/reported snapshot are withheld, and an affected peer is excluded. A target whose essential revenue becomes unresolved does not publish a memo. A successful amendment still carries a scope warning: extracted numerical contexts are not a formal accounting restatement review. Original observations are retained in every case; a nonfinancial amendment is not automatically assumed harmless.

latest-available-overlap-v1 adds a reproducible selection audit:

  1. Group retained SEC facts by exact ticker, normalized metric, complete interval or instant, duration basis, units, currency and dimensions. Different fiscal windows and currencies are never merged; segmented/unknown contexts are outside this initial automatic policy.
  2. Select the latest available filing for each context at the explicit cutoff. Acceptance timestamps resolve same-day order only when known for all competing latest versions. Conflicting values in tied filings or within one accession are ambiguous; fetching a payload later does not resolve them. Identical aliases or re-presented values can be treated as equivalent with a deterministic source ID.
  3. Keep all original/superseded observations and distinguish single, equivalent, revised and ambiguous contexts. revised means a changed reported value in the retained numerical data, not a diagnosis that the company formally restated.
  4. Replace matching candidate/vendor contexts with the selected SEC version. Keep unresolved alternatives visible so the calculation selector cannot bypass an ambiguity by silently choosing a vendor number or an older convenient period.
  5. Independently check overlaps. A selected older annual/YTD aggregate spanning a changed interval from another filing is withheld without a compatible basis, even if that aggregate was filed later. Complete, contiguous selected quarters may instead reconcile to the latest changed cumulative amount when their exact sum matches it. Mismatches or incomplete coverage withhold the calculation. A matching aggregate sum does not establish the truth of every individual accounting component.

The policy is applied separately at each market-cap date. A revision available at the later report date cannot leak into an earlier-dated comparable. Current research financial calculations use the analysis cutoff. Reported annual snapshot observations are also updated to selected versions, with confidence downgraded and review warnings; ambiguous values are removed instead of being passed to the writer as current facts. Existing annual/Q4/YTD arithmetic recipes keep their previous behavior when replayed without the new policy metadata.

CalculationTrace.reconciliation pins the cutoff, exact source-universe IDs and context/version decisions. reconciliation_checks retains explicit quarter-sum vs reported-value checks. Both fields participate in the calculation identity. Before publication, the verifier independently reloads all required original, selected and superseded source records, verifies retained passages and replays selection and arithmetic. Modifying an audit, cutoff, reported overlap value or source version fails verification. An old report is not reinterpreted using today's newly arrived filings: the record's source snapshot is explicit and immutable.

The report UI and PDF expose the selected and retained alternative values, accessions, filing/acceptance dates, reasons and overlap checks. JSON downloads retain the complete audit and source evidence; offline replay works with the same retained documents. Alternative source passages are labeled in the synthesis prompt so they are not presented as the currently selected fact. The audit scope is retained-sec-contexts-only; it does not certify exhaustive SEC coverage, accounting policy compatibility, issuer identity history, or historical investability.

No dependency or database migration is added. The existing source, observation and calculation stores retain the additional data in their existing JSON fields. New metadata is omitted when absent so legacy record JSON, IDs and replay remain compatible. Existing migrations through 0005 remain necessary. Run a fresh analysis to ingest historical annual and interim filings; an initialized PostgreSQL/Redis environment, SEC contact User-Agent and existing provider credentials are still required.

Tests cover archive discovery, amendments, duplicate/conflicting metadata, as-of and resource bounds, unsafe archive links, request pacing, extraction reuse and failures; exact-context selection, unknown intraday order and same-accession conflicts; changed cumulative overlaps, stale aggregate rejection, earlier market-cap cutoffs, source/audit tampering, reported snapshot updates, publication, offline replay, frontend contracts and database round-trip retention of original/revised versions.

Pending: live SEC/sec-api/FMP account validation and current PostgreSQL integration checks; on-demand backfill beyond configured budgets and full historical research memo APIs; financial-expert examples and review of non-reliance notices, amendment purpose, custom taxonomies, reclassifications and accounting-policy changes; an explicit analyst reconciliation/approval workflow for blocked cross-filing aggregates; security-master/CIK changes and a complete point-in-time data system; durable operational ingestion ledgers, monitoring and distributed request coordination. These checks establish known-version numerical consistency, not a full restatement or audit opinion.

Historical annual coverage tests additionally exercise old cutoffs when the latest 10-K is in the future, 10-K/A extraction failures and malformed metadata, UTC acceptance-date boundaries, requests beyond the former ten-year/40-filing limits, and original/amended annual growth calculations with exact source-linked replay. Historical filing ingestion alone does not make full reports point-in-time: market prices, issuer identities, news and vendor snapshots still need historical availability coverage. A cutoff is a UTC date (end-of-day), not an intraday timestamp.

Historical financial analysis API

POST /api/v1/historical-analyses submits SEC financial analysis at an explicit UTC end-of-day cutoff. It uses historical 10-K/10-Q originals and amendments; it does not invoke the live memo pipeline, agents, vector search, current vendor fundamentals or the company-wide observation archive. No current prices, news or estimates are substituted. This endpoint produces financial facts and replayable calculations, not a full historical investment memo.

Example request:

{
  "ticker": "AAPL",
  "as_of": "2024-06-30",
  "lookback_days": 2192,
  "max_filings": 96,
  "max_archive_files": 10,
  "refresh": false
}

The 202 response includes job_id, as_of, analysis_kind and result_url. Poll GET /api/v1/jobs/{job_id} for progress; historical jobs expose their cutoff and result URL. Read GET /api/v1/historical-analyses/{job_id} when terminal. Results remain readable when their analysis status is failed, so callers can inspect coverage and failure reasons. Pending, unknown or expired results return 404; the shared jobs endpoint distinguishes pending from unknown jobs. Historical jobs do not expose a live memo or live exports through /memos.

The result contains:

  • filing_coverage: requested filing-date interval/form set, discovered filings, manifest document IDs, advertised/loaded archive-page counts, discovered/returned filing counts, unresolved amendments and discovery warnings. A complete discovery does not certify successful extraction, continuous financial periods or full SEC accounting coverage.
  • extractions: per-accession extraction status, observation count and failure reason. retained_sources contains the eligible verified versions, including superseded facts; financial_facts contains selected unambiguous contexts.
  • reconciliation: exact-context availability/version selection at the requested cutoff. calculations contains independently source-verified recipe records with all required original/superseded observations, exact passages and replay traces. Only the discovered filing universe feeds these outputs. Observation and accepted filing dates are checked again before calculation. Unresolved amendments or failed source verification withhold financial outputs instead of falling back to older sources. A normal extraction failure remains visible as incomplete coverage.
  • missing_data: structured code, message, optional accession_no and metric. Codes identify discovery/ingestion/extraction failures, partial filing coverage, missing annual/interim filings, unsupported observations, unresolved amendments, source/calculation verification failures, ambiguous contexts, missing annual revenue or matching income/cash-flow contexts, stale annual data, unavailable calculations and unsupported historical research inputs. Annual data is flagged stale when its latest verified revenue period ended over 550 days before cutoff; the exact filing and financial-period dates are also returned.
  • financial_coverage_complete: scoped to discovery, extraction, supported annual financial contexts and growth/margin/TTM calculation coverage. An omitted DCF scenario does not alone make this flag false. It never certifies a complete investment-research dataset. Overall status is always partial or failed because full historical research inputs are not implemented.

Optional dcf_scenario has the same explicit assumptions contract as live analysis. DCF remains unavailable when required source-linked debt, cash, shares or revenue history are missing. Caller-supplied assumptions are labeled as supplied now, not proven available at the cutoff. Market-cap comparables are not fetched in this mode.

Source passages link to GET /api/v1/historical-analyses/{job_id}/evidence/{document_id}. Only source snapshots and discovery manifests referenced by that result and belonging to its company can be downloaded; unrelated documents return 404. Raw discovery manifests are captured today and can list filings after the cutoff; those filings are excluded from the analysis inputs. The snapshot is evidence of the discovery response, not a historical-time snapshot of the SEC service.

Cutoffs must be YYYY-MM-DD between the operational lower bound 1994-01-01 and today (UTC); timestamps, future cutoffs, unknown fields and out-of-range retrieval budgets return 422. Filing availability is date-based, not intraday. The live POST /analyze now rejects unknown fields, including as_of, so an accidental historical request cannot silently run live analysis. Use the separate endpoint.

Historical analysis requires PostgreSQL, Redis, SEC_API_KEY and a real SEC contact EDGAR_USER_AGENT; LLM, embedding and FMP credentials are not required. Existing migrations through 0005 suffice. No dependency or migration was added. OpenAPI, generated TypeScript contracts and startHistoricalAnalysis/getHistoricalAnalysis client helpers cover the endpoints. The historical UI described below uses the same endpoints and cutoff/coverage contracts.

Operational limits remain: jobs run through FastAPI BackgroundTasks; job/results expire from Redis after 24 hours, while verified source and calculation records remain in PostgreSQL. Durable historical job/result storage, restart-safe worker queues, cancellation, access controls, resumable backfill and ingestion monitoring remain pending. Current ticker-to-CIK mapping and data retrieved today do not prove historical issuer identity or contemporaneous vendor availability. Historical prices/currencies/share classes, news, estimates, transcripts, macro inputs and full historical memo generation remain pending, along with live SEC/sec-api and PostgreSQL deployment validation.

Historical-analysis UI

Open /historical from the History navigation item or the home-page historical financials link. Select a ticker and UTC end-of-day availability cutoff. The form validates real calendar dates from 1994-01-01 through today (UTC), normalizes the ticker, and exposes bounded lookback/filing/archive-page limits and an optional refresh. Zero archive pages is valid and can yield disclosed partial discovery. Submission/configuration failures appear inline and retain the chosen inputs.

Successful submission opens /historical/{jobId}. Queued/running jobs show the chosen cutoff and processing progress, explicitly distinguished from coverage. Partial and failed terminal jobs load their historical result so missing-data reasons remain inspectable. An accidental historical job opened through the live analysis route links to its historical result and does not fetch a live memo.

The result view separates filing discovery from supported financial coverage, shows requested filing-date interval/forms/budgets, advertised and loaded archive pages, discovered and returned filings, actual report/filing/acceptance dates and per-accession extraction outcomes. Structured missing-data reasons are visible before the financial outputs, including metric/accession context; processing and calculation warnings remain expandable. Missing discovery metadata is labeled unavailable, rather than presented as zero or complete coverage.

Selected financial contexts retain exact decimal strings, reporting windows, units, currencies and provenance. Existing calculation views expose formula steps, filing selection audits, source passages and trace JSON downloads. Discovery manifests and retained financial source passages link to the historical result's scoped evidence endpoint. Only supported result-scoped snapshot paths are linked to the configured API origin. Runtime validation rejects missing coverage flags, warning arrays, inconsistent ticker/cutoff metadata and misleading complete responses.

The UI labels its SEC-only scope, sources retrieved now, current ticker-to-CIK mapping limitation and 24-hour result retention. Historical market data and full research memos are not presented as available. Polling stops at terminal states; expired/missing jobs and unavailable/invalid results offer explicit errors and retry/new-analysis actions.

Validation includes Node tests for cutoff/date/budget rules, historical versus live job handling, strict response contracts, safe evidence paths, and server rendering of the actual result component for partial, failed and missing-coverage responses. The fixture in frontend/tests/fixtures/historical-analysis.json is fictional TEST data validated by the backend response model; it is test-only and is not exposed as live research. A test-only TypeScript loader uses the existing compiler to render TSX without adding dependencies. Browser checks with a local fixture cover cutoff persistence, queued-to-terminal polling, partial/failed results, source inspection, actionable configuration errors and a 375px layout. Live-account end-to-end validation and a broader automated browser/accessibility suite remain pending.

Other pending work includes historical run comparison, saved/cross-session history beyond job links, durable restart-safe jobs/results, resumable backfills and a scenario editor within the historical form (the API already accepts explicit DCF scenarios). Historical prices, market caps, news and estimates still require their own point-in-time data foundation before full historical research is supported. No dependency, API schema or database migration is added by this UI stage.

Explorer des projets similaires

Chargement…