Fundamental strategies trade on what companies report: revenue growth, margins, earnings, debt. The data is public, every US company files it with the SEC, but using it in a backtest is harder than it looks. Most fundamental datasets are stamped with the quarter's end, weeks before anyone saw the numbers, and quietly replace first reports with later restatements. Both make a backtest look better than anything you could have traded.
MarketsCoder's US Company Fundamentals dataset is built to avoid both. This guide shows what's in it and how to use it.
What's in the dataset
One row for every 10-K and 10-Q a company files, built from the XBRL financial data in EDGAR, from July 2009. Each row has about 30 normalized fields:
- Income statement:
revenue,gross_profit,operating_income,net_income,eps_dilutedand more, for the filing's quarter or year. - Cash flow:
operating_cash_flow_ytd,capex_ytd,buybacks_ytd, fiscal year to date as companies report them. - Balance sheet:
cash,total_assets,total_liabilities,long_term_debt,shareholders_equity,shares_outstanding. - Identity:
form,fiscal_year,fiscal_period,period_end, and the filing's accession number.
A field a filing doesn't report is None: banks, for example, have no gross profit.
When each row arrives
Rows become available at 17:30 New York time on the filing date. EDGAR dates any filing accepted after 17:30 as the next business day, so a row is never earlier than the real release, and at most a day later. Amendments arrive as their own rows, on their own dates. Our guide to look-ahead bias explains why this matters.
A margin filter in Python
Hold Apple while its latest reported net margin is above 20%:
from AlgorithmImports import *
from lean_platform_data import SecFundamentals
class MarginFilter(QCAlgorithm):
def initialize(self):
self.set_start_date(2014, 1, 1)
self.set_end_date(2021, 1, 1)
self.aapl = self.add_equity("AAPL", Resolution.DAILY).symbol
# A ticker or a CIK. Rows arrive at 17:30 New York time on the filing date.
self.fundamentals = self.add_data(SecFundamentals, "AAPL").symbol
def on_data(self, slice):
if self.fundamentals in slice:
f = slice[self.fundamentals]
self.debug(f"{f.form} {f.fiscal_period} {f.period_end}: revenue {f.revenue}, EPS {f.eps_diluted}")
if f.net_income and f.revenue and f.net_income / f.revenue > 0.2:
self.set_holdings(self.aapl, 1)
else:
self.liquidate(self.aapl)The decision happens when a filing arrives, so the strategy only changes its mind four times a year, on real filing days.
Ideas worth testing
- Growth: compare this quarter's revenue with the same quarter a year earlier, to avoid seasonality.
- Quality: margins, return on equity (
net_incomeovershareholders_equity), or low debt to equity. - Cash: free cash flow,
operating_cash_flow_ytdminuscapex_ytd, against market value. - Buybacks: companies shrinking their share count.
Explore a company's filings first in a notebook, or ask the AI assistant to write a screen. The data is public, from the SEC, and free to use in backtests on MarketsCoder.
Frequently asked questions
Where does the SEC fundamentals data come from?
From the XBRL financial data companies file with the SEC's EDGAR system, one row for every 10-K and 10-Q, normalized into about 30 fields.
When does a filing reach my backtest?
At 17:30 New York time on the filing date. EDGAR dates a filing accepted after 17:30 as the next business day, so this is never earlier than the real release, and up to a day later.
How are restatements handled?
Amendments (10-K/A, 10-Q/A) arrive as new rows on their own filing date. They never rewrite history, so a backtest sees what investors could see at the time.
