This repository contains a trading strategy script that leverages the XGBoost machine learning algorithm to predict trading signals (Buy, Sell, or Hold) for various cryptocurrencies based on a series of technical indicators.
- Data Loading: Functions to load data from single or multiple CSV files.
- Preprocessing: Handles missing values, encodes categorical variables, and scales numerical features.
- Feature Generation: Creates various technical indicators like EMA, MACD, RSI, and more.
- Model Training: Uses Bayesian optimization for hyperparameter tuning and trains an XGBoost classifier.
- Signal Generation: Predicts trading signals based on the trained model.
- Evaluation: Computes various performance metrics such as accuracy, precision, recall, and ROC-AUC.
- Visualization: Plots the stock's close prices and overlays Buy and Sell signals.
Ensure you have the following libraries installed:
- pandas
- numpy
- xgboost
- scikit-learn
- matplotlib
- joblib
- ta
- skopt
- logging
You can install these using pip
:
pip install pandas numpy xgboost scikit-learn matplotlib joblib ta[all] scikit-optimize logging
-
Data Format:
- Make sure your data is in CSV format with columns like 'Close', 'High', 'Low', 'Volume', etc.
- For training, you can use multiple CSV files representing data from different cryptocurrencies.
-
Training the Model:
- Place your CSV files in a folder named
data
. - Run the script and choose the training option:
python trading_script.py
When prompted, choose:
Enter '1' to train the model or '2' to generate signals: 1
- Place your CSV files in a folder named
-
Generating Trading Signals:
- Make sure you've trained the model at least once.
- Place the new data CSV in the
data
folder. - Run the script and choose the signal generation option:
python trading_script.py
When prompted, choose:
Enter '1' to train the model or '2' to generate signals: 2
-
Visualizing Results:
- After generating signals, the script will automatically display a plot of the cryptocurrency's close prices with Buy and Sell signals.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.