Intermediate
15 min
Build a Local AI Data Analyst for the Stock Market
Create an AI data analyst for stock and financial data using Claude Code, Bruin CLI and BigQuery — all running locally on your machine.
AIBruin CLIBigQueryMCPClaude Code
Learning paths:Data AnalystData Engineer
Overview
Goal — Create an AI data analyst for stock and financial data using Claude Code, Bruin CLI and BigQuery.
Audience — Data professionals, hobbyists, and financial analysts who want to build a local AI analyst.
Prerequisites
- BigQuery project and dataset with data already loaded
- gcloud CLI installed
- Bruin CLI installed
- Claude Code installed
- Bruin MCP added to Claude Code (setup video)
High-level flow
bruin init emptyand remove the default SQL asset.- Authenticate to BigQuery with gcloud.
- Add and test a BigQuery connection in Bruin.
- Import database metadata to create source assets.
- Enhance metadata with
bruin ai enhance. - Ask a real analysis question.
Steps
1) Initialize pipeline
- Run
bruin init empty sp500or select the empty template and name the foldersp500. - Remove the placeholder asset or any other empty placeholder files (e.g.
rm sp500/assets/empty.sql)
2) Authenticate to BigQuery
- Run
gcloud auth login.
3) Add and test a BigQuery connection
- List existing connections:
bruin connections list. - Add a new connection:
bruin connections add.- Set environment:
default. - Set name:
gcp-default. - Choose google_cloud_platform connection and provide credentials. See BigQuery connection options.
- Provide a service account file, or set
use_application_default_credentialsto true to usegcloud auth login. - If prompted to set as default, answer
true.
- Set environment:
- Test the connection:
bruin connections test --name gcp-default --env default.
4) Import database metadata
- Run
bruin import database sp500 --connection gcp-default --schema stock_market.
5) Enhance asset metadata
- Run
bruin ai enhance sp500/using Claude Code.
6) Ask the analysis question
- Prompt: "Which companies had their free cash flow margin improve in the past 4 quarters but saw their stock price decrease more than 10% during the same period?"
- Ensure the agent uses
bruin queryfor data access and returns a table or chart.
Sample outputs
- The analysis prompt and a summary of results.
- A simple table or chart output.
Troubleshooting
- Common BigQuery permission issues.
- Bruin connection errors or missing credentials.
- AI CLI authentication errors for
bruin ai enhance.
