Skip to content

PluginForecasting API Reference

The PluginForecasting adds advanced time-series prediction capabilities to the Velo Plot. It implements several statistical forecasting models natively in TypeScript.

Initialization

typescript
import { createChart } from 'velo-plot/scientific';
import { PluginForecasting } from 'velo-plot/plugins/forecasting';

const chart = createChart({ ... });
await chart.use(PluginForecasting({
  defaultOptions: {
    method: 'holtWinters',
    horizon: 50
  }
}));

API Reference

Once registered, the plugin exposes its API through chart.forecasting.

forecast(data, options)

Generates a forecast for the provided raw data, or for an existing series when a series id string is passed.

Parameters:

  • data: SeriesData | number[] | Float32Array | string - The historical data, or a series id.
  • options: ForecastingOptions - Configuration for the forecast.

Returns: ForecastingResult

typescript
// Forecast an existing series by id
const result = chart.forecasting.forecast('s1', { method: 'arima', horizon: 50 });
chart.forecasting.visualize(result); // shaded confidence band + dashed line

forecastSeries(seriesId, options)

Generates a forecast for a specific series already present in the chart.

Parameters:

  • seriesId: string - ID of the series to analyze.
  • options: ForecastingOptions - Configuration for the forecast.

Returns: Promise<ForecastingResult>

visualize(result, config?)

Renders the forecast on the chart overlay.

Parameters:

  • result: ForecastingResult - The result from a forecast call.
  • config: ForecastingVisualizationConfig - (Optional) Styling configuration.

Returns: string (The visualization ID).

clear(id?)

Removes active forecast visualizations.

Parameters:

  • id: string - (Optional) ID of a specific visualization to remove. If omitted, all forecasts are cleared.

Interfaces

ForecastingOptions

PropertyTypeDescription
methodstringMethod to use (see below)
horizonnumberNumber of points to project
confidencenumber(Optional) Confidence level (0-1)
paramsForecastingParamsMethod-specific parameters

ForecastingMethod

All methods are implemented and return finite forecasts with confidence bands. No public method throws for a supported method (as of v2.2.0).

MethodDescriptionUncertainty grows with horizon
'sma'Simple Moving Average (flat projection at trailing average)no
'wma'Weighted Moving Average (linear weights on trailing window)no
'ema'Exponential Moving Average (flat at last EMA)no
'expSmoothing'Simple Exponential Smoothing (SES)no
'holt'Double Exponential Smoothing (trend-aware)yes
'holtWinters'Triple Exponential Smoothing (trend + seasonality)yes
'linear'Linear Trend Projection (least-squares fit)yes
'arima'ARIMA(p,d,q) via the two-stage Hannan-Rissanen procedureyes

ARIMA falls back to Holt's linear trend when the history is too short to fit the requested orders, so it is always safe to call.

ForecastingParams

PropertyTypeDescription
alphanumberSmoothing factor for level
betanumberSmoothing factor for trend
gammanumberSmoothing factor for seasonality
periodnumberSeasonal cycle length
windowSizenumberWindow size for SMA/WMA
pnumberARIMA autoregressive order (default 1)
dnumberARIMA differencing order (default 1)
qnumberARIMA moving-average order (default 0)

Confidence bands

Every forecast returns lowerBound / upperBound computed from in-sample one-step residuals. The band half-width is z(confidence) · σ · √h for trend/AR models (widening with the horizon h) and z(confidence) · σ for the flat moving-average methods. Set the level via options.confidence (default 0.95). Render the shaded band with visualize(result) or the band series type.

ForecastingResult

PropertyTypeDescription
xValuesnumber[]Projected X coordinates
yValuesnumber[]Projected Y values
lowerBoundnumber[]Lower confidence limit
upperBoundnumber[]Upper confidence limit
metadataobjectFit statistics: mse, rmse, mae, r2, confidence

Known limitations

  • Unknown method strings throw — only documented methods (sma, ema, wma, linear, expSmoothing, holt, holtWinters, arima) are supported.

Released under the MIT License.