AI & ML
Fundamental analysis in Ruby, straight from SEC EDGAR
Bruno Costanzo Dev.to (EN Zone)
2 views
fundamentalista is a Ruby gem for fundamental analysis of listed companies. Version 0.6.0 is on RubyGems.
Fundamentalista.configure { |c| c.edgar_user_agent = "Acme Research research@acme.com" }
apple = Fundamentalista.company("AAPL")
year = apple.financials.latest
year.income.revenue # BigDecimal
year.ratios.roe
year.ratios.cash_conversion_cycle
year.piotroski.score
valuation = apple.valuation(price: 230)
valuation.pe
valuation.fcf_yield
valuation.altman_z.zone # => :safe
valuation.intrinsic_value(growth: 0.06, discount_rate: 0.09)
Why another one
Most fundamental data libraries wrap a paid API and hand you a hash. I wanted the shape of RubyLLM: small value objects, one obvious call per question, nil when a filing lacks an input so a ratio never raises on an incomplete company, and to_json on everything so it drops into a Rails view.
Where the data comes from
SEC EDGAR XBRL company facts. Free, no key, only a User-Agent with your contact. US GAAP and IFRS filers, in their reporting currency.
Financial Modeling Prep with a key, for quotes, estimates, prices, segments and exchange rates.
EDGAR is the interesting part. Companies tag the same idea under different concepts, so every line item has an ordered list of alternatives measured over the 500 largest filers with script/coverage. Fourth quarters exist only as annual figures, so they are derived, except weighted average shares, which are not additive. Some filers negate expenses, some tag three currencies. Every figure remembers the concept, form and filing it came from:
year.source(:revenue)
# => #<Fundamentalista::Source concept: "RevenueFromContractWithCustomerExcludingAssessedTax", form: "10-K", filed: 2025-10-31, derivation: :reported>
What is inside
Income, balance and cash flow statements with derived lines (EBIT, EBITDA, free cash flow, net debt, working capital)
Annual, quarterly and trailing twelve months periods
Profitability, liquidity, leverage, efficiency and working capital ratios, DuPont, accruals
Piotroski F, Altman Z, Beneish M, owner earnings
Multiples, yields, Graham number, DCF with fading growth, reverse DCF, earnings power value, residual income, WACC
Banking and insurance lines and ratios: net interest margin, cost of risk, combined ratio, the float
Peer comparison with rankings, Greenblatt's magic formula and currency conversion
Rails
fundamentalista-rails is a mountable engine with watchlists that snapshot ratios and valuations per holding.
Limitations
As-filed data has edges the gem documents rather than hides: stock splits are restated only in later filings, multi-class companies tag share counts per class, and a filer that negates a provision keeps its sign.
Repo: https://github.com/bruno-costanzo/fundamentalista
Read original: https://dev.to/bruno_costanzo/fundamental-analysis-in-ruby-straight-from-sec-edgar-45b1
← Previous
An Pixelart Editor in an table?
Next →
I Wrapped My x402 Pay-Per-Call APIs in an MCP Server — and Got Into the Official Registry Without GitHub
Related
I am 18 should i continue
AI & ML
0
Reddit r/programming
My Grandmother Ran Ajo. I Built the Version Where the Pot Can't Walk Away
AI & ML
0
DEV Community
One AI, six jobs: how I take an idea from a one-line thought to something live, with a team of agents that share a task board
AI & ML
0
DEV Community
The 4 Layers That Decide Which SDK a Coding Agent Uses
AI & ML
0
DEV Community
Comments0
No comments yet — be the first