Skip to content

gkeiel/market_forecaster

Repository files navigation

Market Forecaster

This project provides a Python tool for backtesting and selecting the best-performing strategies to spot market time series, applying only machine learning algorithms.

As main advantages, the project provides:

  • uses supervised machine learning to generate trading signals.
  • recurring trading signals via Telegram channel.
  • open-source code, allowing flexibility in specifying machine learning models and comparing all strategies.

Telegram open channel with daily signals run via GitHub Actions. Anyone can sign up to get a feel for what this bot can offer. t.me/market_forecasting_public

📊 Features

  • Data download: Downloads market data through the Yahoo Finance API.
  • Machine-learning-based indicators: Implements machine-learning-based strategies to identify possible trends.
  • Strategy backtesting: Runs historical backtests, generating figures and summaries for decision-making.
  • Performance evaluation: Assesses results using a weighted objective function and ranks the best strategies.
  • Predict future prices: Make predictions based on supervised machine learning, applying applying statistical models or non-parametric algorithmic models.
  • Configuration files: Uses .env for private environment variables, .json for tickers list, .jsonfor indicators list, and .csv for strategies list.

📈 Available Strategies

The project currently supports supervisioned machine learning strategies for generating trading signals, using the following methods:

  • Linear Regression
  • Decision Trees Regressor
  • Random Forest Regressor
  • Gradient Boosting Regressor
  • Extra Trees Regressor
  • K Neighbors Regressor
  • Autoregressive Integrated Moving Average (ARIMA) models

These options allow the user to compare the performance of different approaches within the selected market.

⚙️ How to Use

  1. Install dependencies:

     pip install pandas
     pip install numpy
     pip install yfinance
     pip install requests
     pip install python-dotenv
     pip install scikit-learn
     pip install statsmodels
  2. Configure tickers and indicators

    • In config.json add the various configuration parameters.
    • In tickers.json add the stock codes to analyze.
    • In indicators.json add the indicators to generate.
    • In strategies.csv list the stocks to generate trading signals, each with its corresponding best strategy.
  3. Configure Telegram

    • Create a Telegram bot and obtain its TOKEN.
    • Create a Telegram channel and obtain its CHAT_ID.
    • Add the bot as channel administrator.
    • Add keys to .env file to be read by market_forecaster.py.
  4. Run the script

    • To run the batch of backtests, execute:
      python market_forecaster.py

🖼️ Output Examples

  • Backtest chart with Random Forest

    After running market_forecaster.py it generates strategy charts, spreadsheets for each ticker, and a summary with results sorted by best. The generated figures follow the example below:

    B3SA3_RF_50_5_5_forecast B3SA3_RF_50_5_5_backtest

    Notice that the asset ends the evaluated period near its initial price, so a Buy & Hold strategy would yield approximately a zero return. On the other hand, strictly following the machine learning strategy with Random Forest Regressor would produce above 160% return over the same period, excluding any trasactions fees. Furthermore, short selling operations are being considered by default in calculations, though they can easily be disabled in the backtest.

🧩 Project Structure

  • market_forecaster.py → Main file for backtesting and selecting the best strategies.
  • tickers.json → List of tickers to analyze.
  • indicators.json → List of machine-learning-based indicators to test.
  • strategies.csv → List of selected strategies for trading signals, including tickers and their indicators.

📌 Notes

⚠️ We are not responsible for any financial losses resulting from the use of the strategies or signals generated by this code.

  • Contributions are welcome! Open an issue or submit a pull request.
  • Future improvements and new features may be added, including:
    • more machine learning methods; ✅
    • statistical methods (ARIMA); ✅
    • improve objective function with new weights and presets;
    • use optimizer for the objective function.

🤝 Support

This repository is independently maintained, only in free time. If you find the code useful and wish to support its continued development, consider donating:

Your support helps keep the project alive and evolving, by adding new indicators, improvements, and documentation.

About

A Python tool for trading signals on global markets based on machine learning

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages