Code Monkey home page Code Monkey logo

tzelalouzeir / xgb_cryptostrategy Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 476 KB

This repository contains a Python script that fetches historical Bitcoin (BTC) price data, calculates technical indicators, and applies a trading strategy based on machine learning. The purpose of the script is to assess the performance of the strategy using the XGBoost algorithm, which predicts long, short, or neutral positions.

License: MIT License

Python 100.00%

xgb_cryptostrategy's Introduction

XGBoost Bitcoin Trading Strategy Analysis

This repository contains a Python script that fetches historical Bitcoin (BTC) price data, calculates technical indicators, and applies a trading strategy based on machine learning. The purpose of the script is to assess the performance of the strategy using the XGBoost algorithm, which predicts long, short, or neutral positions.

Key Features

  1. Data Fetching: Fetches historical BTC-USD price data from Yahoo Finance.
  2. Technical Indicators: Calculates 12 technical indicators such as SMA, EMA, MACD, RSI, and more.
  3. Signal Generation: Determines trading signals (long/short/neutral) based on the change in closing price.
  4. Machine Learning: Uses XGBoost to predict trading signals based on feature importance.
  5. Trading Strategy: Implements a simulated trading strategy, recording entry and exit points and evaluating overall return.
  6. Visualization: Displays feature importance, balance over time, and BTC-USD close prices with trading points.

Libraries Used

  • pandas
  • pandas_ta
  • yfinance
  • numpy
  • matplotlib
  • xgboost
  • scikit-learn

Instructions

  1. Clone the Repository:

    git clone https://github.com/tzelalouzeir/XGB_CryptoStrategy.git
  2. Install Required Libraries: Ensure you have the required libraries. You can install them using:

    pip install pandas pandas_ta yfinance numpy matplotlib xgboost scikit-learn
  3. Run the Script:

    python xgb_backtrade.py
  4. Analyze the Results: After running the script, it will display various metrics, visualizations, and the final trading balance. Result Features ROC Performance

Notes

  • If you wish to fetch fresh data, uncomment the lines related to the yf.download function and adjust the period and interval according to your preference.
  • Adjust parameters such as max_trades_per_day, leverage, and the window size for signal generation to tune the strategy.
  • Ensure to interpret the results in a historical context and not as financial advice.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Disclaimer

This code is intended for educational purposes only. Past performance is not indicative of future results. Always do your research before making any investment.

Related Projects

  • Technical Analysis Repository: This repository fetches 120 days of hourly Bitcoin price data, calculates technical indicators, and analyzes the relations between these indicators.
  • Finding Features with XGBoost: Training and evaluating an XGBoost classifier on the Bitcoin technical indicators dataset. It aims to predict trading signals (like 'long', 'short', or 'neutral') based on the values of various indicators.
  • XGBoost Model Optimization: Optimizing the hyperparameters of an XGBoost classifier using the hyperopt library.

๐Ÿค Let's Connect!

Connect with me on LinkedIn.

For more insights into my work, check out my latest project: tafou.io.

I'm always eager to learn, share, and collaborate. If you have experiences, insights, or thoughts about RL, Prophet, XGBoost, SARIMA, ARIMA, or even simple Linear Regression in the domain of forecasting, please create an issue, drop a comment, or even better, submit a PR!

Let's learn and grow together! ๐ŸŒฑ

License

MIT

xgb_cryptostrategy's People

Contributors

tzelalouzeir avatar

Stargazers

 avatar  avatar  avatar Scott Edwards avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.