Guide

The AI model is trained on data from the chosen stock. The resulting predictions from the test period are shown, as well as how the strategy compares with simply buying and holding the stock.

  1. 1

    Pick a stock and the features the model may use.

  2. 2

    Choose a model and its settings.

  3. 3

    Set the time period, interval and training/testing split.

  4. 4

    Tune the trading controls, then press Run Model.

Model types

Simpler models are easier to trust and less likely to find patterns that aren't really there. More advanced models can capture richer patterns but need more data and are easier to overfit. Trying a simple model first gives you a baseline to beat.

Logistic Regression

Machine Learning

Gives each feature a weight and adds them up into a probability that the price rises.

Strengths
Fast, stable and hard to overfit.
Weaknesses
Only sees straight-line relationships, not combinations of features.

Support Vector Classification

Machine Learning

Finds the boundary that best separates "up" bars from "down" bars, and can bend that boundary to follow curved patterns.

Strengths
Captures non-linear patterns, and works well with smaller datasets.
Weaknesses
Probabilities require an extra step, which makes them less reliable.

XG Boost

Machine Learning

Builds many small decision trees (40 to 300, set by the Generalize/Memorize slider), each one fixing the mistakes of the trees before it.

Strengths
Excellent at combinations of features.
Weaknesses
Struggles with data extrapolation, sensitive to hyperparameters.

Random Forest

Machine Learning

Grows about a hundred decision trees, each on a different random sample of the data and features, and averages their votes.

Strengths
Good at combining features, and reliable with little tuning.
Weaknesses
Can overfit (memorize) if its trees are allowed to grow deep, and is weak at extrapolating.

LSTM

Deep Learning

A neural network with memory. It reads a window of recent bars in order, so it can learn patterns that unfold over time.

Strengths
Has a lookback window, so it sees sequences of data at once.
Weaknesses
Needs more data and takes longer to train.

PPO

Reinforcement Learning

An agent that learns by trial and error. At each bar it chooses to hold the stock or stay in cash, and is rewarded by the next bar's price move.

Strengths
Learns a trading decision directly rather than a forecast, and has memory of recent bars. Can optimize for returns (reward).
Weaknesses
The least predictable and stable during training.

Inputs

Stock & time period

Stock symbol
Any US stock or ETF ticker, e.g. AAPL, MSFT or SPY.
Start & end date
The full period of data used.
Interval
The length of each bar: 5, 15 or 30 minutes, 1 hour, 1 day or 1 week. Intraday data starts in March 2023 and each run is limited to about 5,000 bars, so use shorter periods with shorter intervals.
Training to Testing Ratio
How much of your period is used for training vs testing.

Features

Features are the information the model sees at each bar.

Technical

RSI
Relative Strength Index (14 bars), from 0 to 100. High values mean the stock has risen strongly recently ("overbought"), while low values mean it has fallen strongly ("oversold").
EMA 50
Price relative to its 50-bar exponential moving average.
EMA 200
Price relative to its 200-bar exponential moving average.
MACD
Moving Average Convergence Divergence: the gap between a fast (12-bar) and slow (26-bar) average, plus how that gap compares with its own 9-bar average. Tracks the strength and turning points of a trend.
Volume
Shares traded in the bar, relative to the average of the last 20 bars (so 2 means twice the usual volume).
Percent Change
The bar's price change in percent.
Volatility
How much the price has been swinging over the last 20 bars.
Drawdown
How far the price is below its highest close of the last 252 bars (about a year of daily bars).

Market

Market Context (S&P 500)
How the overall market (the S&P 500) moved on the same bar, and how much better or worse the stock has done than the market over the last 20 bars.

Economic

Inflation
Year-over-year change in the Consumer Price Index.
Interest Rate
The Federal Funds rate.
Unemployment Data
The US unemployment rate.

Economic data changes monthly, so it describes the broad environment, not day-to-day moves.

Time

Hour (Time on the Machine Learning page)
Hour of the trading day. Only meaningful for intraday intervals, e.g. behavior near the open or close.
Day (Date)
Day of the week, for weekday effects.
Month (Months)
Month of the year, for seasonal effects.

Trading controls all models

Buy Confidence & Sell Confidence
How strong a prediction must be before the strategy trades. These control the backtest's trades only: the next-interval call is simply BUY when the signal strength is above 50 and SELL when it is below.
Vary position sizes
Varies the size of the position based on the model's signal strength.
Continuous buying
Buys again every time the signal strength crosses back above the green line, adding to the position, and sells everything when it crosses below the red line. Each buy uses half of the remaining cash, or a share set by signal strength when Vary position sizes is also on.
Risk-adjust
Makes the model care more about moves that are large relative to recent volatility.

Machine Learning settings

Model Selection
Which of the four Machine Learning models above to train. See Model types.
Generalize ↔ Memorize
How closely the model fits its training data.

Deep Learning settings LSTM

Learning rate
How big a step the network takes each time it adjusts (.0001 to .01). Too high and training becomes unstable, but too low and it learns very slowly.
Training time
The maximum number of passes through the training data (100 to 500). Training stops earlier on its own as soon as the model stops improving on new data.
Lookback window
How many recent bars the LSTM reads before each prediction (1 to 50). Its meaning depends on the interval: 20 daily bars is about a month, 20 five-minute bars is under two hours.
Layers & neurons (Build)
The size of the network: up to three stacked layers of 16 to 256 neurons each. Bigger networks can represent more complex patterns but need more data.

Reinforcement Learning settings PPO

Learning rate
How big a step the agent takes each time it updates its strategy (.0001 to .003).
Entropy
How much the agent is encouraged to keep exploring both choices (hold the stock or hold cash) instead of settling on one habit early. Higher values explore more, while 0 lets it commit quickly.
Training timesteps
How many decisions the agent makes during training (10,000 to 100,000). More steps usually give a steadier strategy but take longer. Longer date ranges need more steps for the same amount of practice.
Gamma (future importance)
How much the agent values future rewards compared with the next one (0.80 to 0.99).

Limitations

These models are tools for exploring ideas, not reliable forecasts. Keep these limits in mind when reading the results.

  • The backtest is simplified. Every trade happens at the bar's closing price, with no fees, no bid-ask spread and no taxes, and partial shares are allowed. Real trading would do somewhat worse.
  • It can only buy or stay in cash. A SELL means getting out of the stock, not betting on a fall. There is no short selling or borrowing.
  • It sees one stock's numbers only. The models know nothing about news, earnings reports or events, just the features you tick (plus the S&P 500 if you add Market Context).
  • Data has limits. Each run is capped at about 5,000 bars, intraday data starts in March 2023, and economic data is monthly. When a newer economic figure isn't available yet, the latest one is reused.
  • Results depend on your settings. Different dates, features or settings can give very different results, especially for LSTM and PPO. One good backtest isn't proof that a model works.