Skip to main content

ACEFormer Forecasting

Transformer with Empirical Mode Decomposition (EMD) preprocessing and ProbabilityAttention for stock price forecasting.

Paper: An End-to-End Structure with Novel Position Mechanism and Improved EMD for Stock Forecasting
Source: DurandalLee/ACEFormer


Overview

PropertyValue
Model Nameaceformer-forecasting
CategoryTime Series
FrameworkPyTorch
TrainableYes (train from scratch)
PretrainedNo — requires user data
GPU RequiredOptional (faster with GPU)
VRAM~512 MB
Parameters~100K
Inference EngineSpecialist (forecasting)

Capabilities

  • Stock price prediction using close prices (and optionally volume)
  • Custom EMD (Empirical Mode Decomposition) signal preprocessing
  • ProbSparse attention (Informer-style) with distillation layers
  • Temporal position parameters for time-aware learning
  • Lightweight model suitable for CPU inference
  • Rolling (autoregressive) prediction for horizons longer than predict_size

Training

ACEFormer trains from scratch on user-provided stock data. There are no pretrained weights — the model learns patterns specific to your dataset.

Input Format

CSV file with at least a close price column. Optionally include volume for better performance.

ColumnRequiredDescription
closeYesClosing price
volumeOptionalTrading volume
dateOptionalDate column (not used by model, but helpful for reference)

Minimum dataset size: 50 rows (200+ recommended for good results)

Hyperparameters

ParameterTypeDefaultRangeDescription
unit_sizeint3010-100Input window size (trading days)
predict_sizeint51-30Prediction horizon (trading days)
embed_dimint6432-256Embedding dimension
forward_dimint25664-1024Feed-forward hidden dimension
dis_layerint31-5Number of distillation layers
attn_layerint21-4Number of full attention layers
dropoutfloat0.10.0-0.5Dropout rate
learning_ratefloat0.0011e-4 to 0.01Learning rate
iterationsint2000100-10000Training iterations
batch_sizeint648-256Batch size
target_columnstringcloseTarget column name in CSV

Training Example

Python SDK:

from colabhive import ColabHive

client = ColabHive(api_key="...", account_id="...")

# Upload stock data
dataset = client.datasets.upload(name="AAPL-daily", file="./stock_prices.csv")

# Train ACEFormer
job = client.training.create(
model="aceformer-forecasting",
dataset_id=dataset.id,
hyperparameters={
"unit_size": 30,
"predict_size": 5,
"iterations": 2000,
"target_column": "close"
}
)

# Wait for completion
job.wait()
print(job.get_metrics()) # {"eval_mse": ..., "eval_mae": ..., "eval_rmse": ..., "eval_r2": ...}

cURL:

curl -X POST https://api.colabhive.com/api/builder/v1/training/runs \
-H "X-API-Key: $KEY" \
-H "X-Account-ID: $ACCT" \
-H "Content-Type: application/json" \
-d '{
"job_name": "aceformer-aapl",
"model_config_id": "ACEFORMER_CONFIG_UUID",
"dataset_id": "DATASET_UUID",
"hyperparameters": {
"unit_size": 30,
"predict_size": 5,
"iterations": 2000,
"target_column": "close"
}
}'

Training Output

FileDescription
model.ptPyTorch state_dict (model weights)
config.jsonHyperparameters + preprocessing state (model_type: "aceformer")
summary.jsonTraining metrics (MSE, MAE, RMSE, R2)

Metrics

MetricDescription
train_lossTraining MSE loss
eval_mseValidation Mean Squared Error
eval_maeValidation Mean Absolute Error
eval_rmseValidation Root Mean Squared Error
eval_r2Validation R-squared

Inference

After training, register the model for inference and send time series data.

Register for Inference

curl -X POST https://api.colabhive.com/api/builder/v1/training/runs/RUN_ID/register-for-inference \
-H "X-API-Key: $KEY" -H "X-Account-ID: $ACCT" \
-H "Content-Type: application/json" \
-d '{"name": "aapl-predictor", "description": "AAPL stock price forecaster", "visibility": "account"}'

Run Predictions

Univariate (close prices only):

curl -X POST https://api.colabhive.com/api/builder/v1/endpoints/ENDPOINT_ID/infer \
-H "X-API-Key: $KEY" -H "X-Account-ID: $ACCT" \
-H "Content-Type: application/json" \
-d '{
"input": {
"values": [150.2, 151.0, 149.8, 150.5, 152.0, 151.3, 153.1, 152.7, 154.0, 153.5,
154.2, 153.8, 155.0, 154.5, 155.8, 155.2, 156.0, 155.5, 156.8, 156.2,
157.0, 156.5, 157.8, 157.2, 158.0, 157.5, 158.8, 158.2, 159.0, 158.5],
"horizon": 5
}
}'

Multivariate (close + volume):

curl -X POST .../infer \
-d '{
"input": {
"series": {
"close": [150.2, 151.0, ...],
"volume": [1200000, 1150000, ...]
},
"horizon": 5
}
}'

Response

{
"result": {
"forecasts": [159.3, 159.8, 160.1, 159.5, 160.4],
"model_type": "ACEFormer",
"horizon": 5,
"inference_time_ms": 28.5
}
}

Architecture

ACEFormer combines three key innovations:

  1. Empirical Mode Decomposition (EMD): Custom preprocessing that extracts mid-curve signal from raw price data, reducing noise while preserving trend
  2. ProbSparse Attention: Informer-style attention that selects top-k most informative queries, reducing O(n^2) to O(n log n)
  3. Distillation Layers: Progressive sequence reduction via MaxPool1d + temporal parameters
Input (batch, 30, features)
-> ExpandEmbedding (Conv1d)
-> + PositionalEmbedding (sinusoidal)
-> 3x [ProbSparse CrossAttention + Distilling + Temporal Param]
-> 2x [Full CrossAttention]
-> Linear -> (batch, reduced_seq, 1)

Tips

  • Minimum data: 200+ rows for meaningful results. More data = better generalization.
  • Horizon vs predict_size: If you request horizon > predict_size, the model uses autoregressive rolling prediction. This works but accuracy degrades for longer horizons.
  • Feature selection: Including volume alongside close price typically improves performance.
  • Training iterations: Start with 500-1000 for quick experiments, use 2000-5000 for production models.
  • Unit size: 30 (one trading month) is the default and works well for daily data. Use 5-10 for intraday data.