Getting Started
Welcome to Algo Trading Stack — an extensible, config-driven simulator/backtesting sandbox for building trading bots and interchangeable exit strategies.
This guide helps you go from a clean checkout to your first backtest run with the GUI, and shows where to go next to customize configs, write your own bot, or explore exits.
Prerequisites
- Ubuntu
- Python 3.10+ (recommended)
- pip (or uv/poetry if you prefer)
- Optional (for live data examples later): a TradeStation SIM account and credentials
1) Set up the project
We’ll clone the repo, create an isolated environment, and install dependencies.
# Clone the project
git clone https://github.com/denkovarik/Algo-Trading-Stack.git
cd Algo-Trading-Stack
# Install dependencies
./setup/install.sh
# Activate Python Virutal Environment
source venv/bin/activate
# Download Asset Data from Yahoo Finance
./setup/fetch_sample_portfolio_futures_data.sh
2) Run your first backtest (GUI)
The quickest way to see the system in action is to launch the GUI backtester. This uses a sample bot and a sample backtest config out-of-the-box.
PYTHONPATH=. python3 run_backtest.py
What you’ll see
- A candlestick chart that updates bar-by-bar
- Stop-loss / take-profit guides (when the exit strategy sets them)
- An Equity Curve window (you can open it via “Show Equity Curve”)
- A Statistics dialog (open with the “Show Statistics” button) summarizing trades, win rate, and drawdown per asset
Basic controls in the GUI
- Start / Pause / Resume the backtest (top-level controls)
- Restart Backtest (runs from the beginning with current settings)
- ⏮ / ⏪ / ⏩ / ⏭ buttons to rewind/fast-forward when paused
- Open Chart for a selected symbol
- Show Statistics for portfolio + per-asset metrics
3) Understand what just ran
By default, the sample run
- Loads a backtest config (YAML) defining assets, fees, margins, and slippage
- Uses a simple example bot with an interchangeable exit (e.g., ATR-based trailing stop)
- Steps through historical bars, placing orders and tracking PnL and margin
- Emits updates to the GUI (charts, equity curve) and logs per-fill data for stats
You didn’t have to write code — just run the backtester with a config.
Next, you can change the config or swap the bot/exit to try different ideas.
4) Pick a config to try (optional)
Backtest configs live under backtest_configs/. You can point the runner at a specific config if you like:
Example: run with a specific config file
PYTHONPATH=. python3 run_backtest.py --config backtest_configs/backtest_config.yaml
If your runner doesn’t take a flag in your current branch, you can temporarily edit run_backtest.py to point at a different YAML, or copy the default and tweak fields like initial_cash, commission_per_contract, fee_per_trade, and assets.
5) Headless & CLI options (optional)
If you want to run without launching the GUI (for quick tests or remote machines):
PYTHONPATH=. python3 run_backtest_headless.py
This will process the backtest and print/record results without opening windows.
6) Generate and train ML exit strategies (optional)
In addition to the built-in exits (ATR, fixed-ratio), Algo Trading Stack supports ML-driven exits such as PPO-based trailing stops.
Here’s how you can generate training data, train a model, and plug it straight into your backtests.
Step 1: Generate training data
Run the training data generator to produce labeled samples from historical data:
PYTHONPATH=. python3 bots/generate_ML_SL_Training_data.py \
--config bots/configs/ml_sl_config.yaml \
--output-dir bots/data/yahoo_finance/training_data
Step 2: Train a PPO exit model
With the training data in place, run the PPO trainer:
PYTHONPATH=. python3 bots/train_ppo_stop_selector.py \
--input_dir bots/data/yahoo_finance/training_data \
--output_dir bots/models/PPO_Trailing_Stop_Loss \
--total_timesteps 300000
Step 3: Rerun a backtest with your model
Once a model is trained and saved in the bots/models/ directory, the backtester will automatically attempt to load it when you use an ML-based exit strategy.
Simply re-run a backtest (GUI or headless):
PYTHONPATH=. python3 run_backtest.py
7) (Comming Soon) Live data sandbox
If you have a TradeStation SIM setup and credentials in config/tradestation_config.yaml, you can experiment with the live-data charting sandbox:
PYTHONPATH=. python3 run_live.py
This opens a lightweight charting window that streams minute bars from the SIM API, so you can visualize price action and test basic UI behavior with real-time updates. (Order routing is disabled in the live demo unless you wire a broker interface.)
8) Where to go next
Now that you can run a backtest and see the GUI, here’s what to explore:
- Architecture — Learn how Engine, Environment, Bots, Exits, and UI fit together.
- Config Files — See how YAML defines assets (tick size/value, margins, fees), slippage, and global run settings.
- Bots & Strategies — Use the base bot class to implement your own logic, then plug in an exit strategy.
- Exit Strategies — Swap between ATR, fixed-ratio, RL/sequence, or bandit hybrids without changing your bot.
- Testing & Validation — Keep risk limits and logic safe as you iterate.
FAQ
Q: Where do I change symbols, margins, and fees?
A: In the backtest YAML (see Config Files). You can add/remove assets, set tick_size
, tick_value
, initial_margin
, maintenance_margin
, commission_per_contract
, and slippage_*
.
Q: How do I use a different exit?
A: In your bot initialization, pass a different ExitStrategy (e.g., ATR trailing vs fixed-ratio vs RL/bandit). See Exit Strategies.
Q: How do I write my own bot?
A: Subclass the base bot and implement your entry logic (e.g., override decide_side
). Then attach any exit strategy you like. See Bots & Strategies.