Portfolio kit
Return and risk metrics of a book, the benchmark and underwater curves, allocation views, the monthly heatmap and the four risk figures.
@unifin/chart-kit-portfolio owns the performance and risk maths of a portfolio and the painters of
the views a portfolio surface shows.
import { periodReturns, maxDrawdown, sharpeRatio, sortinoRatio, beta } from '@unifin/chart-kit-portfolio';
const daily = periodReturns(portfolioValues);
maxDrawdown(portfolioValues); // worst peak-to-trough decline
sharpeRatio(daily); // annualised, 252 periods
sortinoRatio(daily); // the same on downside deviation
beta(daily, benchmarkReturns); // sensitivity to the benchmarkWhat the kit renders
| View | Function | Reads |
|---|---|---|
| Benchmark curves | benchmarkCurves + paintBenchmarkCurves | portfolio and benchmark values; the curve is indexed to 100 at the first point |
| Underwater | drawdownSeries + paintUnderwater | the same values; every point is a percent below the running peak |
| Allocation | allocationShares + treemapRects / paintTreemap, paintAllocationDonut, paintStackedBar | weights per instrument; the treemap is drawn by the kit, the donut and the stacked bar are alternatives |
| Monthly heatmap | monthlyGrid + paintReturnsHeatmap | monthly returns; rows are years, columns are months, growth and fall tones come from the theme |
| Positions table | buildPositionRows + POSITION_COLUMNS | quantity, value, weight, profit and profit percent per position |
Live curves, allocation and heatmap

The S105 wave ramps the fills: the underwater band is dense at the zero line and fades into the depth (0.28 -> 0.06), the portfolio curve of the benchmark frame gets a ribbon down to its baseline (0.16 -> 0.02), and every allocation shape - treemap cell, stacked bar slice and donut ring - carries one vertical ramp (0.42 -> 0.25) with a light 1 px edge. The fills are additive options of the kit painters; on a canvas without gradients every shape keeps its flat tone.

Risk figures
Four figures answer where the risk of a book comes from. They reuse the analytic family of the core - the correlogram is the shared heatmap with the diverging tone, the cone is the fan chart - so no figure ships its own painter.
| Figure | Function | Reads |
|---|---|---|
| Correlogram | correlationGrid + paintCorrelationMatrix | a labelled correlation matrix; the diagonal is forced to 1, out-of-range values are clamped and the upper triangle wins |
| Risk decomposition | riskContributions + paintRiskDecomposition | weights and a covariance matrix; the contributions are the Euler decomposition of the variance and add up to one |
| Scenario cone | monteCarloCone + paintMonteCarloCone | a spec with a seed; the same seed always yields the same cone and the bands are nested |
| Attribution | attributionRows | the steps of a performance bridge; the rows share the base arithmetic of the waterfall |
import { correlationGrid, riskContributions, monteCarloCone } from '@unifin/chart-kit-portfolio';
correlationGrid(['AAPL', 'GLD'], correlations); // diverging heatmap grid
riskContributions([0.6, 0.4], covariance); // shares that add up to one
monteCarloCone({ start: 100, drift: 0.0006, volatility: 0.013, steps: 120, seed: 11 });The cone also has a worker form: monteCarloJob builds a flat payload, monteCarloJobTransferables
lists the buffers to transfer and coneFromJob rebuilds the bands on the receiving side, so a long
simulation can leave the main thread without changing the numbers.
The screener
The portfolio monitoring board builds its rows from the same positions: market value, weight and profit, with the lots of every position behind a chevron and the P&L colours coming from the kit tones. The locale switch moves the grouping and the decimal separator, the precision stays declared.
| KEGC | 9 | 12,438.00 | 45.2% | -612.00 | -4.69% | |
| BAC | 40 | 6,984.00 | 25.4% | 256.00 | 3.80% | |
| RDGR | 60 | 5,124.00 | 18.6% | -222.00 | -4.15% | |
| KZAP | 6 | 1,629.00 | 5.9% | 21.00 | 1.31% | |
| AAPL | 12 | 1,354.80 | 4.9% | 102.00 | 8.14% |
import { POSITION_COLUMNS, buildPositionRows } from '@unifin/chart-kit-portfolio';
import { filterTableRows, sortTableRows } from '@unifin/chart-core';
const rows = buildPositionRows(positions); // market value, cost, P&L, P&L %, weight
const sorted = sortTableRows(rows, POSITION_COLUMNS, { key: 'pnl', direction: 'desc' });
const top = filterTableRows(sorted, POSITION_COLUMNS, 'AAPL');The correlation terrain in 3D
The correlation matrix behind the correlogram also reads as a terrain: every pair of asset classes
lifts a ridge by its coefficient, the pairs above the ridge threshold carry a warn stroke and the
deep negatives mark pockets in the down tone. The same drag, wheel and keyboard controls steer the
camera, the reset button and the two angle presets restore the canonical views, and
prefers-reduced-motion keeps the frame static while the controls stay live. The S105 frame sheen
washes the whole scene once with a single diagonal pass - never per cell.

import { correlationTerrainModel, paintCorrelationTerrain } from '@unifin/chart-kit-portfolio/formats';
import { scene3dCamera } from '@unifin/chart-core/scene3d';
const terrain = correlationTerrainModel({ labels, matrix });
paintCorrelationTerrain(ctx, terrain, { width, height, theme, camera: scene3dCamera() });The kit reference is the Portfolio kit API; the camera is part of the core API.
See also
- Portfolio kit API - every exported symbol.
- Table kit - the row journal and the group totals a position table can carry.
- Analytics kits - all four kits and the table kit.
Fixed income kit
Yield and price maths for bonds, duration and convexity, accrued interest, the yield curve with spreads, the maturity ladder and the coupon timeline.
Swaps kit
The accrual schedule of both legs, forward rates from a discount curve, present value, the par swap rate and the painters of the ladder, the net flows and the cumulative PV curve.
