Downloads · 30 days
0
SatyamSinghal/financial-ttm
financial-ttm is a machine learning model from SatyamSinghal. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This project implements a Transformer-based deep learning model designed specifically for financial time series prediction. The system can forecast multiple target variables:
Downloads · 30 days
0
Access
Public
Updated Jun 17, 2025
Repo size
3.6 MB
Likes
0
Public
Click a slice to open those files.
.pth3.6 MB · 100%
From the Hugging Face model README
This project implements a Transformer-based deep learning model designed specifically for financial time series prediction. The system can forecast multiple target variables:
The model leverages the Transformer architecture's ability to capture long-term dependencies and patterns in sequential data, making it well-suited for financial market prediction tasks.
ML_TTT/
├── main.py # Entry point with training orchestration
├── feature_engineering.py # Data transformation and sequence creation
├── models.py # Neural network architecture definitions
├── training.py # Training loop, datasets, and optimization
├── metrics.py # Performance evaluation metrics
├── prediction_agent.py # Model inference and prediction interface
├── risk_manager.py # Risk analysis utilities
├── real_time_data.py # Data handling for live/synthetic data
└── requirements.txt # Project dependencies
The core FinancialTTM model consists of:
pip install -r requirements.txt
main.py:config = {
'input_dim': 20, # Number of input features
'd_model': 64, # Transformer dimension
'nhead': 4, # Number of attention heads
'num_layers': 2, # Transformer encoder layers
'lookback_window': 20, # Sequence length for input
'prediction_horizon': 5, # Number of future steps to predict
'batch_size': 64, # Training batch size
'learning_rate': 0.001, # Learning rate
'epochs': 20 # Training epochs
}
Run the training script:
python main.py
This will:
financial_ttm_model.pthimport torch
from models import FinancialTTM
# Load model
model_data = torch.load('financial_ttm_model.pth')
model = FinancialTTM(
input_dim=model_data['config']['input_dim'],
d_model=model_data['config']['d_model'],
nhead=model_data['config']['nhead'],
num_layers=model_data['config']['num_layers'],
prediction_horizon=model_data['config']['prediction_horizon']
)
model.load_state_dict(model_data['state_dict'])
model.eval()
# Prepare input (ensure it's preprocessed the same way as training data)
input_sequence = torch.FloatTensor(processed_input_data)
# Get predictions
with torch.no_grad():
predictions = model(input_sequence)
# Access different predictions
price_predictions = predictions['price_prediction']
volatility_predictions = predictions['volatility_prediction']
confidence = predictions['confidence']
risk_class = predictions['risk_classification']
Model performance is evaluated using:
import torch
# After successful training
model_info = {
'model_state_dict': model.state_dict(),
'config': {
'input_dim': 20,
'd_model': 64,
'nhead': 4,
'num_layers': 2,
'prediction_horizon': 5
},
'feature_columns': list(numeric_columns), # Feature column names
'scaler': feature_eng.scaler # Save scaler for preprocessing
}
torch.save(model_info, "financial_ttm_model.pth")
pip install huggingface_hub
huggingface-cli login
from huggingface_hub import HfApi
api = HfApi()
api.create_repo(repo_id="your-username/financial-ttm", private=False)
# Upload model file
api.upload_file(
path_or_fileobj="financial_ttm_model.pth",
path_in_repo="financial_ttm_model.pth",
repo_id="your-username/financial-ttm"
)
# Upload readme
api.upload_file(
path_or_fileobj="README.md",
path_in_repo="README.md",
repo_id="your-username/financial-ttm"
)
# Upload example usage code
api.upload_file(
path_or_fileobj="example_inference.py",
path_in_repo="example_inference.py",
repo_id="your-username/financial-ttm"
)
Once published, you can share the URL: https://huggingface.co/your-username/financial-ttm
Users can then download and use your model:
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(repo_id="your-username/financial-ttm", filename="financial_ttm_model.pth")
model_data = torch.load(model_path)
Contributions are welcome! Here are some areas for potential improvement:
This project is licensed under the MIT License - see the LICENSE file for details.