Skip to content

An imaginative example of a neural-network-based trading bot that merges a fantasy world simulation with cluster-based RL signals

License

Notifications You must be signed in to change notification settings

kadeng/AlpacaBot

 
 

Repository files navigation

Quantum RL Swing Traders – README
This repository features three advanced (and partly imaginative) Python scripts for Reinforcement Learning (RL)–based trading on Alpaca. They incorporate powerful RL techniques, creative illusions (like “quantum bridging”), and extensive indicator-based logic. The scripts are:

long.py

A long-only RL-based swing trading approach.
Uses SuperTrend, RSI, MACD, Bollinger Bands, SMA Crossover, and more.
Emphasizes trailing stop-loss, take-profit, and volatility-based risk management (ATR).
Persists the RL model’s weights and replay memory for ongoing learning.
short.py

A script allowing both long and short positions, referencing advanced RL routines.
Retains the same Double DQN + Dueling architecture, plus Prioritized Replay.
Uses minimal real or paper trades via Alpaca and references partial illusions about bridging or cluster expansions.
Checks drawdown, supertrend signals, and logs all trades.
quantum.py

A futuristic script merging multi-symbol RL logic with “quantum bridging illusions.”
Mentions specialized cluster layers per symbol (5 stocks + 5 ETFs) or up to 10 total.
Follows a similar loop to fetch bars, compute indicators, pick an RL action, and place an order.
Saves/loads model states (e.g., agent_checkpoint.pth or replay buffer) for persistent learning.
Disclaimer: Any reference to “quantum bridging,” illusions, or advanced futuristic AI is creative in nature. No real quantum computing is taking place here. The scripts do not guarantee any profitable trading outcome.

Key Features
Alpaca API Integration:

Retrieves historical OHLCV data.
Places trades in paper or live mode, depending on your config.json.
Reinforcement Learning:

Double DQN with Dueling Networks => stable Q-value estimates.
Prioritized Experience Replay => focuses training on critical experiences.
Adaptive Epsilon Decay => transitions from exploration to more policy-driven actions.
Technical Indicators:

SuperTrend for bullish vs. bearish signals.
RSI, MACD, Bollinger Bands, SMA Crossover, ATR for volatility, volume change, etc.
Risk Management:

Trailing Stop-Loss & Take-Profit placeholders.
Position Sizing: e.g., up to ~5% of total capital, or ATR-based shares logic.
Drawdown checks: halts trading if account equity drops beyond a user-defined threshold.
Persistent Memory:

Each RL agent can save and reload model weights (agent_checkpoint.pth or .pt files) plus replay buffer (replay_memory.pkl) for continuing training across sessions.
Setup & Usage
1. Dependencies
Python ≥ 3.8 recommended
Install necessary packages:
bash
Copy
Edit
pip install --upgrade pip
pip install alpaca-trade-api nest_asyncio torch ta pandas numpy scikit-learn
2. config.json
Create a file named config.json in the same directory, for example:

json
Copy
Edit
{
  "API_KEY": "YourAlpacaKey",
  "API_SECRET": "YourAlpacaSecret",
  "PAPER": true,
  "BASE_URL": "https://paper-api.alpaca.markets",
  "LOG_FILE": "trading_bot.log",
  "LOG_LEVEL": "INFO",
  "MEMORY_SIZE": 100000,
  "BATCH_SIZE": 64,
  "GAMMA": 0.99,
  "LEARNING_RATE": 0.0005,
  "TARGET_UPDATE": 1000,
  "EPSILON_DECAY": 10000,
  "ALPHA": 0.6,
  "BETA_START": 0.4,
  "CAPITAL_ALLOCATION": 0.05,
  "MAX_DRAWDOWN_LIMIT": 0.2,
  "TRAILING_STOP_LOSS": 0.05,
  "TAKE_PROFIT": 0.10,
  "MIN_HOLD_DAYS": 180,
  "MAX_HOLD_DAYS": 365,
  "SYMBOL_LIST_FILE": "list.txt"
}
Set your Alpaca keys, risk thresholds, memory sizes, etc. to match your preferences.

3. list.txt
Provide symbols for trading, one per line, e.g.:

Copy
Edit
AAPL
MSFT
TSLA
PLTR
SPY
QQQ
4. Running a Script
Long-Only: python long.py
Short + Long: python short.py
Quantum + Multi-Symbol: python quantum.py
Scripts typically launch an async loop, gather historical bars from Alpaca, compute indicators, pick RL actions, place orders, and log results. Some usage of TimeFrame.Day or TimeFrame.FifteenMin might require an updated alpaca_trade_api; check your version if you see timeframe errors.

Disclaimers
Fictional or Demonstrative:

References to “quantum bridging” or illusions are purely creative.
These scripts are not production-ready nor guaranteed to produce profits.
No Real Guarantees:

Actual trading is high risk. Thoroughly test in paper accounts or historical backtests.
TimeFrame Usage:

Some older references to daily vs. 15-minute bars. Keep your alpaca client updated.
Continuing Education:

Feel free to adapt or integrate more robust backtesting, user interface, or advanced risk management as needed.
Contributing
Fork this repo and clone to your local machine.
Create a Branch: git checkout -b feature/myEnhancements
Push and Open a Pull Request to propose new indicators, cluster logic, or quantum illusions.
Enjoy exploring these RL-based trading scripts, be mindful of the disclaimers, and have fun with the imaginative spin on “quantum bridging” or advanced cluster-based illusions!

About

An imaginative example of a neural-network-based trading bot that merges a fantasy world simulation with cluster-based RL signals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%