LP risk canvas

Open-source charting engine

LP risk canvas

One position with its risks on one chart. A concentrated-liquidity range is a band from the entry bar; a 10x short hedge has price lines for its entry and its liquidation. The opens, every exit and return of the range and, if the price gets there, the liquidation are atPrice markers at the exact price. The second pane shows the position against holding the tokens (impermanent loss) and the hedged P&L, before fees: a short of the starting ETH leaves about the impermanent loss.

Apache-2.0

LP risk canvas: DeFi & AMMs example

position: 'atPrice' · addBand · createPriceLine · addSeries('baseline')

Code
import { FerroChart } from '@ferrochart/core';

const canvas = document.querySelector('canvas');
// Market data: the synthetic FerroChart demo API. Use your own feed.
const chart = await FerroChart.create(canvas, { theme: 'dark' });
const bars = await fetch('/api/bars?symbol=ETHUSD&interval=1h&count=720').then((r) => r.json());
const candles = chart.addCandlestickSeries();
candles.setData(bars);
const n = bars.time.length;
// An ETH/USDC concentrated-liquidity position opened 12 days ago, ±8% around
// the entry, hedged two hours later with a 10x short of its ETH.
const entry = n - 288, p0 = bars.close[entry], pa = p0 * 0.92, pb = p0 * 1.08;
const amounts = (p) => { // ETH and USDC of one unit of liquidity at price p
  const s = Math.sqrt(Math.min(Math.max(p, pa), pb));
  return [1 / s - 1 / Math.sqrt(pb), s - Math.sqrt(pa)];
};
const [x0, y0] = amounts(p0);
const hedgeAt = entry + 2, ph = bars.close[hedgeAt], margin = (x0 * ph) / 10;
const liq = ph * (1 + 1 / 10 - 0.005); // maintenance margin 0.5%
// The range as a band from the entry bar; the short's entry and liquidation as price lines.
const edge = (price) => bars.time.map((t, i) => (i < entry ? NaN : price));
const style = { color: '#7ee787', lineWidth: 1, lineStyle: 'dashed', priceLineVisible: false, lastValueVisible: false };
const hi = chart.addSeries('line', style), lo = chart.addSeries('line', style);
hi.setData({ time: bars.time, value: edge(pb) });
lo.setData({ time: bars.time, value: edge(pa) });
chart.addBand(hi, lo, { fill: 'rgba(126, 231, 135, 0.08)' });
candles.createPriceLine({ price: ph, color: '#b388ff', title: 'short entry' });
candles.createPriceLine({ price: liq, color: '#ff5d73', lineStyle: 'solid', lineWidth: 2, title: 'short liquidation' });
// Events at the price they happened: the opens, the range exits and returns, a liquidation.
const at = (i, price, color, text) => ({ time: bars.time[i], position: 'atPrice', price, shape: 'circle', size: 9, color, text });
const markers = [at(entry, p0, '#7ee787', 'LP open'), at(hedgeAt, ph, '#b388ff', 'short')];
const lp = [], net = [];
let zone = 0, streak = 0, liquidated = false; // zone: -1 below the range, 0 in it, 1 above
for (let i = 0; i < n; i++) {
  if (i < entry) { lp.push(NaN); net.push(NaN); continue; }
  const p = bars.close[i], [x, y] = amounts(p);
  if (i >= hedgeAt && !liquidated && bars.high[i] >= liq) { liquidated = true; markers.push(at(i, liq, '#ff5d73', 'liquidated')); }
  const now = p > pb ? 1 : p < pa ? -1 : 0;
  streak = now === zone ? 0 : streak + 1; // a new zone counts after 12 closes
  if (streak === 12) {
    const j = i - 11, edge = (now || zone) > 0 ? pb : pa;
    markers.push(now ? at(j, edge, '#ffb547', 'out of range') : at(j, edge, '#2ee6b6', 'back in range'));
    zone = now;
    streak = 0;
  }
  const hedge = i < hedgeAt ? 0 : liquidated ? -margin : x0 * (ph - p);
  lp.push(((x * p + y) / (x0 * p + y0) - 1) * 100); // against holding the tokens
  net.push(((x * p + y + hedge) / (x0 * p0 + y0) - 1) * 100); // LP and short, of the capital
}
candles.setMarkers(markers.sort((a, b) => a.time - b.time));
// Second pane: what the position earns, before fees.
const pane = chart.addPane(0.5);
chart.addSeries('baseline', { baseValue: 0, color: '#2ee6b6', downColor: '#ff5d73', topFill: 'rgba(46, 230, 182, 0.2)', bottomFill: 'rgba(255, 93, 115, 0.2)', pricePrecision: 2 }, pane)
  .setData({ time: bars.time, value: net });
chart.addSeries('line', { color: '#ffb547', lineWidth: 1.5, pricePrecision: 2 }, pane).setData({ time: bars.time, value: lp });
chart.applyPriceScaleOptions({ margins: { top: 0.22, bottom: 0.05 } }, pane);
chart.addLayer({ pane, build: (ctx) => [
  { type: 'text', x: ctx.rect.x + 8, y: ctx.rect.y + 6, text: 'LP + short, % of capital', color: '#2ee6b6', size: 11 },
  { type: 'text', x: ctx.rect.x + 8, y: ctx.rect.y + 22, text: 'LP vs holding (impermanent loss), %', color: '#ffb547', size: 11 },
] });
chart.setVisibleLogicalRange(entry - 40, n + 4);

Built for tick-level data.

Apple M4 Max · Chrome + WebGPU

Load 1 million bars and draw the first frame in the browser

WASM · WebGPU

Load 10 million bars natively, level-of-detail pyramid included

native Rust

Heap allocations per frame while panning, zooming and streaming

steady state

WebAssembly package size, gzip

all features

Browser figures: Google Chrome with WebGPU; the 10 million bar load is native Rust. Bars show each figure against its target: 300 ms for a load, no allocations, 1.5 MB for the package.

Examples

313 examples
across 20 use cases.

Each example is a live chart rendered by FerroChart in your browser, with its source code alongside. All data is synthetic.

Bar replay
Real-time stream
Candlesticks + volume
01

Price action

25 examples →

Candles, bars and lines for any market, streaming in real time.

Depth heatmap
Delta footprint
Footprint
04

Order flow

20 examples →

Footprint, depth heatmap and market profile, on a compute-shader path.

Implied volatility · basis
Long/short ratio · CVD
Funding · open interest · liquidations
06

Crypto derivatives

15 examples →

Funding, open interest, liquidations and basis in panes under price.

Risk reversal · butterfly
Expected move to expiry
Implied vs realised vol · IV rank
12

Options & volatility

18 examples →

Implied against realised, skew, expected moves and dealer exposure in time.

Joint drawdowns
Underwater curve · worst drawdown
Equity curve · drawdown
16

Portfolio, risk & quant

24 examples →

Equity curves, drawdowns, rolling statistics, factor research and risk checks.

Grouped columns
Stacked columns
100% stacked area
19

Custom series & plugins

11 examples →

Stacked, grouped, box and brushed series: layer plugins on the same GPU frame.

Browse all 20 use cases

Price action

Bar types & transforms

Technical analysis

Order flow

Execution & trade review

Crypto derivatives

On-chain

DeFi & AMMs

Memecoins & wallets

Equities & fundamentals

China A-shares

Options & volatility

Rates, FX & macro

Futures & commodities

Funds & ETFs

Portfolio, risk & quant

Private markets & personal finance

Prediction markets

Custom series & plugins

Labs & flagships

Features

Designed for market data.

01

Cross-platform rendering

A single Rust core with WebGPU and WebGL2 backends in the browser, wgpu on Metal, Vulkan and DirectX 12 in native applications, and a CPU renderer for servers. Golden-image tests keep the backends consistent.

02

Performance independent of data size

Bar data stays on the GPU and coordinate transforms run in shaders, so panning and zooming update only a few uniforms. A level-of-detail pyramid keeps tens of millions of bars responsive.

03

30 built-in indicators

Moving averages, channels and oscillators from SMA to Ichimoku. Values are updated incrementally on each tick and tested against reference data.

04

29 drawing tools

Trend lines, channels, Fibonacci tools, pitchforks, Gann fans, patterns, Elliott waves, ranges, positions and text, with undo and redo. Drawings and chart state serialize to JSON.

05

Synchronized charts

Sync groups link the crosshair and the visible range across multiple charts.

06

Extensible

Plugin interfaces for custom series, layers and drawing tools. Bindings for JavaScript, Rust and Python, and a C ABI for C#, C++, Qt and Flutter.

Get started

One API in every language.

Every binding follows the same model: create a chart, add series, set data and add indicators. Data is passed as columns, from typed arrays, Rust slices or DataFrames.

  • JavaScript & TypeScript
  • Rust
  • Python & Jupyter
  • C, C#, C++
Read the documentation
main.js
$ npm install @ferrochart/core
import { FerroChart } from '@ferrochart/core';

const chart = await FerroChart.create(canvas, { theme: 'dark' });
const candles = chart.addCandlestickSeries();
chart.addVolumeSeries(candles);
candles.setData(bars); // [{ time, open, high, low, close, volume }, ...]
chart.addIndicator(candles, 'ema', { n: 20 });
chart.addIndicator(candles, 'macd'); // in a new pane

FerroChart

Every market.
Every screen.
One engine.

Open source under Apache-2.0, from the browser to the trading desk.