A smart crypto trading pipeline that combines social sentiment, news analysis, on-chain metrics, and machine learning to generate and backtest trading signals for Bitcoin.
-
π Multi-source Data Collection:
- Reddit posts (
r/Bitcoin) - News articles (via NewsAPI)
- Blockchain on-chain transaction data
- Reddit posts (
-
π Sentiment Analysis:
- VADER and TextBlob sentiment scores
- Optional BERT-based transformer sentiment
- Rolling sentiment smoothing
-
π‘ Trading Signal Generation:
- Simple rules based on sentiment thresholds
- Buy/Hold/Sell labeling
-
π§ͺ Backtesting with Backtrader:
- Strategy simulation on real-time BTC prices
- Final portfolio value calculation
-
π€ Machine Learning Classifier:
- XGBoost model trained on historical sentiment/price data
- Accuracy and classification reporting
-
βοΈ Sharpe Ratio Optimization:
- Automated threshold tuning for maximum risk-adjusted returns
Crypto.py # Main script
sentiment_data.csv # Intermediate file with collected raw sentiment data
sentiment_trading_data.csv # Processed file with sentiment + signals
-
Clone this repository:
git clone https://github.com/your-username/CryptoSentimentTrader.git cd CryptoSentimentTrader -
Install required packages:
pip install -r requirements.txt
Example
requirements.txt:praw requests pandas newsapi-python nltk textblob transformers backtrader xgboost scikit-learn tf-keras -
Download NLTK data:
import nltk nltk.download("vader_lexicon")
-
Replace the following with your own API keys:
client_id,client_secretin the Reddit sectionNEWS_API_KEYfor the NewsAPI
β
Accuracy: 0.78
π Best Sharpe Ratio: 1.42
π Optimized Buy Threshold: 0.75
π° Final Portfolio Value: $11,326.52
- API rate limits may affect large data pulls.
- Transformer sentiment is optional but can be enabled for deeper NLP insight.
- Model assumes short-term predictionβdo not use for long-term financial advice.
Feel free to fork, improve, or contribute PRs. Suggestions welcome!
MIT License