fundamentalista-rails
Fundamental analysis pages for your Rails application, on top of the fundamentalista gem. Mount the engine and you get company pages with statements, ratios, scores and valuation, peer comparison with the magic formula, and watchlists whose valuation snapshots build a history over time.
Installation
gem "fundamentalista-rails"bin/rails fundamentalista_rails:install:migrations
bin/rails db:migrateMount the engine and configure the data source. The SEC asks for a User-Agent naming your application and a contact email; Financial Modeling Prep needs an API key.
# config/routes.rb
mount FundamentalistaRails::Engine, at: "/fundamentals"
# config/initializers/fundamentalista.rb
Fundamentalista.configure do |config|
config.edgar_user_agent = "Acme Research research@acme.com"
config.fmp_api_key = ENV["FMP_API_KEY"] # optional
endThe engine points the gem at Rails.cache with a one day expiry unless you set config.cache yourself, so a company page costs one download and a watchlist does not hammer the SEC. Put the engine behind whatever authentication your application uses; it ships none.
Pages
| Path | What it does |
|---|---|
/fundamentals |
Look a ticker up |
/fundamentals/companies/AAPL |
Five years of statements with growth, every ratio, Piotroski, Beneish and owner earnings |
/fundamentals/companies/AAPL?price=320 |
The same, plus multiples, yields, Graham number, Altman Z-score, intrinsic value and implied growth at that price |
/fundamentals/comparison?tickers=AAPL+MSFT+KO |
Peers side by side, with prices for the multiples, ranked by the magic formula |
/fundamentals/watchlists |
Named lists of companies, each holding with the price you value it at |
The pages are server rendered with a small stylesheet of their own, so they fit any application and need no assets, JavaScript or Tailwind.
Watchlists and snapshots
A watchlist holds companies with a price. Taking a snapshot of a holding stores that day's ratios, valuation and scores as JSON on a Snapshot record, so looking at a company regularly leaves you with its valuation history, which the underlying data sources never give you for free.
holding = FundamentalistaRails::Watchlist.find_by(name: "Quality").holdings.find_by(ticker: "AAPL")
holding.snapshot!
holding.snapshots.map { |snapshot| [snapshot.taken_on, snapshot.dig(:valuation, :pe)] }The models are plain Active Record and yours to extend: schedule snapshot! from a job to build the history without visiting the page.
Development
bundle install
bundle exec rake # request specs against a dummy app, and RuboCopSpecs stub the SEC with recorded responses; no keys are needed.
License
MIT.