Build an Earnings Preview Agent
Before a company reports earnings, analysts need a quick-hit research brief covering the company’s fundamentals, factor exposures, and recent insider activity. This tutorial builds a Node.js agent that pulls data from multiple SEC API endpoints and assembles a pre-earnings research brief you can share with your team.What you will build
- A Node.js script that generates pre-earnings research briefs
- Company intelligence summary from the SEC API intelligence bundle
- Factor decomposition showing what is driving the stock
- Recent insider transactions leading up to earnings
- A formatted markdown report ready for distribution
Prerequisites
- An SEC API key (set as
SECAPI_API_KEY) - Node.js 18+
- Basic familiarity with the SEC API
Step 1 — Set up the project
Create the project and install dependencies.package.json:
.env file:
Step 2 — Build the data fetchers
Createindex.js with functions that pull data from each SEC API endpoint.
Step 3 — Build the report generator
Add the logic that assembles all the data into a structured markdown report.Step 4 — Wire up the main function
Add the entry point that orchestrates all the data fetches and generates the report.Step 5 — Run the agent
Generate an earnings preview for any ticker.Expected output
Step 6 — Generate batch previews
Add support for generating previews for all companies reporting in a given week.Step 7 — Extend with custom queries
Use the SEC API intelligence query endpoint to add custom research questions to the brief.Next steps
- Add technical indicators: Pull price bars from
/v1/market/barsand compute moving averages, RSI, or other signals. - Include peer comparison: Use
/v1/intelligence/securityfor multiple tickers to build a peer comparison table. - Automate distribution: Pipe the markdown report to a Slack channel, email, or Notion page.
- Schedule before earnings: Use the earnings calendar to automatically trigger preview generation 3 days before each report date.