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
| Property | Value |
|---|---|
| Model Name | aceformer-forecasting |
| Category | Time Series |
| Framework | PyTorch |
| Trainable | Yes (train from scratch) |
| Pretrained | No — requires user data |
| GPU Required | Optional (faster with GPU) |
| VRAM | ~512 MB |
| Parameters | ~100K |
| Inference Engine | Specialist (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.
| Column | Required | Description |
|---|---|---|
close | Yes | Closing price |
volume | Optional | Trading volume |
date | Optional | Date column (not used by model, but helpful for reference) |
Minimum dataset size: 50 rows (200+ recommended for good results)
Hyperparameters
| Parameter | Type | Default | Range | Description |
|---|---|---|---|---|
unit_size | int | 30 | 10-100 | Input window size (trading days) |
predict_size | int | 5 | 1-30 | Prediction horizon (trading days) |
embed_dim | int | 64 | 32-256 | Embedding dimension |
forward_dim | int | 256 | 64-1024 | Feed-forward hidden dimension |
dis_layer | int | 3 | 1-5 | Number of distillation layers |
attn_layer | int | 2 | 1-4 | Number of full attention layers |
dropout | float | 0.1 | 0.0-0.5 | Dropout rate |
learning_rate | float | 0.001 | 1e-4 to 0.01 | Learning rate |
iterations | int | 2000 | 100-10000 | Training iterations |
batch_size | int | 64 | 8-256 | Batch size |
target_column | string | close | — | Target 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
| File | Description |
|---|---|
model.pt | PyTorch state_dict (model weights) |
config.json | Hyperparameters + preprocessing state (model_type: "aceformer") |
summary.json | Training metrics (MSE, MAE, RMSE, R2) |
Metrics
| Metric | Description |
|---|---|
train_loss | Training MSE loss |
eval_mse | Validation Mean Squared Error |
eval_mae | Validation Mean Absolute Error |
eval_rmse | Validation Root Mean Squared Error |
eval_r2 | Validation 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:
- Empirical Mode Decomposition (EMD): Custom preprocessing that extracts mid-curve signal from raw price data, reducing noise while preserving trend
- ProbSparse Attention: Informer-style attention that selects top-k most informative queries, reducing O(n^2) to O(n log n)
- 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.