Stock Analyst
1. Scaffold the staging views
Prompt the agent:
In stock-analyst/assets/, create three Bruin SQL assets for the staging layer. All should materialize as views (cheap, always fresh) with schema staging.
staging/fundamentals.sql → staging.fundamentals
- Source:
raw.fmp_fundamentals - Uppercase
symbol, castdateto DATE - Dedupe on (symbol, date) using
QUALIFY ROW_NUMBER() OVER (PARTITION BY symbol, date ORDER BY date DESC) = 1 - Pivot income-statement / balance-sheet / cash-flow rows into one row per (symbol, fiscal_quarter_end)
- Compute
free_cash_flow = operating_cash_flow - capital_expenditures - Keep: symbol, fiscal_quarter_end, revenue, gross_profit, operating_income, net_income, eps_diluted, operating_cash_flow, capital_expenditures, free_cash_flow, total_assets, total_liabilities, shareholders_equity
staging/prices.sql → staging.prices
- Source:
raw.yahoo_prices - Uppercase
symbol, castdateto DATE - Dedupe on (symbol, date)
- Compute
daily_return = (close - LAG(close) OVER (PARTITION BY symbol ORDER BY date)) / LAG(close) OVER (...) - Compute 20-day and 50-day simple moving averages of close
- Keep: symbol, date, open, high, low, close, adj_close, volume, daily_return, sma_20, sma_50
staging/macro.sql → staging.macro
- Source:
raw.fred_macro - Pivot so each date has columns:
fed_funds_rate(FEDFUNDS),cpi(CPIAUCSL),unemployment_rate(UNRATE),yield_spread_10y2y(T10Y2Y),real_gdp(GDPC1) - Forward-fill missing values (monthly/quarterly series need daily granularity) using
LAST_VALUE(... IGNORE NULLS) OVER (ORDER BY date)or equivalent - Add a
regimecolumn:CASE WHEN yield_spread_10y2y < 0 THEN 'inverted' ELSE 'normal' END
For each asset, add a top-level description:, column descriptions, and at least one quality check (e.g. not_null on symbol/date, unique on the grain columns).
Show me the SQL for each asset before writing the files. Don't run anything yet - I'll approve first.
Read each SQL file the agent produces. Look specifically for the QUALIFY, the dedup logic, and the pivot structure. If anything looks off, push back - it's cheaper to correct here than downstream.