历史相似走势

开源图表引擎

历史相似走势

在历史中搜索与最近 60 根 K 线相关性最高的 60 根窗口,缩放后以琥珀色线叠加在最后几根 K 线上,并延伸到未来,显示当时随后的走势。图层插件为匹配窗口加阴影并标注匹配项。这只是相似走势搜索的演示,并非预测。

Apache-2.0

历史相似走势:技术分析示例

addLayer · addSeries('line') · future times

代码
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=BTCUSD&interval=4h&count=2000').then((r) => r.json());
chart.addCandlestickSeries().setData(bars);
// Find the past window whose shape best matches the last 60 bars (correlation of log prices).
const m = 60, ahead = 40, n = bars.time.length;
const logs = bars.close.map(Math.log);
const corr = (a, b) => {
  const ma = a.reduce((s, v) => s + v) / a.length, mb = b.reduce((s, v) => s + v) / b.length;
  let ab = 0, aa = 0, bb = 0;
  a.forEach((v, i) => { ab += (v - ma) * (b[i] - mb); aa += (v - ma) ** 2; bb += (b[i] - mb) ** 2; });
  return ab / Math.sqrt(aa * bb);
};
const now = logs.slice(n - m);
let best = { r: -1, end: 0 };
for (let end = m; end < n - m - ahead; end++) {
  const r = corr(logs.slice(end - m, end), now);
  if (r > best.r) best = { r, end };
}
// The match and what followed it, scaled to today's price: over the last 60 bars, then past them.
const step = bars.time[n - 1] - bars.time[n - 2];
const scale = bars.close[n - 1] / bars.close[best.end - 1];
const k = Array.from({ length: m + ahead }, (_, j) => j - m + 1);
chart.addSeries('line', { color: '#ffb547', lineWidth: 2, lastValueVisible: false, priceLineVisible: false }).setData({
  time: k.map((j) => (j <= 0 ? bars.time[n - 1 + j] : bars.time[n - 1] + j * step)),
  value: k.map((j) => bars.close[best.end - 1 + j] * scale),
});
const day = (i) => new Date(bars.time[i]).toISOString().slice(0, 10);
const label = `Best match: ${day(best.end - m)} to ${day(best.end - 1)} · r = ${best.r.toFixed(2)}`;
// Shade the window that was matched, with the result.
chart.addLayer({
  pane: chart.mainPane,
  position: 'background',
  build(ctx) {
    const x1 = ctx.timeToX(bars.time[n - m]), x2 = ctx.timeToX(bars.time[n - 1]);
    if (x1 === null || x2 === null) return [];
    return [
      { type: 'rect', x: x1, y: ctx.rect.y, width: x2 - x1, height: ctx.rect.height, color: '#4cc9f014' },
      { type: 'text', x: x1 + 6, y: ctx.rect.y + ctx.rect.height - 12, text: 'Last 60 bars', color: '#4cc9f0', size: 11, align: 'left' },
      { type: 'text', x: ctx.rect.x + 10, y: ctx.rect.y + 16, text: label, color: '#ffb547', size: 12, align: 'left', background: '#161a22e0', padding: 6 },
    ];
  },
});
chart.setBarSpacing(6);
chart.setVisibleLogicalRange(n - 150, n + ahead + 4);

为逐笔级数据而生。

Apple M4 Max · Chrome + WebGPU

在浏览器中载入 100 万根 K 线并画出首帧

WASM · WebGPU

原生载入 1000 万根 K 线,含多级细节金字塔

原生 Rust

平移、缩放和实时推送时每帧的堆分配次数

稳定状态

WebAssembly 包体积(gzip)

包含全部功能

浏览器数据:Google Chrome + WebGPU;1000 万根 K 线的载入为原生 Rust。进度条表示各项数据相对于目标的比例:载入 300 毫秒、零分配、安装包 1.5 MB。

示例

313 个示例,
覆盖 20 个应用场景。

每个示例都是 FerroChart 在你的浏览器中实时渲染的图表,并附带源代码。所有数据均为模拟数据。

K 线回放
实时数据流
K 线 + 成交量
01

价格走势

25 个示例 →

适用于任何市场的 K 线、美国线和折线,实时流式更新。

深度热力图
Delta 足迹图
足迹图
04

订单流

20 个示例 →

足迹图、深度热力图和市场轮廓,走计算着色器路径。

隐含波动率 · 基差
多空比 · CVD
资金费率 · 持仓量 · 清算
06

加密衍生品

15 个示例 →

资金费率、持仓量、清算和基差,显示在价格下方的窗格中。

风险逆转 · 蝶式
到期预期波动幅度
隐含与已实现波动率 · IV Rank
12

期权与波动率

18 个示例 →

隐含波动率与已实现波动率、偏斜、预期波动幅度和做市商敞口随时间的变化。

联合回撤
水下曲线 · 最大回撤
净值曲线 · 回撤
16

组合、风险与量化

24 个示例 →

净值曲线、回撤、滚动统计、因子研究和风险检查。

分组柱状图
堆叠柱状图
100% 堆叠面积图
19

自定义系列与插件

11 个示例 →

堆叠、分组、箱线和刷选系列:在同一 GPU 帧上叠加图层插件。

浏览全部 20 个应用场景

价格走势

K 线类型与变换

技术分析

订单流

执行与交易复盘

加密衍生品

链上数据

DeFi 与 AMM

Meme 币与钱包

股票与基本面

A 股

期权与波动率

利率、外汇与宏观

期货与大宗商品

基金与 ETF

组合、风险与量化

私募市场与个人理财

预测市场

自定义系列与插件

实验室与旗舰示例

特性

为行情数据而设计。

01

跨平台渲染

同一个 Rust 内核:浏览器中使用 WebGPU 和 WebGL2 后端,原生应用中通过 wgpu 运行在 Metal、Vulkan 和 DirectX 12 上,服务器上使用 CPU 渲染器。黄金图像测试保证各后端输出一致。

02

性能与数据量无关

K 线数据常驻 GPU,坐标变换在着色器中完成,平移和缩放只需更新少量 uniform。多级细节金字塔让数千万根 K 线依然流畅。

03

30 个内置指标

从 SMA 到一目均衡表的均线、通道和震荡指标。每个 tick 增量更新,并用参考数据测试。

04

29 种画线工具

趋势线、通道、斐波那契工具、叉子线、江恩角度线、形态、艾略特波浪、区间、仓位和文字,支持撤销与重做。画线和图表状态可序列化为 JSON。

05

多图联动

同步组可在多个图表之间联动十字光标和可见范围。

06

易于扩展

自定义系列、图层和画线工具的插件接口。提供 JavaScript、Rust 和 Python 绑定,以及供 C#、C++、Qt 和 Flutter 使用的 C ABI。

开始使用

每种语言,同一套 API。

所有绑定遵循同一模型:创建图表、添加系列、设置数据、添加指标。数据按列传入,可以是类型化数组、Rust 切片或 DataFrame。

  • JavaScript 与 TypeScript
  • Rust
  • Python 与 Jupyter
  • C、C#、C++
阅读文档
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

每一个市场。
每一块屏幕。
同一个引擎。

基于 Apache-2.0 开源,从浏览器到交易台。