Defeat Beta API

repository·main·Indexed 20 days ago

https://github.com/defeat-beta/defeatbeta-api

An open-source, high-performance alternative to Yahoo Finance's market data APIs. Powered by DuckDB and hosted datasets, it provides sub-second analytical queries for stock prices, financial statements, and qualitative data. Key features include automated DCF valuation analysis, LLM-powered earnings call transcript analysis, and a Model Context Protocol (MCP) server for direct integration with AI models.

Tokens
67.1K
Snippets
214
Records
288
Agent score
72%

What's inside defeatbeta-api

  1. Overview of DefeatBeta Skills

    main

    DefeatBeta Skills are specialized tools designed to enhance an AI agent's financial analysis capabilities. They function as extensions on top of the Defeat Beta API MCP. These skills are compatible with AI platforms that support skill extensions, including Claude Desktop, Manus, Codex, Hermes Agent, and OpenClaw Agent.

    Key capabilities include:

    • Pre-earnings analysis: Synthesizing consensus estimates, guidance, and bull/base/bear scenarios.
    • DCF Modeling: Generating editable Excel files with live formulas for WACC and FCF projections.
    • Post-earnings reporting: Producing professional sell-side style DOCX reports with beat/miss analysis and updated valuations.
  2. Overview of Defeat Beta API

    main

    Defeat Beta API is an open-source, high-performance alternative to Yahoo Finance's market data APIs. It is designed for reliability by using a hosted dataset on Hugging Face (defeatbeta/yahoo-finance-data) instead of web scraping, which eliminates common rate-limiting and scraping issues.

    Key Features:

    • High-Performance Engine: Powered by DuckDB's OLAP engine and the cache_httpfs extension for sub-second SQL queries.
    • Extended Financial Data: Provides metrics such as TTM EPS, TTM PE, Market Cap, various ratios (PS, PB, PEG, ROE, ROIC, ROA), WACC, Equity Multiplier, Asset Turnover, SEC Filings, Earnings call transcripts, Stock News, and Revenue breakdowns (by segment and geography).
    • Automated DCF Valuation: Generates Discounted Cash Flow (DCF) analyses with professional Excel outputs, including WACC calculation, 10-year cash flow projections, and fair price estimation.
    • LLM-Powered Analysis: Tools for using LLMs to analyze earnings call transcripts, quarterly financial changes, and quarterly forecasts.
    • AI Integrations: Includes an MCP (Model Context Protocol) server implementation and a Skills implementation for use with platforms like Claude.ai and Manus.
  3. Data Source Tiers for Earnings Analysis

    main

    The defeatbeta-earnings-analysis skill categorizes all financial data into three mandatory tiers to ensure data integrity and clear attribution. Developers and users must adhere to these source policies:

    Tier 1 — MCP only (Strict)

    Authoritative financial data. Use only specific MCP tools. No web fallback is allowed. If MCP returns no data, state the gap in the report; do not attempt to patch it from 10-Qs, press releases, or news.

    Tier 2 — MCP preferred, web fallback allowed

    Primary source is MCP. Web fallback (e.g., 10-Q, earnings releases) is permitted only if MCP coverage is incomplete. Crucial: Fallback data must be explicitly labeled as Fallback: in all figures, tables, and the Sources section to prevent blending with authoritative MCP data.

    Tier 3 — Web only

    Data MCP does not cover. This includes consensus estimates, analyst price targets, stock reaction history, options-implied moves, and specific operating metrics (e.g., DAU/MAU, unit shipments). Always cite the source name and an "as of" date.

  4. Use Defeat Beta API with Model Context Protocol (MCP)

    main

    By using the Model Context Protocol (MCP), you can connect the Defeat Beta API directly to AI models. This allows the models to access real, structured financial data for analysis and reasoning, rather than relying on outdated information or assumptions.

    Common use cases for this integration include:

    • Analyzing Company Profiles
    • Investigating Company Officers
    • Tracking Stock Prices and Historical Performance
    • Reviewing Earnings Call Transcripts
    • Monitoring Financial News
    • Examining Financial Statements
    • Analyzing Revenue Breakdowns
    • Assessing Profitability, Valuation, and Growth metrics.
  5. How Defeat Beta API MCP works

    main

    The Defeat Beta API MCP acts as a bridge between MCP clients (like Claude Desktop or Manus AI) and the defeatbeta-api Python package.

    The workflow is as follows:

    1. MCP Client sends requests via JSON-RPC over stdio.
    2. Defeat Beta API MCP Server (running in an isolated .venv) receives the request, constructs the necessary context, performs windowing/summarization, and shapes the output for the LLM.
    3. Defeat Beta API (the PyPI package) is called by the MCP server to access market data, prices, history, and metrics.
    4. Financial Data Sources are retrieved via the API and returned to the client.
  6. Explore Stock Evaluation Dimensions

    main

    The Defeat Beta API evaluates stocks across five primary dimensions. You can use these categories to access specific financial and qualitative data points:

    • Information: Qualitative data including profile, sec filing, officers, earnings call transcripts, and financial news.
    • Finance: Quantitative market and statement data including price, statement, earning calendar, splits, dividends, and revenue breakdown (segmented by geography, product, etc.).
    • Profitability: Margin metrics such as gross margin, operating margin, net margin, ebitda margin, and fcf margin.
    • Growth: Year-over-year (YoY) growth metrics for revenue, operating income, net income, fcf, and eps.
    • Value: Valuation and historical ratios including ttm-eps, ttm-pe, historical-market-cap, historical-ps-ratio, historical-pb-ratio, historical-peg-ratio, and various industry-specific comparison ratios (e.g., industry-ttm-pe, industry-net-margin).
  7. Understand the defeatbeta-earnings-analysis report structure

    main

    The primary deliverable is a DOCX file organized as a standard sell-side update. The typical structure includes:

    PagesContent
    Page 1Rating + price target + 3-4 paragraph investment-impact bullets + updated estimates summary table
    Pages 2-3Detailed results analysis — revenue by segment (Client / Server / DC GPU / Gaming / Embedded), margin walk, EPS reconciliation
    Pages 4-5Key business metrics + management guidance (current quarter + medium-term) parsed from the earnings call
    Pages 6-7Investment thesis update — each prior thesis pillar reassessed against this quarter's evidence
    Pages 8-10Valuation update — DCF (via defeatbeta-dcf's get_stock_dcf_analysis tool), trading multiples, peer benchmarks, price-target walk
    Page 11-12Appendix — peer comparison table, transcript highlights, complete Sources section (Tier 1 / Tier 2 / Tier 3)

    The report embeds approximately 10 charts (e.g., revenue progression, EPS progression, margin trends, segment mix, and valuation bands).

  8. Compare defeatbeta-api with yfinance

    main

    When deciding between defeatbeta-api and yfinance, consider your requirements for data freshness versus bulk analysis efficiency:

    Use defeatbeta-api if:

    • You need bulk historical data: It is optimized for large-scale analysis.
    • You want to avoid rate limits: It avoids Yahoo Finance's real-time rate limits by fetching data periodically (typically weekly) and hosting it on Hugging Face.
    • You need efficient querying: It uses the Parquet format, which allows for flexible SQL queries via DuckDB.
    • You need high performance: It uses cache_httpfs for local disk caching of remote data from Hugging Face.
    • You need multi-source data: It integrates data from sources beyond just Yahoo Finance.

    Use yfinance if:

    • You need real-time data: defeatbeta-api is non-real-time and updates on a periodic basis (typically weekly).
  9. How defeatbeta-earnings-analysis ensures data accuracy

    main

    The skill uses a Call-Then-Write cache pattern to prevent hallucinating numbers and ensure every cited figure is traceable to a source:

    1. Immediate Caching: Every Tier 1 or Tier 2 MCP tool call is immediately followed by a Write of the verbatim return value to a JSON file in ./<TICKER>_<PERIOD>/cache/<tool>.json within the current working directory.
    2. Source of Truth: These cache files serve as the report's ground truth.
    3. Verified Reading: When drafting sections, the model Reads the relevant cache file to cite numbers rather than relying on its own context memory, which may have been compressed or paraphrased.

    This pattern also applies to transcripts; the skill uses grep against on-disk transcripts for guidance quotes rather than pulling massive text blocks into the LLM context.

  10. Important API requirements for financial analysis

    main

    When using the defeatbeta-analyst APIs, be aware of these critical requirements:

    1. Relative Time Queries: Always call get_latest_data_update_date first. This provides the reference "today" date for all relative time queries.
    2. Fiscal Periods: Earnings transcripts use fiscal periods which may differ from calendar periods. You must specify both fiscal_year and fiscal_quarter.
    3. SEC Filing Access: When accessing SEC URLs, you must use the sec_user_agent field value as the User-Agent header, otherwise the SEC will block the request.
    4. Sector Exceptions: ROIC and Equity Multiplier are not applicable to banks or financial institutions. Check the sector in the company profile before calculating these.
  11. Calculate the Weighted Decision Model score

    main

    The weighted decision model uses 5 to 8 dimensions with explicit weights totaling 100%. Each dimension is scored from -2 to +2:

    ScoreOutcome
    +2Clear Bull outcome
    +1Modestly positive
    0Base or in line
    -1Modestly negative
    -2Clear Bear outcome

    Formula: Weighted Score = sum(weight × dimension score ÷ 2)

    The resulting score ranges from -1.0 to +1.0. Use the following default bands to determine the scenario:

    • Bull: score $\ge$ +0.35 and no veto gate triggered
    • Base: score between -0.35 and +0.35 and no veto gate triggered
    • Bear: score $\le$ -0.35, OR any Bear veto gate triggered.
  12. DCF Calculation Methodology

    main

    The DCF analysis follows these mathematical models:

    • CAPM (Cost of Equity): Rf + β × (Rm - Rf)
    • WACC: Wd × Kd × (1 - Tax Rate) + We × Ke
    • CAGR: (Ending Value / Beginning Value)^(1/Years) - 1
    • Enterprise Value (NPV): Σ Total Value_i / (1 + WACC)^i for $i=1$ to $10$
    • Terminal Value (Gordon Growth Model): FCF₁₀ × (1 + g_terminal) / (WACC - g_terminal)
    • Equity Value: Enterprise Value + Cash - Total Debt
    • Fair Price: Equity Value / Shares Outstanding