YAML Metadata
Warning:
empty or missing yaml metadata in repo card
(https://huggingface.co/docs/hub/model-cards#model-card-metadata)
finance-ts-lstm-autoencoder-anomaly
Model Overview
This model is a specialized LSTM Autoencoder designed for Unsupervised Anomaly Detection in multivariate financial time series data. It learns the "normal" day-to-day patterns and correlations between key financial assets (e.g., Bitcoin, Ethereum, Nasdaq, VIX). An anomaly is identified when the model's reconstruction error for a given time window exceeds a predetermined threshold, indicating a significant deviation from expected behavior.
Model Architecture
- Architecture: Stacked LSTM Autoencoder
- Input: A sequence of normalized financial data (30 days/timesteps, 4 features).
- Encoder: Two stacked LSTM layers (
num_layers=2), mapping the input sequence down to a fixed-sizelatent_dimension(32). The latent vector captures the compressed "essence" of the sequence's normal pattern. - Decoder: Two stacked LSTM layers, which attempt to reconstruct the original 30-day input sequence solely from the latent vector.
- Anomaly Score: The squared difference between the input sequence and the reconstructed output (Mean Squared Error, MSE).
Intended Use
- Risk Management: Automatically flagging unusual market movements that warrant investigation, such as sudden decoupling of crypto and traditional markets.
- Trading Signal Generation: Serving as a preliminary signal for potential market regime shifts or extreme volatility events.
- Data Quality Monitoring: Detecting corrupt or erroneous data feeds.
Limitations and Ethical Considerations
- Threshold Dependency: The definition of an "anomaly" is determined by the
anomaly_threshold(e.g., 0.05 MSE). Choosing this threshold is subjective and requires careful validation, as a low threshold causes many false alarms (false positives), and a high one misses real crises (false negatives). - Unsupervised: The model learns from historical data. It will flag any novel event (whether a real crisis or just a new market behavior) as an anomaly.
- Interpretation: The model only flags that something is anomalous, not why. Further analysis (e.g., feature attribution) is required to understand the cause.
- Data Requirements: Requires clean, co-integrated, and consistently normalized time series data for all features.
Example Code (Conceptual PyTorch Usage)
This example shows how the model is conceptually used to calculate an anomaly score.
import torch
import torch.nn as nn
import numpy as np
# Model parameters (matches config.json)
INPUT_SIZE = 4
SEQ_LENGTH = 30
ENCODER_HIDDEN = 64
LATENT_DIM = 32
# Conceptual Model Class (not runnable without full implementation)
class LSTMAutoencoder(nn.Module):
# (Encoder and Decoder setup omitted for brevity)
def forward(self, x):
# x is (Batch, SEQ_LENGTH, INPUT_SIZE)
# encoder_output = self.encoder(x)
# reconstructed_output = self.decoder(encoder_output)
# return reconstructed_output
return torch.randn_like(x) # Placeholder for reconstruction
# Load weights and instantiate (Conceptual)
# model = LSTMAutoencoder(...)
# model.load_state_dict(torch.load("pytorch_model.bin"))
# model.eval()
# Dummy input data: 30 days of the 4 features
# In a real scenario, this would be standardized/normalized.
current_window = torch.randn(1, SEQ_LENGTH, INPUT_SIZE)
# with torch.no_grad():
# reconstruction = model(current_window)
# Calculate Anomaly Score (Reconstruction Error)
mse_loss = nn.MSELoss(reduction='mean')
anomaly_score = mse_loss(current_window, reconstruction).item()
# ANOMALY_THRESHOLD = 0.05 (from config.json)
# if anomaly_score > ANOMALY_THRESHOLD:
# print(f"ANOMALY DETECTED! Score: {anomaly_score:.4f}")
# else:
# print(f"Normal. Score: {anomaly_score:.4f}")
- Downloads last month
- 18
Inference Providers
NEW
This model isn't deployed by any Inference Provider.
๐
Ask for provider support