Markets and Investing
Charts for a brokerage app, a fund's factsheet or a portfolio tracker: a market by sector, a price and its trend, a stock's days as candles, how far a fund fell from its high, a portfolio measured against what it could have held instead, and how asset classes move together. The companies, funds and indexes are made up. Where an example needs a long run of prices, a seeded random walk of a few lines makes it, so change its seed or its drift and the chart redraws with a new market.
The numbers on this page are made up to show the charts. They are not financial advice.
Prices and the Market
Sector Map
A made-up stock market's sectors, each tile sized by the sector's market cap and colored by how it moved today: green for up, red for down, a deeper shade for a move of 1% or more, and grey for no move at all. The change is written in each sector's name too, so the tile, its tooltip and the data table say it in words as well as in color. A tile too small for its name, as on a narrow screen, leaves it to the tooltip and the table.
function example() { const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', notation: 'compact', maximumFractionDigits: 1, }); const signed = new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 1, signDisplay: 'exceptZero', }); // Each sector's market cap, in dollars, and its move today. const sectors = [ { sector: 'Technology', cap: 5.3e12, move: 0.021 }, { sector: 'Financials', cap: 4.5e12, move: 0.004 }, { sector: 'Health Care', cap: 3.9e12, move: -0.012 }, { sector: 'Consumer', cap: 3.7e12, move: 0.009 }, { sector: 'Media', cap: 3.6e12, move: 0.015 }, { sector: 'Industry', cap: 3.4e12, move: -0.003 }, { sector: 'Staples', cap: 2.9e12, move: -0.007 }, { sector: 'Energy', cap: 2.2e12, move: -0.024 }, { sector: 'Utilities', cap: 2.0e12, move: 0 }, { sector: 'Property', cap: 1.8e12, move: -0.011 }, { sector: 'Mining', cap: 1.3e12, move: 0.006 }, ]; const colorOf = (move: number) => { if (move <= -0.01) return 'danger-50'; if (move < 0) return 'danger-75'; if (move === 0) return 'grey-light'; if (move < 0.01) return 'success-75'; return 'success-40'; }; return ( <Treemap label="Sectors by market cap, with today's move" description="Each tile is a sector, sized by its market cap. Green tiles rose today and red tiles fell, in a deeper shade for a move of 1% or more." data={sectors.map(({ sector, cap, move }) => ({ name: `${sector} ${signed.format(move)}`, value: cap, color: colorOf(move), }))} valueFormatter={value => dollars.format(value)} height={320} /> ); }
Price with Moving Averages
A year of daily closes for a made-up company, with its 50-day and 200-day moving averages. Lines suit a long daily series: the averages share the price's axis, so where one crosses another reads at a glance. Dashes tell the averages apart from the price and from each other, and a reference line marks the day the 50-day average crossed above the 200-day, worked out from the same rows. The example makes the months of closes before that year as well, since a 200-day average needs 200 closes behind its first point.
function example() { // mulberry32, a public-domain seeded random number generator by Tommy // Ettinger: the same seed draws the same prices on every render. function mulberry32(seed: number) { return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } const random = mulberry32(17); const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }); const dateOf = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeZone: 'UTC', }); // A close for each weekday, moving up to 2% either way with a small drift. const day = new Date('2025-01-01'); const dates: string[] = []; const closes: number[] = []; let price = 80; while (closes.length < 451) { day.setUTCDate(day.getUTCDate() + 1); if (day.getUTCDay() % 6 === 0) continue; // Saturday or Sunday price *= 1 + 0.0006 + (random() - 0.5) * 0.04; dates.push(dateOf.format(day)); closes.push(price); } const average = (end: number, length: number) => closes .slice(end - length + 1, end + 1) .reduce((sum, close) => sum + close, 0) / length; // The last year, from the first day with 200 closes behind it. const days = closes.slice(199).map((close, i) => ({ date: dates[i + 199], close, short: average(i + 199, 50), long: average(i + 199, 200), })); const cross = days.find( (row, i) => i > 0 && row.short > row.long && days[i - 1].short <= days[i - 1].long ); return ( <LineChart label="Quillfeather Instruments, daily close and moving averages" data={days} dataKey="date" series={[ { name: 'close', label: 'Close', color: 'link' }, { name: 'short', label: '50-day average', color: 'grey', strokeDasharray: '6 3', }, { name: 'long', label: '200-day average', color: 'danger-50', strokeDasharray: '2 2', }, ]} referenceLines={ cross ? [{ x: cross.date, label: '50-day crosses above' }] : [] } valueFormatter={value => dollars.format(value)} yAxisProps={{ domain: ['auto', 'auto'] }} hasDots={false} hasLegend /> ); }
Price with Volume
Three months of a made-up company's trading days as candles, with the shares traded in a pane under them. A candle shows a day's open, high, low and close at once, hollow for a day that closed up and filled for one that closed down, and the volume pane shows how much trading stood behind each move. On results day the stock opens well above the last close, a gap the candles leave open, on several times the usual volume, and a reference line marks the day.
function example() { // mulberry32, a public-domain seeded random number generator by Tommy // Ettinger: the same seed draws the same prices on every render. function mulberry32(seed: number) { return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } const random = mulberry32(21); const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', }); const compact = new Intl.NumberFormat('en-US', { notation: 'compact', maximumFractionDigits: 1, }); const dayName = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', timeZone: 'UTC', }); // About three months of weekdays. const dates: string[] = []; for ( const day = new Date('2026-03-01'); dates.length < 65; day.setUTCDate(day.getUTCDate() + 1) ) { if (day.getUTCDay() % 6 !== 0) dates.push(dayName.format(day)); } // Each day opens near the last close and moves up to 2.5% either way, // with a small upward drift, and a bigger move trades more shares. Results // day opens 6% higher on three times the volume. const resultsDay = 40; let close = 64; const days = dates.map((date, i) => { const results = i === resultsDay; const open = close * (results ? 1.06 : 1 + (random() - 0.5) * 0.01); close = open * (1 + (random() - 0.48) * 0.05); const move = Math.abs(close - open) / open; return { date, open, high: Math.max(open, close) * (1 + random() * 0.012), low: Math.min(open, close) * (1 - random() * 0.012), close, volume: Math.round( (300000 + random() * 300000) * (1 + move * 25) * (results ? 3 : 1) ), }; }); return ( <CandlestickChart label="Brindlewood Labs, three months of daily prices and volume" data={days} dataKey={{ x: 'date', open: 'open', high: 'high', low: 'low', close: 'close', volume: 'volume', }} referenceLines={[{ x: dates[resultsDay], label: 'Results' }]} valueFormatter={value => dollars.format(value)} volumeValueFormatter={value => compact.format(value)} volumeHeight="30%" xAxisProps={{ minTickGap: 24 }} height={360} /> ); }
Drawdown
Three years of a made-up fund, each week drawn as how far it stood below its highest close so far,
so the chart sits at zero on a new high and dips below it as the fund falls. An area under zero
reads as how deep and how long each fall went, which a price chart hides in its ups and downs. A
reference line marks the deepest point, and a shaded band spans the fall it belongs to, from the
high before it to the week the fund got back there. The band is a Recharts ReferenceArea, passed
as a child, since the chart's own referenceLines draw lines rather than spans.
import { ReferenceArea } from 'recharts'; function example() { // mulberry32, a public-domain seeded random number generator by Tommy // Ettinger: the same seed draws the same prices on every render. function mulberry32(seed: number) { return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } const random = mulberry32(54); const percent = new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 1, }); const dateOf = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium', timeZone: 'UTC', }); // A price each Friday, and how far it is below the highest one so far. let price = 100; let peak = price; const weeks = Array.from({ length: 157 }, (_, week) => { if (week > 0) price *= 1 + 0.002 + (random() - 0.5) * 0.09; peak = Math.max(peak, price); return { date: dateOf.format(Date.UTC(2023, 0, 6 + week * 7)), drawdown: price / peak - 1, }; }); const worst = Math.min(...weeks.map(week => week.drawdown)); // The deepest fall runs from the last high up to its worst week to the // next new high after it, or to the end while the fund is still below. const bottom = weeks.findIndex(week => week.drawdown === worst); const highs = weeks.map(week => week.drawdown === 0); const start = highs.lastIndexOf(true, bottom); const back = highs.indexOf(true, bottom); const end = back === -1 ? weeks.length - 1 : back; return ( <AreaChart label="Thistledown Growth Fund, below its last high" description={`The fund's worst week stood ${percent.format(-worst)} below its high.`} data={weeks} dataKey="date" series={[{ name: 'drawdown', label: 'Below its high', color: 'danger' }]} referenceLines={[{ y: worst, label: `Worst: ${percent.format(worst)}` }]} valueFormatter={value => percent.format(value)} hasGradient={false} fillOpacity={0.3} > <ReferenceArea x1={weeks[start].date} x2={weeks[end].date} fill="var(--bulma-text)" fillOpacity={0.08} label={{ value: 'Deepest fall', position: 'insideTop', fill: 'var(--bulma-text)', fontSize: 12, }} /> </AreaChart> ); }
Portfolios and Funds
Portfolio Against Benchmark
Five years of a made-up portfolio beside the index it measures itself against, as two lines on one axis so the gap between them reads month by month. Both are indexed to 100 at the start, so 150 means half as much again whatever either was worth, and the reference line at 100 shows when either was below where it began. This portfolio holds bonds beside its stocks, so it fell less than the index in the first year's slump and trailed it in the rally after.
function example() { // mulberry32, a public-domain seeded random number generator by Tommy // Ettinger: the same seed draws the same prices on every render. function mulberry32(seed: number) { return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } const random = mulberry32(319); const monthOf = new Intl.DateTimeFormat('en-US', { month: 'short', year: 'numeric', timeZone: 'UTC', }); // Each month the market moves, and the portfolio, which holds bonds as // well as stocks, follows part of the way, plus moves of its own. let portfolio = 100; let benchmark = 100; const months = Array.from({ length: 61 }, (_, month) => { if (month > 0) { const market = (random() - 0.5) * 0.12; benchmark *= 1 + 0.007 + market; portfolio *= 1 + 0.006 + market * 0.6 + (random() - 0.5) * 0.02; } return { month: monthOf.format(Date.UTC(2021, month, 1)), portfolio: Math.round(portfolio * 10) / 10, benchmark: Math.round(benchmark * 10) / 10, }; }); return ( <LineChart label="A portfolio against its benchmark, both starting at 100" data={months} dataKey="month" series={[ { name: 'portfolio', label: 'Portfolio', color: 'primary' }, { name: 'benchmark', label: 'Saltmarsh All-Market Index', color: 'grey', strokeDasharray: '5 5', }, ]} referenceLines={[{ y: 100, label: 'Start' }]} yAxisProps={{ domain: ['auto', 'auto'], tickCount: 6 }} hasDots={false} hasLegend /> ); }
Allocation
A three-fund portfolio as a donut, with the total in the middle where a pie would have its center.
The labels give each fund's share and the tooltip its amount. The center text is drawn only, so
the chart's description says the total for a screen reader.
function example() { const dollars = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0, }); const holdings = [ { name: 'Fernhollow Total Market Fund', value: 84600, color: 'primary' }, { name: 'Fernhollow International Fund', value: 37200, color: 'link' }, { name: 'Fernhollow Bond Fund', value: 28200, color: 'info' }, ]; const total = holdings.reduce((sum, holding) => sum + holding.value, 0); return ( <PieChart label="A three-fund portfolio" description={`${dollars.format(total)} in all.`} data={holdings} isDonut centerLabel={dollars.format(total)} valueFormatter={value => dollars.format(value)} showLabels labelsType="percent" labelsPosition="inside" hasLegend height={320} /> ); }
Asset Correlations
How closely the made-up returns of a spread of asset classes have moved together, from 1, always in step, to -1, always opposite. A heatmap lays every pair out as one cell of a grid, so the blocks that move together stand out at a glance: the stock markets with each other, and the two kinds of bonds. A diverging scale keeps zero pale and colors the two directions apart, and each cell writes its value, since a correlation matrix is hard to read by color alone. The grid is symmetric, each pair appearing on both sides of the diagonal of ones. On a narrow screen the cells are too small for their values and the axis leaves out the column names that don't fit, so the grid shows color alone there, and the tooltip and the data table give each cell's pair and value.
function example() { const assets = [ 'US stocks', 'Intl stocks', 'Emerging', 'Property', 'Commodities', 'Gold', 'Corp bonds', 'Treasuries', ]; // Each asset's correlation with the ones listed before it, so each pair // is written once. const before = [ [], [0.85], [0.72, 0.82], [0.7, 0.62, 0.55], [0.35, 0.42, 0.5, 0.3], [0.05, 0.15, 0.25, 0.1, 0.4], [0.3, 0.28, 0.25, 0.45, 0.05, 0.2], [-0.25, -0.2, -0.15, 0.05, -0.25, 0.3, 0.7], ]; const cells = assets.flatMap((row, r) => assets.map((column, c) => ({ row, column, r: r === c ? 1 : r > c ? before[r][c] : before[c][r], })) ); return ( <Heatmap label="Correlations between made-up asset class returns" data={cells} dataKey={{ x: 'column', y: 'row', value: 'r' }} colorScale="diverging" domain={[-1, 1]} valueLabel="Correlation" valueFormatter={value => value.toFixed(2)} showLabels height={420} /> ); }
Risk Against Return
Made-up funds, each a point placed by how much its price swings in a year, its volatility, and what it returned. A scatter puts every fund on both measures at once, so the trade between them shows as the slope of the cloud: funds that swing more tend to return more, and spread wider, and a point below its neighbors is a fund that took the risk without the reward. Each kind of fund has its own shape as well as its own color, and the tooltip names the fund.
function example() { // mulberry32, a public-domain seeded random number generator by Tommy // Ettinger: the same seed places the same funds on every render. function mulberry32(seed: number) { return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; }; } const random = mulberry32(8); const families = [ 'Copperwick', 'Fernhollow', 'Marrowfield', 'Quillfeather', 'Saltmarsh', ]; const kinds = [ { name: 'Bond', risk: 4, color: 'info', shape: 'circle' }, { name: 'Balanced', risk: 9, color: 'success', shape: 'square' }, { name: 'Stock', risk: 15, color: 'link', shape: 'triangle' }, { name: 'Small-Cap', risk: 21, color: 'danger', shape: 'diamond' }, ] as const; const round = (value: number) => Math.round(value * 10) / 10; return ( <ScatterChart label="Funds by yearly volatility and return" dataKey={{ x: 'volatility', y: 'yearly' }} nameKey="fund" series={kinds.map(kind => ({ name: kind.name, label: `${kind.name} funds`, color: kind.color, shape: kind.shape, // Each fund swings near its kind's risk, and returns about a third // of it on top of 1.5%, give or take more the more it swings. data: families.map(family => { const volatility = kind.risk + (random() - 0.5) * 5; const luck = (random() - 0.5) * volatility * 0.5; return { fund: `${family} ${kind.name} Fund`, volatility: round(volatility), yearly: round(1.5 + volatility * 0.35 + luck), }; }), }))} xAxisLabel="Volatility" yAxisLabel="Return" xUnit="%" unit="%" hasLegend height={340} /> ); }