Dobromir Popov 8981ad0691 wip
2025-03-31 02:22:51 +03:00
..
2025-03-25 13:38:25 +02:00
2025-03-25 12:48:58 +02:00
wip
2025-03-31 02:22:51 +03:00
wip
2025-03-31 02:22:51 +03:00
2025-03-25 12:48:58 +02:00
2025-03-25 13:49:59 +02:00
2025-03-25 12:48:58 +02:00
2025-03-25 12:48:58 +02:00
wip
2025-03-31 02:22:51 +03:00
2025-03-29 03:53:38 +02:00
2025-03-29 03:53:38 +02:00
2025-03-25 13:38:25 +02:00

Neural Network Trading System

A comprehensive neural network trading system that uses deep learning models to analyze cryptocurrency price data and generate trading signals.

Architecture Overview

This project implements a 500M parameter neural network system using a Mixture of Experts (MoE) approach. The system consists of:

  1. Data Interface: Connects to real-time trading data from realtime.py and processes it for the neural network models
  2. CNN Module (100M parameters): A deep convolutional neural network for feature extraction from time series data
  3. Transformer Module: Processes high-level features and raw data for improved pattern recognition
  4. Mixture of Experts (MoE): Coordinates the different models and combines their predictions

The system is designed to identify buy/sell opportunities in cryptocurrency markets by analyzing patterns in historical price and volume data.

Components

Data Interface

  • Located in NN/utils/data_interface.py
  • Provides seamless access to historical and real-time data from realtime.py
  • Preprocesses data for neural network consumption
  • Supports multiple timeframes and features

CNN Model

  • Located in NN/models/cnn_model.py
  • Implements a deep convolutional network for time series analysis
  • Uses multiple parallel convolutional layers to detect patterns at different time scales
  • Includes bidirectional LSTM layers for sequence modeling
  • Optimized for financial time series data

Transformer Model

  • Located in NN/models/transformer_model.py
  • Uses self-attention mechanism to process time series data
  • Takes both raw data and high-level features from the CNN as input
  • Better at capturing long-range dependencies in the data

Orchestrator

  • Located in NN/main.py
  • Coordinates data flow between the models
  • Implements training and inference pipelines
  • Provides a unified interface for the entire system

Usage

Requirements

  • TensorFlow 2.x
  • NumPy
  • Pandas
  • Matplotlib
  • scikit-learn

Training the Model

To train the neural network on historical data:

python -m NN.main --mode train --symbol BTC/USDT --timeframes 1h 4h 1d --epochs 100

Making Predictions

To make one-time predictions:

python -m NN.main --mode predict --symbol BTC/USDT --timeframe 1h --model_type cnn

Running Real-time Analysis

To continuously analyze the market and generate signals:

python -m NN.main --mode realtime --symbol BTC/USDT --timeframe 1h --interval 60

Model Architecture Details

CNN Architecture

The CNN model uses a multi-scale approach with three parallel convolutional pathways:

  • Short-term patterns: 3x1 kernels
  • Medium-term patterns: 5x1 kernels
  • Long-term patterns: 7x1 kernels

These pathways are merged and processed through deeper convolutional layers, followed by LSTM layers to capture temporal dependencies.

Transformer Architecture

The transformer model uses:

  • Multi-head self-attention layers to capture relationships between different time points
  • Layer normalization and residual connections for stable training
  • A feed-forward network for final classification/regression

Mixture of Experts

The MoE model:

  • Combines predictions from CNN and Transformer models
  • Uses a weighted average approach for signal generation
  • Can be extended with additional expert models

Training Data

The system uses historical OHLCV (Open, High, Low, Close, Volume) data at different timeframes:

  • 1-minute candles for short-term analysis
  • 1-hour candles for medium-term trends
  • 1-day candles for long-term market direction

Output

The system generates one of three signals:

  • BUY: Indicates a potential buying opportunity
  • HOLD: Suggests maintaining current position
  • SELL: Indicates a potential selling opportunity

Development

Adding New Models

To add a new model type:

  1. Create a new class in the NN/models directory
  2. Implement the required interface (build_model, train, predict, etc.)
  3. Update the orchestrator to include the new model

Customizing Parameters

Key parameters can be customized through command-line arguments or by modifying the configuration in main.py.