Automated investment portfolio system built on n8n

A fully automated personal investment analytics system built entirely in n8n — from parsing raw broker reports through to live FIFO portfolio valuations, yield dashboards, multi-account support, an AI voice assistant via Telegram, and a scheduled news digest from 10 international sources.

  • 16n8n workflows
  • FIFOPosition accounting
  • Every 6hPortfolio refresh
  • 10News sources
Automated investment portfolio system built on n8n

Context

Spreadsheets and manual broker reports were no longer enough

Managing an active investment portfolio across multiple accounts — stocks, bonds, dividends, cash flows — requires constant data work: downloading broker reports, cross-referencing positions with live prices, calculating average buy prices with FIFO, and tracking yields. Done manually, this takes hours per week. The goal was to eliminate all of that with a fully automated pipeline that stays accurate, deduplicated, and always up to date.

Challenge

Broker reports are HTML, prices are APIs, and data must never duplicate

Broker statement files arrive as unstructured HTML — multiple embedded tables per file, different formats for trades versus cash flow versus income payments. Live prices come from a separate market data API in a column-array format that needs custom parsing. FIFO accounting across buy and sell events requires stateful calculation logic. And because workflows run on a schedule, every database write had to be idempotent — no duplicate records regardless of how many times a pipeline re-runs.

Solution

A pipeline system covering every layer of the investment workflow

16 n8n workflows were designed as a layered system: ingestion, calculation, enrichment, and delivery. Each layer is independently schedulable, idempotent, and writes to a shared PostgreSQL database.

Broker report ingestion

Scheduled workflow pulls HTML reports from Google Drive, splits them into three parallel parsing branches — trades, cash flow, and income payments — then extracts each table using CSS selectors and custom JavaScript parsers. All records are upserted with hash-based deduplication, handling split-adjusted quantities automatically.

FIFO portfolio valuation

Every 6 hours: live prices are fetched from the market data API, merged with trade history from PostgreSQL, and position values are recalculated using a JavaScript FIFO queue per ticker. Shares and bonds use separate calculation branches (bonds use face-value normalisation). Results are upserted into the portfolio table.

Yield, multi-account & Metabase dashboards

Separate workflows compute dividend yield and bond yield to maturity across positions. A second account (tax-advantaged) is handled by a parallel set of identical pipelines feeding into a unified aggregated view. All collected data is visualised in Metabase — portfolio value, yield per position, cash flow history, and income payments — connected directly to the PostgreSQL database populated by n8n.

AI assistant & news digest

A Telegram bot accepts voice messages, transcribes via Whisper, and replies with GPT-4.1-mini responses. A separate scheduled workflow aggregates 10 international RSS feeds (BBC, DW, Al Jazeera, France24, NY Times, NPR and others) every 3 hours for a curated news digest.

Engineering approach

How it was built

01

Data model

Designed the PostgreSQL schema: broker_trades, cash_operations, broker_cash_flow, portfolio tables. Defined idempotency strategy — hash keys for cash events, deal numbers for trades, ticker as upsert key for portfolio.

02

Report parsing

Built the HTML ingestion pipeline. Wrote custom JavaScript parsers for each table type, handling varied column counts, date formats, and encoding. Added stock split correction logic (ratio-adjusted quantity and price per ticker).

03

FIFO engine

Implemented FIFO queue logic in n8n Code nodes — separate implementations for shares (unit price) and bonds (face-value normalised). Handles partial sells, remaining quantity tracking, and yield percentage calculation.

04

AI & delivery layer

Connected Telegram webhook, Whisper transcription, and GPT-4.1-mini for the voice assistant. Built the news aggregation pipeline across 10 RSS sources with parallel fetching and scheduled delivery.

Results

Measured impact

  • 16Active workflows
  • 0Hours of manual data work/week
  • 6hMax portfolio staleness
  • 2Accounts tracked
  • 10News sources aggregated

Technology

Stack & capabilities

  • n8n
  • PostgreSQL
  • Metabase
  • Google Drive API
  • OpenAI Whisper
  • GPT-4.1-mini
  • Telegram Bot API
  • RSS
  • JavaScript
  • HTML parsing

Facing a similar challenge?

Start a project