Skip to main content
Glama
marketlens

marketlens

by lisaperrin

marketlens

CLI and MCP server for stock research on top of yfinance. Also a Claude Code plugin.

CI Python 3.12+ License: MIT

╭──────────────────── AAPL · Apple Inc. ────────────────────╮
│ Price                                          355.58 USD │
│ Day change                                         +0.63% │
│ Total return (6mo)                                +15.51% │
│ Annualised volatility                              27.43% │
│ Max drawdown                                      -12.71% │
│ Sharpe ratio                                         1.17 │
│ SMA 50 / 200                                   342.84 / — │
│ RSI 14                                               58.0 │
│ Market cap                                          5.17T │
│ P/E trailing / forward                      39.60 / 33.63 │
│ 52-week range                             243.42 / 360.83 │
│ Sector / industry       Technology / Consumer Electronics │
│ Data as of                 2026-11-26 17:16 CET (delayed) │
╰───────────────────────────────────────────────────────────╯

Quick reads on single stocks, side-by-side comparisons, portfolio valuation from a TOML file, and the same data exposed to Claude through MCP so it pulls real numbers instead of making them up. Data is delayed Yahoo data. Not investment advice.

Install

Needs Python 3.12+ and uv.

git clone https://github.com/lisaperrin/marketlens
cd marketlens
uv sync
uv run marketlens --help

Related MCP server: Yahoo Finance MCP Server

Usage

marketlens quote AAPL MSFT
marketlens analyze NVDA --period 6mo
marketlens compare AAPL MSFT VTI
marketlens portfolio                     # reads ./portfolio.toml
marketlens brief --watchlist AAPL,MSFT --portfolio portfolio.toml
marketlens alerts --portfolio portfolio.toml --rules alerts.toml
marketlens cache stats

--json before the command gives JSON. --no-cache skips the local cache.

Periods: 1mo 3mo 6mo 1y 2y 5y max.

Optional flags

marketlens analyze NVDA -b SPY           # benchmark return, excess return, beta
marketlens compare AAPL MSFT -b VWCE.DE  # Excess and Beta columns
marketlens portfolio -b VWCE.DE          # benchmark day move + weighted portfolio beta
marketlens analyze NVDA --indicators     # EMA 20, MACD, Bollinger Bands

Benchmark stats use the trading days both series have in common. The analyze panel shows a "Signals" row when the close is outside the Bollinger Bands, MACD or SMA 50/200 crossed in the last 5 sessions, or RSI is past 70/30. Otherwise the row isn't there.

portfolio.toml

base_currency = "EUR"
benchmark = "VWCE.DE"      # optional, used by `portfolio` only

[[holdings]]
symbol = "ALV.DE"
shares = 5
cost_basis = 250.00        # avg price paid per share

Use the ticker of the listing you bought (e.g. ABEA.DE for Alphabet on Xetra). There is no FX conversion, so mixed currencies will add up to nonsense. The file is gitignored.

alerts.toml

[defaults]
rsi_above = 70
rsi_below = 30
day_change_abs = 5.0       # percent
bollinger = true

[[rules]]
symbol = "NVD.DE"
price_below = 120.0
price_above = 200.0

alerts prints only what fired. Symbols it can't fetch are listed as skipped; the rest still run. --fail-on-alert exits 3 if anything fired (for cron). See examples/alerts.example.toml.

Claude Code

/plugin install marketlens --marketplace lisaperrin/marketlens

Installs:

  • MCP server marketlens with get_quote, analyze_ticker, compare_tickers, portfolio_summary, market_brief, check_alerts, get_statements. Started with uvx from the plugin directory, so uv has to be on PATH. First start takes a minute.

  • Skills: /marketlens:analyze-ticker, compare-tickers, portfolio-review, market-brief, check-alerts. add-indicator is for working on this repo.

  • Agents: market-analyst (research notes from live data), quant-reviewer (checks indicator maths and tests).

  • Hooks: one prints the tool list at session start, one spots $TICKER in a prompt and tells Claude to use the tools instead of recalling prices.

Layout

src/marketlens/
  data/         MarketDataProvider protocol, YFinanceProvider, CachedProvider (sqlite), FakeProvider
  analysis/     indicators.py (SMA, EMA, RSI, MACD, Bollinger), stats.py (returns, vol, drawdown,
                Sharpe, beta, correlation), summary.py (TickerSummary, signals)
  portfolio/    holdings.py (TOML), valuation.py
  alerts/       rules.py (TOML), engine.py
  report/       rich tables, brief
  cli.py        Typer
  mcp_server.py MCPServer, same functions as the CLI

All data access goes through MarketDataProvider. CachedProvider wraps any provider with a SQLite cache (quotes 15 min, history 1 h, fundamentals and statements 24 h). FakeProvider serves fixed frames; tests never hit the network.

Conventions, since they bite otherwise:

  • total_return, annualized_volatility, max_drawdown, pnl_pct, weight are fractions. change_pct, day_change_pct, dividend_yield are percentages.

  • None means Yahoo didn't have it. Nothing is estimated or filled in.

  • RSI is Wilder smoothing. Volatility is sample std × √252. Beta is cov/var of daily returns on an inner join of dates, None under 3 shared points.

  • Errors subclass MarketLensError. CLI prints one line and exits 1. MCP raises ToolError.

get_statements(symbol, years=4) (library and MCP, no CLI command) returns per-fiscal-year balance sheet / income / cash flow lines: net PPE, capex (as a positive number), R&D, SG&A, total debt, cash, shares outstanding, close at year end. Oldest first, as reported. Written for firmvalue, which uses this package as its data source. STATEMENT_FIELDS has the field names. If you type against Statements with a Protocol, use read-only properties; frozen dataclass fields don't satisfy settable attributes under strict mypy.

Development

uv sync --all-groups
uv run pytest -q                                  # ~225 tests, offline, ~3 s
uv run ruff check . && uv run ruff format --check . && uv run mypy
uv run python scripts/validate_plugin.py --with-claude-cli

ruff, line length 100. mypy strict. pytest treats warnings as errors. CI runs on 3.12 and 3.13. Every indicator and statistic has a test with a value computed by hand; see tests/analysis/. .claude/settings.json has two hooks for people working on this in Claude Code: ruff after every edit, and a block on git push --force, --no-verify and git reset --hard.

Design notes and the plans I worked from: docs/design.md, docs/plan.md, docs/plan-0.2.md.

Changelog

  • 0.3.1: cache rows written by an older version of a model are refetched instead of decoded with missing fields (0.3.0 could report employees=None from a 0.2.0 cache for a day).

  • 0.3.0: get_statements, Fundamentals.employees, py.typed.

  • 0.2.0: benchmark comparison, EMA/MACD/Bollinger + signals, alerts.

  • 0.1.0: provider + cache, analysis, portfolio, CLI, MCP server, plugin.

Known gaps

No FX. No intraday. No backtests. Headcount is a single latest number (yfinance has no history). Yahoo line names differ for banks and insurers, so some statement fields come back None there.

License

MIT. Yahoo data via yfinance, subject to Yahoo's terms. Not affiliated with Yahoo.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides tools for stock data retrieval, historical analysis, and market comparison using yfinance. It features robust guardrails to ensure secure interactions and blocks restricted content like investment advice.
      -
    • A
      license
      A
      quality
      D
      maintenance
      Provides real-time stock quotes, market indices, historical data, and financial visualizations from Yahoo Finance without API keys, enabling users to analyze and visualize market data through Claude.
      3
      1
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables Claude to fetch live company data and news by ticker, including quotes, financials, analyst views, and historical data via Yahoo Finance.
      -
    • F
      license
      Not graded
      quality
      C
      maintenance
      Provides Claude with free stock-market data including quotes, fundamentals, history, news, index top-10 rankings, market movers, and penny-stock screens using public sources like Yahoo Finance and Wikipedia. No API keys or subscriptions required.
      -