A powerful tool for analyzing trade data using Large Language Models (LLMs). This tool supports reading trade data from both CSV and Parquet files, with features for sampling, filtering, and detailed analysis.
-
Multiple File Format Support:
- CSV files (pipe-delimited)
- Parquet files (with ZSTD compression)
-
Flexible Data Sampling:
- Sample by absolute number (e.g.,
--sample 1000) - Sample by percentage (e.g.,
--sample 10%) - Per-symbol or global sampling
- Sample by absolute number (e.g.,
-
Symbol Filtering:
- Filter trades for specific symbols
- Support for multiple symbols
-
Multiple LLM Providers:
- OpenAI
- NVIDIA AI
- Ollama (local)
-
Trade Analysis:
- Volume analysis
- Price analysis
- Statistical measures
- Pattern recognition
- Market microstructure insights
- Clone the repository:
git clone <repository-url>
cd python_trade_analyzer- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
cp .env.example .env
# Edit .env with your API keys and preferencespython src/trade_analyzer.py trades.csv --sample 1000 --symbols AAPL,MSFT# Read from Parquet file
python src/trade_analyzer.py trades.parquet --sample 1000 --symbols AAPL,MSFT
# Save sample to Parquet
python src/trade_analyzer.py trades.csv --sample 1000 --symbols AAPL,MSFT --save-sample sample.parquet
# Load from saved Parquet sample
python src/trade_analyzer.py trades.csv --load-sample sample.parquet# Sample 1000 trades per symbol
python src/trade_analyzer.py trades.csv --sample 1000 --symbols AAPL,MSFT
# Sample 10% of trades per symbol
python src/trade_analyzer.py trades.csv --sample 10% --symbols AAPL,MSFT
# Sample from all symbols
python src/trade_analyzer.py trades.csv --sample 1000# Use OpenAI (default)
python src/trade_analyzer.py trades.csv --provider openai
# Use NVIDIA AI
python src/trade_analyzer.py trades.csv --provider nvidia
# Use local Ollama
python src/trade_analyzer.py trades.csv --provider ollamaLLM_TOKEN: Default API key for LLM providersOPENAI_API_KEY: OpenAI API keyNVIDIA_API_KEY: NVIDIA AI API keyLOG_LEVEL: Logging level (INFO, DEBUG, etc.)DEFAULT_OPENAI_MODEL: Default model for OpenAIDEFAULT_NVIDIA_MODEL: Default model for NVIDIADEFAULT_OLLAMA_MODEL: Default model for Ollama
- Pipe-delimited (|)
- Required columns:
- Time
- Symbol
- Trade Price
- Trade Volume
- Sale Condition
- Same column structure as CSV
- ZSTD compression for optimal storage
The tool provides comprehensive trade analysis including:
-
Volume Analysis
- Total volume
- Average trade size
- Distribution by trade type
- Buy/Sell imbalance
-
Price Analysis
- Price range
- VWAP
- Volatility
- Price trends
-
Statistical Measures
- Mean, median, mode
- Standard deviation
- Time-weighted metrics
-
Pattern Analysis
- Price impact ratio
- Trade size clustering
- Support/resistance levels
-
Market Microstructure
- Bid-ask bounce
- Trade sign analysis
- Market impact
- Liquidity analysis
The tool recognizes various sale condition codes:
-
Regular Trades:
- Empty condition or '@' = REGULAR
-
Opening/Closing:
- 'O' = OPENING
- 'M' or '6' = CLOSING
- '5' = REOPENING
-
Special Trade Types:
- 'F' = ISO (Intermarket Sweep Order)
- 'I' = ODD_LOT
- 'X' = CROSS
- 'B' or 'W' = AVG_PRICE
- 'C' = CASH
- 'V' = CONTINGENT
- '7' = QCT (Qualified Contingent Trade)
- '4' = DERIVATIVE
-
Extended Hours:
- 'T' or 'U' = EXTENDED
-
Out of Sequence:
- 'L' or 'Z' = OUT_OF_SEQ
-
Other Special Conditions:
- 'H' = PRICE_VARIATION
- 'P' = PRIOR_REF
- 'R' = SELLER
- 'E' = AUTO_EXEC
- 'K' = RULE_127_155
- '9' = CORRECTED_CLOSE
- Uses DuckDB for efficient data processing
- Parquet format provides better compression and faster read times
- Sampling is done at the database level for memory efficiency
- Supports processing large files through efficient streaming
Contributions are welcome! Please feel free to submit a Pull Request.
MIT License - See LICENSE file for details