Interactive Brokers Portfolio Tracker: Returns, Risk, Setup
An Interactive Brokers portfolio tracker takes the raw record IBKR keeps of your account — every trade, dividend and tax deduction — and turns it into the answers a long-term investor actually wants: how the portfolio has done against the market, how much risk it carried, and where the return came from. The cleanest way to feed one is a Flex Query read through IBKR’s Flex Web Service, which is read-only by design. This guide covers why the statements alone are hard work, what a tracker should get right, and how the connection is set up.
Why IBKR’s own statements are hard to read as an investor
Interactive Brokers’ reporting is thorough, and that is the point of it. A broker serving active traders, professionals and accountants in many markets has to record everything: each execution of an order, each currency conversion, each commission and fee, each dividend with its withholding tax on a separate line, each corporate action. A statement built for completeness is exactly what a tax return or an audit needs.
It is not what a long-term investor needs on a Sunday evening. The questions are simpler and the statement does not answer them directly: am I beating an index fund? how deep was the worst fall? which three holdings made most of the money? are my positions really different bets? Getting there from a statement means exporting, cleaning and re-adding lines in a spreadsheet — and doing it again next quarter.
What a tracker should get right with IBKR data
A short checklist, whichever tool you use:
- Read-only access. The tracker should never hold a credential that can place an order or move money. A Flex Query can only report, which makes it the right way in.
- Orders, not executions. One order filled in five pieces is one decision. A tracker that counts it as five trades distorts your turnover and makes transactions harder to audit.
- Dividends with their tax. A dividend and the tax withheld from it should arrive together, along with payments in lieu of dividends on lent shares.
- Currencies handled for you. If you buy US shares from a euro or sterling account, every figure should be converted into one base currency, not added across currencies.
- Duplicates recognised by the broker’s own ids. A trade that arrives twice — from a sync and from a file — should be one trade.
- Honesty about history. A tracker that silently starts last year will give you a return that is not yours. Know how far back it can read.
- Measures that need a whole history — CAGR, max drawdown, a Sharpe ratio and comparison with a benchmark — computed the same way every time.
How the connection works: a Flex Query and a token
Lemma Analysis connects Interactive Brokers through two values from Client Portal: a Flex Web Service token and a Flex Query ID. The query is a report template you build once; the token lets our servers ask IBKR to run it. Neither can trade. In outline:
- In Client Portal, under Performance & Reports → Flex Queries, create an Activity Flex Query with exactly two sections: Trades and Cash Transactions.
- Under Trades, choose Order rather than Execution, for the reason above. Under Cash Transactions keep Dividends, Payment in Lieu of Dividends and Withholding Tax, and choose the Detail level rather than Summary.
- Deliver it as XML over Last 365 Calendar Days, then save and read its Query ID from the round blue i beside it — not your account number, which starts with a U.
- Under Flex Web Service → Configure, enable the service, choose the longest token expiration (one year), leave IP restriction empty — the requests come from our servers, not your device — and generate the token. Write the expiry date down.
The connect dialog in the app spells out every section, option and field to tick, in the words Client Portal prints beside them, and a query missing a required section or field is refused by name when you connect. The token is stored encrypted, never shown again, and deleted when you disconnect; the transactions it imported stay. More on what we hold is on the security page.
The 365-day limit, and how to bring in older years
One limit is worth knowing before you start. A Flex Query reaches back at most 365 days, and the Flex Web Service takes no dates from the caller, so a connection can never read further back than the period of your query. Trades from earlier years will not arrive by themselves.
They can still come in, as files. Export an Activity Statement as CSV from Client Portal for each earlier year and load it through the import wizard, which recognises the Interactive Brokers (Activity Statement) format; the CSV import guide walks through it. Keep those files to the years before the connection’s window: a file row is matched against what is already there by its details rather than by IBKR’s own ids, so the connection should own the most recent year.
Token expiry and the nightly sync
A Flex token lives as long as you chose when you generated it, and nothing reports that date afterwards — not the statement, not an error, until the day it stops working. So the connect dialog asks for the Token expiry. With a date recorded, the connection shows it calmly, switches to a Key expires soon chip thirty days before, and to Key expired after the day. Renewing is the same errand each time: generate a new token in Client Portal, then disconnect the account and connect it again.
Once connected, the account syncs itself every night, and the row counts down to the next sync. Run now starts one at once, but it rarely helps on the day of a trade: a broker’s statement is written after the market closes, so a trade made today arrives in the sync after that. If IBKR rejects the token the row says Key rejected and stops; if a run fails for any other reason it says Sync failed and the token is still good.
What you see once IBKR is connected
The transactions land in a portfolio of your choice, and the portfolio tracker does the bookkeeping: holdings with average cost and profit, a money-weighted XIRR, upcoming dividends, drift against your sector targets, and each position’s contribution to return. The portfolio analytics board then answers the investor’s questions from the first section:
- Portfolio performance vs SPY — your curve against the S&P 500 ETF over the window you choose.
- Headline numbers since inception — CAGR, Sharpe, Sortino, max drawdown, beta vs SPY, alpha, tracking error and win rate.
- Correlation matrix and Factor exposures — whether your holdings are different bets or one bet in several correlated tickers.
- Top drawdowns and Monthly returns — the worst falls, and the record month by month.
Why the board’s return and XIRR can differ for the same year is explained in time-weighted vs money-weighted return.
Broker connections, the import wizard and the analytics board are part of the Ultimate plan, and every new account gets Ultimate for seven days once its email address is confirmed, with no card — enough to connect IBKR and see the board on your own history. The connection lives in Settings → Connected accounts (step by step in the broker connection guide), beside Trading 212, the other broker that can be connected; Revolut, Degiro, XTB and Freedom24 come in through a file instead. On the free plan you can still track a portfolio by entering transactions yourself, within the free plan’s limits.
Educational only. Not investment advice.
Lemma Analysis gives independent investors both lenses in one terminal — a stock screener and an intrinsic value tool for the fundamentals, alongside price history and charts for timing.