Skip to content

A fully featured trading bot that uses reinforcement learning–inspired parameter tuning, a Flask web dashboard, market-hour awareness, and end-of-day watchlist discovery.

Notifications You must be signed in to change notification settings

ProgramingPro2/Reinforcement-Stocks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reinforcement Trading Bot

A fully featured trading bot that uses reinforcement learning–inspired parameter tuning, a Flask web dashboard, market-hour awareness, and end-of-day watchlist discovery. This bot uses yfinance to retrieve near real-time historical data and executes trades via Alpaca's API. It calculates a composite signal based on technical indicators (RSI, MACD, SMA, etc.) to determine buy/sell decisions during US market hours and automatically adjusts its strategy parameters over time.

Features

  • Near Real-Time Data: Uses yfinance for up-to-date historical data.
  • Automated Trading: Executes trades via Alpaca’s API (paper trading for testing).
  • Composite Signal Calculation: Combines RSI, MACD, and SMA signals using configurable weights.
  • Reinforcement Learning–Style Parameter Tuning: Automatically adjusts trading parameters based on recent trade performance.
  • End-of-Day Watchlist Discovery: Updates the watchlist at market close, retaining only the top-performing stocks.
  • Web Dashboard: Hosts a Flask-based dashboard to view current strategy settings, trade logs, and asset signals.

Requirements

Installation

  1. Clone the repository:

    git clone https://github.com/ProgramingPro2/Reinforcement-Stocks.git
    cd Reinforcement-Stocks
    
  2. Create a virtual environment and install packages:

    Linux:

    python3 -m venv venv
    source venv/bin/activate
    pip install alpaca_trade_api pandas numpy flask python-dotenv yfinance

    Windows:

    python3 -m venv venv
    venv\Scripts\activate
    pip install alpaca_trade_api pandas numpy flask python-dotenv yfinance
  3. Start script:

    python main.py

    or in debug mode:

    python main.py --debug

Configuration

Environment Variables: Create a .env file in the project root and add your Alpaca API credentials:

ALPACA_KEY=your_api_key_here
ALPACA_SECRET=your_api_secret_here
ENDPOINT=https://paper-api.alpaca.markets

Adjust the ORDER_AMOUNT (dollar amount per trade) and other strategy parameters in the data.json file or main.py as needed.

Watchlist

Create a stocks.json file in the working directory containing a list of stock tickers. The following characters are not valid, (){}[].,^$@! For example:

 ["AAPL", "MSFT", "GOOGL", "AMZN", "TSLA"]

to automatically verify your file run:

python stocks_file_verifier.py

Usage

Run the trading bot with the debug flag (optional):

python main.py --debug

When you run the script, it will:

Retrieve near real-time historical data via yfinance.
Compute composite signals based on RSI, MACD, and SMA.
Execute trades on Alpaca’s paper trading endpoint (ensure your API credentials are set).
Automatically adjust strategy parameters over time.
Launch a flask dashboard you can access http://0.0.0.0:5000.

Disclaimer

This project is for educational purposes only. Trading involves risk, and you should always perform thorough testing using paper trading before using any strategy with real capital. The author is not responsible for any losses incurred.

Contributing

Contributions, issues, and feature requests are welcome! Please check the issues page for open problems or to suggest enhancements.

About

A fully featured trading bot that uses reinforcement learning–inspired parameter tuning, a Flask web dashboard, market-hour awareness, and end-of-day watchlist discovery.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published