Skip to content

AksanBA/financial-fusion-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Financial Fusion Model

A comprehensive financial analysis and prediction system that combines multiple data sources, advanced machine learning techniques, and sentiment analysis to provide accurate market insights.

πŸš€ Features

  • Multi-Source Data Collection: Market data, news, sentiment analysis
  • Advanced Technical Analysis: Comprehensive technical indicators using TA-Lib
  • AI-Powered Sentiment Analysis: News and social media sentiment processing
  • Machine Learning Models: Time series prediction and classification
  • Real-time Analysis: Live market data processing and analysis
  • API Integration: RESTful API for external integrations
  • Docker Support: Containerized deployment ready

πŸ“‹ Table of Contents

πŸ› οΈ Installation

Prerequisites

  • Python 3.9+
  • TA-Lib (requires system installation)
  • Redis (for caching)
  • Docker (optional, for containerized deployment)

System Dependencies

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install build-essential wget

macOS:

brew install ta-lib

Install TA-Lib from source (Linux):

wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz
tar -xzf ta-lib-0.4.0-src.tar.gz
cd ta-lib/
./configure --prefix=/usr
make
sudo make install

Python Environment

  1. Clone the repository:
git clone https://github.com/yourusername/financial-fusion-model.git
cd financial-fusion-model
  1. Create virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Install development dependencies (optional):
pip install -r requirements-dev.txt

⚑ Quick Start

  1. Set up environment variables:
cp .env.example .env
# Edit .env with your API keys
  1. Configure your API keys in .env:
NEWS_API_KEY=your_news_api_key_here
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_key_here
OPENAI_API_KEY=your_openai_api_key_here
  1. Run the basic data collection:
python -m src.data.collectors.market_data
  1. Start the API server:
python -m src.api.main

πŸ“ Project Structure

financial-fusion-model/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ agents/              # AI agents for analysis
β”‚   β”‚   └── data_agent.py
β”‚   β”œβ”€β”€ api/                 # REST API endpoints
β”‚   β”‚   β”œβ”€β”€ routers/
β”‚   β”‚   └── schemas/
β”‚   β”œβ”€β”€ data/                # Data collection and processing
β”‚   β”‚   β”œβ”€β”€ collectors/      # Market data, news, sentiment
β”‚   β”‚   β”œβ”€β”€ loaders/         # Data loading utilities
β”‚   β”‚   └── processors/      # Text and time series processing
β”‚   β”œβ”€β”€ models/              # ML models and components
β”‚   β”‚   β”œβ”€β”€ fusion_model.py
β”‚   β”‚   └── components/
β”‚   β”œβ”€β”€ serving/             # Model serving utilities
β”‚   └── utils/               # Configuration and utilities
β”œβ”€β”€ config/                  # Configuration files
β”œβ”€β”€ docker/                  # Docker configurations
β”œβ”€β”€ docs/                    # Documentation
β”œβ”€β”€ models/                  # Trained model artifacts
β”œβ”€β”€ notebooks/               # Jupyter notebooks
β”œβ”€β”€ scripts/                 # Utility scripts
β”œβ”€β”€ tests/                   # Test suites
β”œβ”€β”€ requirements.txt         # Python dependencies
β”œβ”€β”€ requirements-dev.txt     # Development dependencies
β”œβ”€β”€ Makefile                 # Build automation
└── README.md               # This file

βš™οΈ Configuration

The project uses environment variables for configuration. Key settings include:

  • NEWS_API_KEY: API key for news data collection
  • ALPHA_VANTAGE_API_KEY: Alpha Vantage API for market data
  • OPENAI_API_KEY: OpenAI API for sentiment analysis
  • DATABASE_URL: Database connection string
  • REDIS_URL: Redis connection for caching
  • LOG_LEVEL: Logging level (INFO, DEBUG, etc.)

πŸ“– Usage

Data Collection

Collect market data:

from src.data.collectors.market_data import MarketDataCollector

collector = MarketDataCollector()
data = collector.get_stock_data("AAPL", "2023-01-01", "2023-12-31")

Collect news and sentiment:

from src.data.collectors.sentiment_analyzer import NewsCollector

news_collector = NewsCollector()
articles = news_collector.get_news_articles("AAPL", start_date, end_date)

Model Training

# Train the fusion model
python -m src.models.fusion_model --train --symbol AAPL

# Evaluate model performance
python -m src.models.fusion_model --evaluate --symbol AAPL

API Usage

Start the API server:

uvicorn src.api.main:app --reload

Access the API documentation at: http://localhost:8000/docs

πŸ”Œ API Documentation

Endpoints

  • GET /health - Health check
  • POST /predict - Get price predictions
  • GET /data/{symbol} - Retrieve market data
  • POST /analyze/sentiment - Analyze text sentiment
  • GET /indicators/{symbol} - Get technical indicators

Example Request

curl -X POST "http://localhost:8000/predict" \
     -H "Content-Type: application/json" \
     -d '{
       "symbol": "AAPL",
       "days_ahead": 5,
       "include_sentiment": true
     }'

🐳 Docker Deployment

Using Docker Compose

# Build and start all services
docker-compose up --build

# Run in background
docker-compose up -d

# Stop services
docker-compose down

Manual Docker Build

# Build the main application
docker build -f docker/Dockerfile -t financial-fusion-model .

# Build the API service
docker build -f docker/Dockerfile.api -t financial-fusion-api .

# Run the container
docker run -p 8000:8000 financial-fusion-api

πŸ§ͺ Testing

Run the test suite:

# Run all tests
python -m pytest

# Run with coverage
python -m pytest --cov=src tests/

# Run specific test category
python -m pytest tests/unit/
python -m pytest tests/integration/

πŸ“Š Model Performance

The fusion model combines multiple data sources:

  • Technical Indicators: RSI, MACD, Bollinger Bands, etc.
  • Sentiment Analysis: News and social media sentiment scores
  • Market Microstructure: Volume, bid-ask spreads, order flow
  • Macroeconomic Factors: Interest rates, volatility indices

Expected performance metrics:

  • Accuracy: 65-75% on 5-day price direction
  • Sharpe Ratio: 1.2-1.8 on backtested strategies
  • Max Drawdown: <15% on historical data

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Commit your changes: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request

Development Setup

# Install development dependencies
pip install -r requirements-dev.txt

# Install pre-commit hooks
pre-commit install

# Run code formatting
black src/
isort src/

# Run linting
flake8 src/
mypy src/

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • TA-Lib for technical analysis indicators
  • LangChain for AI agent framework
  • FastAPI for the web framework
  • Alpha Vantage for market data API
  • NewsAPI for news data collection

πŸ“§ Contact


⭐ Star this repo if you found it helpful!

🚨 Disclaimer

This software is for educational and research purposes only. It should not be used as the sole basis for financial decisions. Always consult with qualified financial advisors before making investment decisions. Past performance does not guarantee future results.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages