NHiTSFinance<T>

Models & Types · AiDotNet.Finance.Forecasting.Neural

N-HiTS (Neural Hierarchical Interpolation for Time Series) model for financial forecasting.

Inheritance: NeuralNetworkBase<T> → FinancialModelBase<T> → ForecastingModelBase<T> → NHiTSFinance<T>

For Beginners

N-HiTS works like having multiple “zoom levels” on your time series:

  • One level looks at fine details (hourly patterns)
  • Another looks at medium patterns (daily patterns)
  • Another looks at the big picture (weekly/monthly trends)

Each level (stack) samples the data at different rates:

  • High-frequency stack: Processes data at full resolution
  • Medium-frequency stack: Downsamples by 4x (averages 4 points into 1)
  • Low-frequency stack: Downsamples by 8x

This multi-scale approach helps N-HiTS:

  • Be more efficient (fewer parameters than N-BEATS)
  • Handle long horizons better
  • Capture patterns at different time scales

How It Works

N-HiTS improves upon N-BEATS by incorporating hierarchical interpolation and multi-rate signal sampling. It achieves better accuracy on long-horizon forecasting while being more parameter-efficient through its stack-specific pooling approach.

Reference: Challu et al., “N-HiTS: Neural Hierarchical Interpolation for Time Series Forecasting”, AAAI 2023. https://arxiv.org/abs/2201.12886

Example

var architecture = new NeuralNetworkArchitecture<double>(
    inputType: InputType.OneDimensional,
    taskType: NeuralNetworkTaskType.Regression,
    inputHeight: 60, inputWidth: 1, inputDepth: 1, outputSize: 24);
var model = new NHiTSFinance<double>(architecture);
var onnxModel = new NHiTSFinance<double>(architecture, "nhits.onnx");

Constructors

Constructor Summary
NHiTSFinance(NeuralNetworkArchitecture<T> architecture, NHiTSOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an N-HiTS network in native mode for training from scratch.
NHiTSFinance(NeuralNetworkArchitecture<T> architecture, string onnxModelPath, NHiTSOptions<T> options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer, ILossFunction<T> lossFunction) Creates an N-HiTS network using pretrained ONNX model.

Properties

Property Summary
bool IsChannelIndependent { get; }
bool SupportsTraining { get; }
bool UseNativeMode { get; }
int NumFeatures { get; }
int PatchSize { get; }
int PredictionHorizon { get; }
int SequenceLength { get; }
int Stride { get; }

Methods

Method Summary
Dictionary<string, T> Evaluate(Tensor<T> predictions, Tensor<T> actuals)
Dictionary<string, T> GetFinancialMetrics()
ModelMetadata<T> GetModelMetadata()
Tensor<T> ApplyInstanceNormalization(Tensor<T> input)
Tensor<T> AutoregressiveForecast(Tensor<T> input, int steps)